### Question:
ToDoAPI { @POST @Consumes("application/json") @Produces("application/json") public ToDo newToDo(ToDo td) { if(td == null) { throw new WebApplicationException("Must supply a ToDo in the POST body.", Response.Status.BAD_REQUEST); } try { return store.persist(td); } catch (ToDoStoreException e) { throw new WebApplicationException("Error saving ToDo.", Response.Status.INTERNAL_SERVER_ERROR); } } ToDoAPI();  ToDoAPI(ToDoStore store); @GET @Path("/{id}") @Produces("application/json") ToDo getToDo(@PathParam("id") String id); @GET @Produces("application/json") Collection<ToDo> getToDos(); @POST @Consumes("application/json") @Produces("application/json") ToDo newToDo(ToDo td); @PUT @Path("/{id}") @Produces("application/json") @Consumes("application/json") ToDo updateToDo(@PathParam("id") String id, ToDo td); @DELETE @Path("/{id}") void deleteToDo(@PathParam("id") String id);  }### Answer:
@Test public void testNewToDo() { ToDo td = new ToDo(); td.setTitle("do a test"); td = api.newToDo(td); assertNotNull(td.getId()); Collection<ToDo> todos = api.getToDos(); assertTrue(todos.contains(td1)); assertTrue(todos.contains(td2)); assertTrue(todos.contains(td)); assertEquals(3, todos.size()); }
@Test public void testNewToDoException() { try { api.newToDo(null); fail("Expected exception to be thrown."); } catch(WebApplicationException e) { assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus()); } }
@Test public void testNewToDoInternalError() { try { errorApi.newToDo(new ToDo()); fail("Expected exception to be thrown."); } catch(WebApplicationException e) { assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getResponse().getStatus()); } }