@Test public void When_Pass_Validation_Then_Do_Not_Throw_Assertion_Error() throws NoSuchMethodException, IOException { Method method = Providers.class.getDeclaredMethod("string", String.class); RequestBodyValid annotation = (RequestBodyValid) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<RequestBodyValid> metadata = new Metadata<>(Providers.class, method, null, annotation, type); RequestBody requestBody = (RequestBody) requestBodyValidMockery.legal(metadata); requestBodyValidMockery.validate(metadata, requestBody); }
@Test public void When_Call_Legal_With_Default_Then_Get_RequestBody_With_Default_Legal() throws NoSuchMethodException, IOException { Method method = Providers.class.getDeclaredMethod("stringWithDefault", String.class); RequestBodyValid annotation = (RequestBodyValid) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<RequestBodyValid> metadata = new Metadata<>(Providers.class, method, null, annotation, type); RequestBody requestBody = (RequestBody) requestBodyValidMockery.legal(metadata); assertNotNull(requestBody); assertThat(requestBody.contentType().toString(), is("text/plain; charset=utf-8")); Buffer buffer = new Buffer(); requestBody.writeTo(buffer); assertThat(buffer.readUtf8(), is("s1")); }
@Test public void When_Call_Legal_Then_Get_RequestBody_Legal() throws NoSuchMethodException, IOException { Method method = Providers.class.getDeclaredMethod("string", String.class); RequestBodyValid annotation = (RequestBodyValid) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<RequestBodyValid> metadata = new Metadata<>(Providers.class, method, null, annotation, type); RequestBody requestBody = (RequestBody) requestBodyValidMockery.legal(metadata); assertNotNull(requestBody); assertThat(requestBody.contentType().toString(), is("text/plain; charset=utf-8")); Buffer buffer = new Buffer(); requestBody.writeTo(buffer); RequestBody candidate = RequestBody.create(MediaType.parse("text/plain"), buffer.readUtf8()); requestBodyValidMockery.validate(metadata, candidate); }