### Question:
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);  }### Answer:
@Test public void setSecretReturnsMetadataObject() { HashicorpSetSecretData setSecretData = new HashicorpSetSecretData("engine", "name", Collections.emptyMap()); Versioned.Metadata metadata = mock(Versioned.Metadata.class); when(delegate.set(setSecretData)).thenReturn(metadata); Object result = keyVaultService.setSecret(setSecretData); assertThat(result).isInstanceOf(Versioned.Metadata.class); assertThat(result).isEqualTo(metadata); }
@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"); }