@Test public void setSecretIfNullPointerExceptionThenHashicorpExceptionThrown() { HashicorpSetSecretData setSecretData = mock(HashicorpSetSecretData.class); when(delegate.set(any(HashicorpSetSecretData.class))).thenThrow(new NullPointerException()); Throwable ex = catchThrowable(() -> keyVaultService.setSecret(setSecretData)); assertThat(ex).isExactlyInstanceOf(HashicorpVaultException.class); assertThat(ex.getMessage()).isEqualTo("Unable to save generated secret to vault. Ensure that the secret engine being used is a v2 kv secret engine"); }
@Override public Object setSecret(HashicorpSetSecretData hashicorpSetSecretData) { KeyValueOperationsDelegate keyValueOperationsDelegate = keyValueOperationsDelegateFactory.create(hashicorpSetSecretData.getSecretEngineName()); try { return keyValueOperationsDelegate.set(hashicorpSetSecretData); } catch (NullPointerException ex) { throw new HashicorpVaultException("Unable to save generated secret to vault. Ensure that the secret engine being used is a v2 kv secret engine"); } }
HashicorpKeyVaultService implements KeyVaultService<HashicorpSetSecretData, HashicorpGetSecretData> { @Override public Object setSecret(HashicorpSetSecretData hashicorpSetSecretData) { KeyValueOperationsDelegate keyValueOperationsDelegate = keyValueOperationsDelegateFactory.create(hashicorpSetSecretData.getSecretEngineName()); try { return keyValueOperationsDelegate.set(hashicorpSetSecretData); } catch (NullPointerException ex) { throw new HashicorpVaultException("Unable to save generated secret to vault. Ensure that the secret engine being used is a v2 kv secret engine"); } } }
HashicorpKeyVaultService implements KeyVaultService<HashicorpSetSecretData, HashicorpGetSecretData> { @Override public Object setSecret(HashicorpSetSecretData hashicorpSetSecretData) { KeyValueOperationsDelegate keyValueOperationsDelegate = keyValueOperationsDelegateFactory.create(hashicorpSetSecretData.getSecretEngineName()); try { return keyValueOperationsDelegate.set(hashicorpSetSecretData); } catch (NullPointerException ex) { throw new HashicorpVaultException("Unable to save generated secret to vault. Ensure that the secret engine being used is a v2 kv secret engine"); } } HashicorpKeyVaultService(KeyValueOperationsDelegateFactory keyValueOperationsDelegateFactory); }
HashicorpKeyVaultService implements KeyVaultService<HashicorpSetSecretData, HashicorpGetSecretData> { @Override public Object setSecret(HashicorpSetSecretData hashicorpSetSecretData) { KeyValueOperationsDelegate keyValueOperationsDelegate = keyValueOperationsDelegateFactory.create(hashicorpSetSecretData.getSecretEngineName()); try { return keyValueOperationsDelegate.set(hashicorpSetSecretData); } catch (NullPointerException ex) { throw new HashicorpVaultException("Unable to save generated secret to vault. Ensure that the secret engine being used is a v2 kv secret engine"); } } HashicorpKeyVaultService(KeyValueOperationsDelegateFactory keyValueOperationsDelegateFactory); @Override String getSecret(HashicorpGetSecretData hashicorpGetSecretData); @Override Object setSecret(HashicorpSetSecretData hashicorpSetSecretData); }
HashicorpKeyVaultService implements KeyVaultService<HashicorpSetSecretData, HashicorpGetSecretData> { @Override public Object setSecret(HashicorpSetSecretData hashicorpSetSecretData) { KeyValueOperationsDelegate keyValueOperationsDelegate = keyValueOperationsDelegateFactory.create(hashicorpSetSecretData.getSecretEngineName()); try { return keyValueOperationsDelegate.set(hashicorpSetSecretData); } catch (NullPointerException ex) { throw new HashicorpVaultException("Unable to save generated secret to vault. Ensure that the secret engine being used is a v2 kv secret engine"); } } HashicorpKeyVaultService(KeyValueOperationsDelegateFactory keyValueOperationsDelegateFactory); @Override String getSecret(HashicorpGetSecretData hashicorpGetSecretData); @Override Object setSecret(HashicorpSetSecretData hashicorpSetSecretData);  }