/** * @see OptionalMockery#legalOrIllegal(Metadata) */ @Override public Object illegal(Metadata<Optional> metadata) { return legalOrIllegal(metadata); }
@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)); }
@Before public void init() { optionalMockery = new OptionalMockery(); }
@Test public void When_Support_Type_Retrieved_Then_Is_The_Same_as_The_Type_Of_The_Param() 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); Type[] supportedTypes = optionalMockery.supportedTypes(metadata); assertThat(supportedTypes.length, is(1)); assertTrue(Arrays.asList(supportedTypes).contains(Model.class)); }
@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)) .isEmpty()); 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));
/** * @see OptionalMockery#legalOrIllegal(Metadata) */ @Override public Object legal(Metadata<Optional> metadata) { return legalOrIllegal(metadata); }