SecretsDeliveryResource { @Timed @ExceptionMetered @GET public List<SecretDeliveryResponse> getSecrets(@Auth Client client) { logger.info("Client {} listed available secrets.", client.getName()); return aclDAO.getSanitizedSecretsFor(client).stream() .map(SecretDeliveryResponse::fromSanitizedSecret) .collect(toList()); } @Inject  SecretsDeliveryResource(AclDAOFactory aclDAOFactory); @VisibleForTesting  SecretsDeliveryResource(AclDAO aclDAO); @Timed @ExceptionMetered @GET List<SecretDeliveryResponse> getSecrets(@Auth Client client);  }
@Test public void returnsEmptyJsonArrayWhenUserHasNoSecrets() throws Exception { when(aclDAO.getSanitizedSecretsFor(client)).thenReturn(ImmutableSet.of()); List<SecretDeliveryResponse> secrets = secretsDeliveryResource.getSecrets(client); assertThat(secrets).isEmpty(); }
@Test public void returnsJsonArrayWhenUserHasOneSecret() throws Exception { when(aclDAO.getSanitizedSecretsFor(client)).thenReturn(ImmutableSet.of(sanitizedFirstSecret)); List<SecretDeliveryResponse> secrets = secretsDeliveryResource.getSecrets(client); assertThat(secrets).containsOnly(SecretDeliveryResponse.fromSanitizedSecret( SanitizedSecret.fromSecret(firstSecret))); }
@Test public void returnsJsonArrayWhenUserHasMultipleSecrets() throws Exception { when(aclDAO.getSanitizedSecretsFor(client)) .thenReturn(ImmutableSet.of(sanitizedFirstSecret, sanitizedSecondSecret)); List<SecretDeliveryResponse> secrets = secretsDeliveryResource.getSecrets(client); assertThat(secrets).containsOnly( SecretDeliveryResponse.fromSanitizedSecret(SanitizedSecret.fromSecret(firstSecret)), SecretDeliveryResponse.fromSanitizedSecret(SanitizedSecret.fromSecret(secondSecret))); }