### Question:
MyResource { @POST @Produces(MediaType.TEXT_PLAIN) public String post(@Size(min = 3) String payload) { return payload; }  @POST @Produces(MediaType.TEXT_PLAIN) String post(@Size(min = 3) String payload); @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) void post2(@NotNull @FormParam("name") String name, @Min(1) @Max(10) @FormParam("age") int age);  }### Answer:
@Test public void testInvalidRequest() { try { target.request().post(Entity.text("fo"), String.class); fail("Request must fail with payload < 3"); } catch (BadRequestException e) { assertNotNull(e); } }
@Test public void testValidRequest() { String r = target.request().post(Entity.text("foo"), String.class); assertEquals("foo", r); }
@Test public void testValidPostRequest() { MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>(); map.add("name", "Penny"); map.add("age", "1"); target.request().post(Entity.form(map)); map.clear(); map.add("name", "Leonard"); map.add("age", "2"); target.request().post(Entity.form(map)); }
@Test public void testInvalidPostRequest() { try { MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>(); map.add("name", null); map.add("age", "1"); target.request().post(Entity.form(map)); } catch (BadRequestException e) { assertNotNull(e); } }
@Test public void testInvalidPostRequestLesserAge() { try { MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>(); map.add("name", "Penny"); map.add("age", "0"); target.request().post(Entity.form(map)); } catch (BadRequestException e) { assertNotNull(e); } }
@Test public void testInvalidPostRequestGreaterAge() { try { MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>(); map.add("name", "Penny"); map.add("age", "11"); target.request().post(Entity.form(map)); } catch (BadRequestException e) { assertNotNull(e); } }