### Question:
HubEncryptionKeyStore implements EncryptionKeyStore { @Override public PublicKey getEncryptionKeyForEntity(String entityId) { LOG.info("Retrieving encryption key for {} from config", entityId); try { return configServiceKeyStore.getEncryptionKeyForEntity(entityId); } catch (ApplicationException e) { if (e.getExceptionType().equals(ExceptionType.CLIENT_ERROR)) { throw new NoKeyConfiguredForEntityException(entityId); } throw new RuntimeException(e); } } @Inject  HubEncryptionKeyStore(ConfigServiceKeyStore configServiceKeyStore); @Override PublicKey getEncryptionKeyForEntity(String entityId);  }### Answer:
@Test public void shouldGetPublicKeyForAnEntityThatExists() throws Exception { String entityId = "entityId"; when(configServiceKeyStore.getEncryptionKeyForEntity(entityId)).thenReturn(publicKey); final PublicKey key = keyStore.getEncryptionKeyForEntity(entityId); assertThat(key).isEqualTo(publicKey); }
@Test(expected = NoKeyConfiguredForEntityException.class) public void shouldThrowExceptionIfNoPublicKeyForEntityId() throws Exception { String entityId = "non-existent-entity"; when(configServiceKeyStore.getEncryptionKeyForEntity(entityId)).thenThrow(ApplicationException.createUnauditedException(ExceptionType.CLIENT_ERROR, UUID.randomUUID())); keyStore.getEncryptionKeyForEntity(entityId); }