/** * Serialize the DTO legal object deferred from its mockery as the content of a {@code RequestBody}. * @see DTO.Behaviour */ @Override public Object legal(Metadata<RequestBodyDTO> metadata) { Object legal = dtoJsonMockery.legal(DTOJsonMetadata(metadata)); RequestBody requestBodyLegal = RequestBody .create(MediaType.parse("text/plain"), legal.toString()); return requestBodyLegal; }
@Test public void When_Pass_Validation_Then_Do_Not_Throw_Assertion_Error() throws NoSuchMethodException { Method method = ProvidersJsonConverter.class.getDeclaredMethod("mock", String.class); DTOJson annotation = (DTOJson) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<DTOJson> metadata = new Metadata<>(ProvidersJsonConverter.class, method, null, annotation, type); String json = (String) dtoJsonMockery.legal(metadata); dtoJsonMockery.validate(metadata, json); }
@Test public void When_Class_Has_Not_Json_Converter_Then_Throw_Exception() throws NoSuchMethodException { Method method = Providers.class.getDeclaredMethod("mock", String.class); DTOJson annotation = (DTOJson) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<DTOJson> metadata = new Metadata<>(Providers.class, method, null, annotation, type); exception.expect(RuntimeException.class); dtoJsonMockery.legal(metadata); }
@Test public void When_Call_Legal_Then_Get_Legal() throws NoSuchMethodException { Method method = ProvidersJsonConverter.class.getDeclaredMethod("mock", String.class); DTOJson annotation = (DTOJson) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<DTOJson> metadata = new Metadata<>(ProvidersJsonConverter.class, method, null, annotation, type); String json = (String) dtoJsonMockery.legal(metadata); assertThat(json, is(jsonMockSample())); }