/** * Serialize the illegal object as content of a {@code RequestBody} deferring to {@link ValidMockery} for object creation. * @see ValidMockery */ @Override public Object illegal(Metadata<RequestBodyValid> metadata) { Object illegal = validMockery.illegal(validMetadata(metadata)); illegal = illegal != null ? illegal.toString() : ""; RequestBody requestBodyIllegal = RequestBody .create(MediaType.parse("text/plain"), illegal.toString()); return requestBodyIllegal; }
@Test public void When_Illegal_With_Default_Value_Then_Get_Default() throws NoSuchMethodException { Method method = ProvidersIllegal.class .getDeclaredMethod("checkIllegalDefault", String.class); Valid annotation = (Valid) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<Valid> metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat(((String)validMockery.illegal(metadata)), is("illegal")); }
@Test public void When_Call_Illegal_With_Primitive_Type_Then_Illegal_Matches_Expected_Type() throws NoSuchMethodException { Method method = ProvidersIllegal.class.getDeclaredMethod("checkIllegalsPrimitives", int.class, long.class, double.class, float.class); Valid annotation = (Valid) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<Valid> metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat((int) validMockery.illegal(metadata), is(0)); annotation = (Valid) method.getParameterAnnotations()[1][0]; type = method.getGenericParameterTypes()[1]; metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat((long) validMockery.illegal(metadata), is(0l)); annotation = (Valid) method.getParameterAnnotations()[2][0]; type = method.getGenericParameterTypes()[2]; metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat((double) validMockery.illegal(metadata), is(0d)); annotation = (Valid) method.getParameterAnnotations()[3][0]; type = method.getGenericParameterTypes()[3]; metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat((float) validMockery.illegal(metadata), is(0f)); }
Metadata<Valid> metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertTrue(((String)validMockery.illegal(metadata)) .isEmpty()); metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat(((Integer)validMockery.illegal(metadata)), is(0)); metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat(((Long)validMockery.illegal(metadata)), is(0l)); metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat(((Double)validMockery.illegal(metadata)), is(0d)); metadata = new Metadata<>(Providers.class, method, null, annotation, type); assertThat(((Float)validMockery.illegal(metadata)), is(0f));