@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()); } }
@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 { @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 { @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); }
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); }
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);  }