GroupsResource { @Path("{groupId}") @Timed @ExceptionMetered @DELETE public Response deleteGroup(@Auth User user, @PathParam("groupId") LongParam groupId) { logger.info("User '{}' deleting group id={}.", user, groupId); Optional<Group> group = groupDAO.getGroupById(groupId.get()); if (!group.isPresent()) { throw new NotFoundException("Group not found."); } groupDAO.deleteGroup(group.get()); auditLog.recordEvent(new Event(Instant.now(), EventTag.GROUP_DELETE, user.getName(), group.get().getName())); return Response.noContent().build(); } @Inject  GroupsResource(AclDAOFactory aclDAOFactory, GroupDAOFactory groupDAOFactory, AuditLog auditLog); @VisibleForTesting  GroupsResource(AclDAO aclDAO, GroupDAO groupDAO, AuditLog auditLog); @Timed @ExceptionMetered @GET Response findGroups(@Auth User user, @DefaultValue("") @QueryParam("name") String name); @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response createGroup(@Auth User user, @Valid CreateGroupRequestV2 request); @Path("{groupId}") @Timed @ExceptionMetered @GET GroupDetailResponse getGroup(@Auth User user, @PathParam("groupId") LongParam groupId); @Path("{groupId}") @Timed @ExceptionMetered @DELETE Response deleteGroup(@Auth User user, @PathParam("groupId") LongParam groupId);  }
@Test public void canDelete() { when(groupDAO.getGroupById(0xdeadbeef)).thenReturn(Optional.of(group)); Response response = resource.deleteGroup(user, new LongParam(Long.toString(0xdeadbeef))); verify(groupDAO).deleteGroup(group); assertThat(response.getStatus()).isEqualTo(204); }
@Test(expected = NotFoundException.class) public void notFoundWhenDeletingBadId() { when(groupDAO.getGroupById(0x1bad1dea)).thenReturn(Optional.empty()); resource.deleteGroup(user, new LongParam(Long.toString(0x1bad1dea))); }