### Question:
EmployeeResource { @GET @Produces({ "application/json", "application/xml" }) @Path("{id}") public Employee get(@PathParam("id") int id) { if (id < bean.getEmployees().size()) return bean.getEmployees().get(id); else return null; }  @GET @Produces({ "application/xml", "application/json" }) Employee[] getList(); @GET @Produces({ "application/json", "application/xml" }) @Path("{id}") Employee get(@PathParam("id") int id); @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) void addToList(@FormParam("name") String name,
         @FormParam("age") int age); @PUT void putToList(@FormParam("name") String name,
         @FormParam("age") int age); @DELETE @Path("{name}") void deleteFromList(@PathParam("name") String name);  }### Answer:
@Test @InSequence(1) public void testPostAndGet() { 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)); map.clear(); map.add("name", "Sheldon"); map.add("age", "3"); target.request().post(Entity.form(map)); Employee[] list = target.request().get(Employee[].class); assertEquals(3, list.length); assertEquals("Penny", list[0].getName()); assertEquals(1, list[0].getAge()); assertEquals("Leonard", list[1].getName()); assertEquals(2, list[1].getAge()); assertEquals("Sheldon", list[2].getName()); assertEquals(3, list[2].getAge()); }
@Test @InSequence(2) public void testGetSingle() { Employee p = target .path("{id}") .resolveTemplate("id", "1") .request(MediaType.APPLICATION_XML) .get(Employee.class); assertEquals("Leonard", p.getName()); assertEquals(2, p.getAge()); }
@Test @InSequence(3) public void testPut() { MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>(); map.add("name", "Howard"); map.add("age", "4"); target.request().post(Entity.form(map)); Employee[] list = target.request().get(Employee[].class); assertEquals(4, list.length); assertEquals("Howard", list[3].getName()); assertEquals(4, list[3].getAge()); }
@Test @InSequence(4) public void testDelete() { target .path("{name}") .resolveTemplate("name", "Howard") .request() .delete(); Employee[] list = target.request().get(Employee[].class); assertEquals(3, list.length); }
@Test @InSequence(5) public void testClientSideNegotiation() { JsonArray json = target.request().accept(MediaType.APPLICATION_JSON).get(JsonArray.class); assertEquals(3, json.size()); for(int i = 0; i < json.size(); i++) { JsonObject obj = json.getJsonObject(i); String name = obj.getString("name"); int age = obj.getInt("age"); if("Penny".equals(name)) { assertEquals(1, age); } else if("Leonard".equals(name)) { assertEquals(2, age); } else if("Sheldon".equals(name)) { assertEquals(3, age); } else { fail("Unknown Employee returned [" + name + ", " + age + "]"); } } }
@Test @InSequence(6) public void testDeleteAll() { Employee[] list = target.request().get(Employee[].class); for (Employee p : list) { target .path("{name}") .resolveTemplate("name", p.getName()) .request() .delete(); } list = target.request().get(Employee[].class); assertEquals(0, list.length); }