passthrough null as port number in builder (#56)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
fdda685f6f
commit
75561a0540
@ -1,3 +1,9 @@
|
||||
## UNRELEASED
|
||||
|
||||
### Fix
|
||||
* Make `HTTPVaultConnectorBuilder#withPort(Integer)` null-safe (#56)
|
||||
|
||||
|
||||
## 1.0.0 (2021-10-02)
|
||||
|
||||
### Breaking
|
||||
|
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>de.stklcode.jvault</groupId>
|
||||
<artifactId>jvault-connector</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
@ -125,13 +125,13 @@ public final class HTTPVaultConnectorBuilder {
|
||||
/**
|
||||
* Set port (default: 8200).
|
||||
* A value of {@code null} or {@code -1} indicates that no port is specified, i.e. the protocol default is used.
|
||||
* Otherwise a valid port number bwetween 1 and 65535 is expected.
|
||||
* Otherwise, a valid port number between 1 and 65535 is expected.
|
||||
*
|
||||
* @param port Vault TCP port
|
||||
* @return self
|
||||
*/
|
||||
public HTTPVaultConnectorBuilder withPort(final Integer port) {
|
||||
if (port < 0) {
|
||||
if (port == null || port < 0) {
|
||||
this.port = null;
|
||||
} else if (port < 1 || port > 65535) {
|
||||
throw new IllegalArgumentException("Port number " + port + " out of range");
|
||||
|
@ -89,6 +89,8 @@ class HTTPVaultConnectorBuilderTest {
|
||||
assertThrows(IllegalArgumentException.class, () -> HTTPVaultConnector.builder().withPort(0), "Port number 0 should throw an exception");
|
||||
builder = assertDoesNotThrow(() -> HTTPVaultConnector.builder().withPort(-1), "Port number -1 should not throw an exception");
|
||||
assertNull(builder.getPort(), "Port number -1 should be omitted");
|
||||
builder = assertDoesNotThrow(() -> HTTPVaultConnector.builder().withPort(null), "Port number NULL should not throw an exception");
|
||||
assertNull(builder.getPort(), "Port number NULL should be passed through");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user