protected void validate(int port) { assertValid(port); }
protected void validate(int port) { assertValid(port); }
protected void validate(int port) { assertValid(port); }
public Builder port(int port) { Port.assertValid(port); this.port = Optional.of(port); return this; }
public Builder port(int port) { Port.assertValid(port); this.port = Optional.of(port); return this; }
@VisibleForTesting Host(String hostName, int port) { Preconditions.checkNotNull(hostName, "Hostname could not be null"); Preconditions.checkArgument(!Strings.isNullOrEmpty(hostName), "Hostname could not be empty"); Port.assertValid(port); this.hostName = hostName; this.port = port; }
@VisibleForTesting Host(String hostName, int port) { Preconditions.checkNotNull(hostName, "Hostname could not be null"); Preconditions.checkArgument(!Strings.isNullOrEmpty(hostName), "Hostname could not be empty"); Port.assertValid(port); this.hostName = hostName; this.port = port; }
@VisibleForTesting Host(String hostName, int port) { Preconditions.checkNotNull(hostName, "Hostname could not be null"); Preconditions.checkArgument(!Strings.isNullOrEmpty(hostName), "Hostname could not be empty"); Port.assertValid(port); this.hostName = hostName; this.port = port; }
@Override public void init() throws MessagingException { spamdHost = Optional.ofNullable(getInitParameter(SPAMD_HOST)) .filter(s -> !Strings.isNullOrEmpty(s)) .orElse(DEFAULT_HOST); spamdPort = MailetUtil.getInitParameterAsStrictlyPositiveInteger(getInitParameter(SPAMD_PORT), DEFAULT_PORT); Port.assertValid(spamdPort); }
@Test public void assertValidShouldThrowOnNegativePort() { assertThatThrownBy(() -> Port.assertValid(-1)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void assertValidShouldThrowOnZeroPort() { assertThatThrownBy(() -> Port.assertValid(0)) .isInstanceOf(IllegalArgumentException.class); }
@Test void assertValidShouldThrowOnNegativePort() { assertThatThrownBy(() -> Port.assertValid(-1)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void assertValidShouldThrowOnTooBigValue() { assertThatThrownBy(() -> Port.assertValid(Port.MAX_PORT_VALUE + 1)) .isInstanceOf(IllegalArgumentException.class); }
@Test void assertValidShouldThrowOnTooBigValue() { assertThatThrownBy(() -> Port.assertValid(Port.MAX_PORT_VALUE + 1)) .isInstanceOf(IllegalArgumentException.class); }
@Test void assertValidShouldThrowOnZeroPort() { assertThatThrownBy(() -> Port.assertValid(0)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void assertValidShouldAcceptMaxValue() { Port.assertValid(Port.MAX_PORT_VALUE); }
@Test public void assertValidShouldAcceptOne() { Port.assertValid(1); }
@Test void assertValidShouldAcceptMaxValue() { Port.assertValid(Port.MAX_PORT_VALUE); }
@Test void assertValidShouldAcceptOne() { Port.assertValid(1); }