ClientsResource { @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) public Response createClient(@Auth User user, @Valid CreateClientRequestV2 createClientRequest) { logger.info("User '{}' creating client '{}'.", user, createClientRequest.name()); long clientId; try { clientId = clientDAO.createClient(createClientRequest.name(), user.getName(), createClientRequest.description(), new URI(createClientRequest.spiffeId())); } catch (DataAccessException | URISyntaxException e) { logger.warn("Cannot create client {}: {}", createClientRequest.name(), e); throw new ConflictException("Conflict creating client."); } URI uri = UriBuilder.fromResource(ClientsResource.class).path("{clientId}").build(clientId); Response response = Response .created(uri) .entity(clientDetailResponseFromId(clientId)) .build(); if (response.getStatus() == HttpStatus.SC_CREATED) { auditLog.recordEvent(new Event(Instant.now(), EventTag.CLIENT_CREATE, user.getName(), createClientRequest.name())); } return response; } @Inject  ClientsResource(AclDAOFactory aclDAOFactory, ClientDAOFactory clientDAOFactory,
      AuditLog auditLog); @VisibleForTesting  ClientsResource(AclDAO aclDAO, ClientDAO clientDAO, AuditLog auditLog); @Timed @ExceptionMetered @GET Response findClients(@Auth User user, @DefaultValue("") @QueryParam("name") String name); @Timed @ExceptionMetered @POST @Consumes(APPLICATION_JSON) Response createClient(@Auth User user,
      @Valid CreateClientRequestV2 createClientRequest); @Path("{clientId}") @Timed @ExceptionMetered @GET ClientDetailResponse getClient(@Auth User user,
      @PathParam("clientId") LongParam clientId); @Path("{clientId}") @Timed @ExceptionMetered @DELETE Response deleteClient(@Auth User user, @PathParam("clientId") LongParam clientId);  }
@Test public void createsClient() throws Exception { CreateClientRequestV2 request = CreateClientRequestV2.builder() .name("new-client-name") .description("description") .spiffeId("spiffe .build(); when(clientDAO.createClient("new-client-name", "user", "description", new URI("spiffe when(clientDAO.getClientById(42L)).thenReturn(Optional.of(client)); when(aclDAO.getSanitizedSecretsFor(client)).thenReturn(ImmutableSet.of()); Response response = resource.createClient(user, request); assertThat(response.getStatus()).isEqualTo(201); }