@Test public void When_Call_Legal_Or_Illegal_With_Custom_Object_Return_Null() throws NoSuchMethodException { Method method = Providers.class.getDeclaredMethod("checkCustomObject", Model.class); Optional annotation = (Optional) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<Optional> metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertNull(optionalMockery.illegal(metadata)); assertNull(optionalMockery.legal(metadata)); }
@Test public void When_Call_Legal_Or_Illegal_With_Primitive_Type_Then_Matches_Expected_Type() throws NoSuchMethodException { Method method = Providers.class.getDeclaredMethod("checkPrimitives", int.class, long.class, double.class, float.class); Optional annotation = (Optional) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<Optional> metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat((int) optionalMockery.illegal(metadata), is(0)); assertThat((int) optionalMockery.legal(metadata), is(0)); annotation = (Optional) method.getParameterAnnotations()[1][0]; type = method.getGenericParameterTypes()[1]; metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat((long) optionalMockery.illegal(metadata), is(0l)); assertThat((long) optionalMockery.legal(metadata), is(0l)); annotation = (Optional) method.getParameterAnnotations()[2][0]; type = method.getGenericParameterTypes()[2]; metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat((double) optionalMockery.illegal(metadata), is(0d)); assertThat((double) optionalMockery.legal(metadata), is(0d)); annotation = (Optional) method.getParameterAnnotations()[3][0]; type = method.getGenericParameterTypes()[3]; metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat((float) optionalMockery.illegal(metadata), is(0f)); assertThat((float) optionalMockery.legal(metadata), is(0f)); }
Metadata<Optional> metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertTrue(((String)optionalMockery.illegal(metadata)) .isEmpty()); assertTrue(((String)optionalMockery.legal(metadata)) metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat(((Integer)optionalMockery.illegal(metadata)), is(0)); assertThat(((Integer)optionalMockery.legal(metadata)), is(0)); metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat(((Long)optionalMockery.illegal(metadata)), is(0l)); assertThat(((Long)optionalMockery.legal(metadata)), is(0l)); metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat(((Double)optionalMockery.illegal(metadata)), is(0d)); assertThat(((Double)optionalMockery.legal(metadata)), is(0d)); metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat(((Float)optionalMockery.illegal(metadata)), is(0f)); assertThat(((Float)optionalMockery.legal(metadata)), is(0f));