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:
@ -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");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user