Skip to content

Commit d2864ce

Browse files
committed
Warn on using global namespace.
Test preventing empty namespaces.
1 parent 0335b63 commit d2864ce

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

src/main/java/com/bettercloud/vault/VaultConfig.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ public VaultConfig environmentLoader(final EnvironmentLoader environmentLoader)
8484
* @return This object, with the namespace populated, ready for additional builder-pattern method calls or else
8585
* finalization with the build() method
8686
*/
87-
public VaultConfig nameSpace(final String nameSpace) {
88-
assert !nameSpace.isEmpty();
89-
this.nameSpace = nameSpace;
90-
return this;
87+
public VaultConfig nameSpace(final String nameSpace) throws VaultException {
88+
if (nameSpace != null && !nameSpace.isEmpty()) {
89+
this.nameSpace = nameSpace;
90+
return this;
91+
} else throw new VaultException("A namespace cannot be empty.");
9192
}
9293

9394
/**

src/test/java/com/bettercloud/vault/VaultTests.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void testGlobalEngineVersionVaultConstructor() {
2929
}
3030

3131
@Test
32-
public void testNameSpaceProvidedVaultConstructor() {
32+
public void testNameSpaceProvidedVaultConstructor() throws VaultException {
3333
VaultConfig vaultConfig = new VaultConfig().nameSpace("testNameSpace");
3434
Vault vault = new Vault(vaultConfig, 1);
3535
Assert.assertNotNull(vault);
@@ -39,19 +39,11 @@ public void testNameSpaceProvidedVaultConstructor() {
3939
public void testNameSpaceProvidedVaultConstructorCannotBeEmpty() {
4040
try {
4141
VaultConfig vaultConfig = new VaultConfig().nameSpace("");
42-
} catch (AssertionError e) {
43-
Assert.assertEquals(e.getClass(), AssertionError.class);
42+
} catch (VaultException e) {
43+
Assert.assertEquals(e.getMessage(), "A namespace cannot be empty.");
4444
}
4545
}
4646

47-
48-
@Test
49-
public void testNameSpaceNotProvidedVaultConstructor() {
50-
VaultConfig vaultConfig = new VaultConfig().nameSpace(null);
51-
Vault vault = new Vault(vaultConfig, 1);
52-
Assert.assertNotNull(vault);
53-
}
54-
5547
@Test(expected = IllegalArgumentException.class)
5648
public void testInvalidGlobalEngineVersionVaultConstructor() {
5749
VaultConfig vaultConfig = new VaultConfig();

0 commit comments

Comments
 (0)