@Test public void When_Call_Illegal_With_Default_Then_Get_RequestBody_With_Default_Illegal() 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.illegal(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_Illegal_Then_Get_RequestBody_Illegal() 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.illegal(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()); exception.expect(AssertionError.class); requestBodyValidMockery.validate(metadata, candidate); }