CommentResource { @POST @Path("/update") public Response updateComment(@Auth AccessToken token, @Valid Comment comment) { if(comment.getUserId().equals(token.getUserId())) { comment.setUpdateTime(DateTime.now()); commentDao.updateComment(comment); return Response.ok(comment).build(); } else { return Response.notModified().build(); } } CommentResource(CommentDAO commentDao); @GET @Path("/{id}") Comment commentById(@PathParam("id") Long id); @POST Comment createComment(@Auth AccessToken token, @Valid Comment comment); @POST @Path("/update") Response updateComment(@Auth AccessToken token, @Valid Comment comment); @POST @Path("/{id}/delete") Response deleteComment(@Auth AccessToken token, @PathParam("id") Long id);  }
@Test public void testUpdateComment() throws Exception { Response res = rule.getJerseyTest() .target("/comment/update") .request(MediaType.APPLICATION_JSON_TYPE) .header("Authorization", "Bearer test") .post(Entity.json(comment)); assertThat(res.getStatusInfo().getStatusCode()).isEqualTo(200); verify(commentDao).updateComment(any()); }
@Test public void cantUpdateComment() throws Exception { Response res = rule.getJerseyTest() .target("/comment/update") .request(MediaType.APPLICATION_JSON_TYPE) .header("Authorization", "Bearer test") .post(Entity.json(invalidComment)); assertThat(res.getStatusInfo().getStatusCode()).isEqualTo(304); verify(commentDao, never()).updateComment(any()); }