### Question:
ToDoAPI { @PUT @Path("/{id}") @Produces("application/json") @Consumes("application/json") public ToDo updateToDo(@PathParam("id") String id, ToDo td) { if(id == null) { throw new WebApplicationException("Must supply an ID, for example /api/todos/123.", Response.Status.BAD_REQUEST); } if(td == null) { throw new WebApplicationException("Must supply a ToDo in the PUT body.", Response.Status.BAD_REQUEST); } try { ToDo updatedTd = store.update(id, td); if(updatedTd == null) { throw new WebApplicationException("The ToDo with the ID " + id + " does not exist.", Response.Status.BAD_REQUEST); } return updatedTd; } catch (ToDoStoreException e) { throw new WebApplicationException("Error updating 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 testUpdateToDoIdException() { try { api.updateToDo(null, new ToDo()); fail("Expected exception to be thrown."); } catch(WebApplicationException e) { assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus()); } }
@Test public void testUpdateToDoException() { try { api.updateToDo("123", null); fail("Expected exception to be thrown."); } catch(WebApplicationException e) { assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus()); } }
@Test public void testUpdateToDoInternalError() { try { errorApi.updateToDo("123", new ToDo()); fail("Expected exception to be thrown."); } catch(WebApplicationException e) { assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getResponse().getStatus()); } }
@Test public void testUpdateToDoDoesNotExist() { try{ api.updateToDo("123", new ToDo()); fail("Expected exception to be thrown."); } catch(WebApplicationException e) { assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus()); } }
@Test public void testUpdateToDo() { ToDo td = new ToDo(); td.setTitle("do a test"); td.setCompleted(true); api.updateToDo(td1.getId(), td); td = api.getToDo(td1.getId()); assertEquals("do a test", td.getTitle()); assertTrue(td.isCompleted()); }