Port { public static boolean isValid(int port) { return VALID_PORT_RANGE.contains(port); } Port(int value); static Port of(int portNumber); static int generateValidUnprivilegedPort(); static void assertValid(int port); static boolean isValid(int port); int getValue(); @Override final boolean equals(Object o); @Override final int hashCode(); static final int MAX_PORT_VALUE; static final int PRIVILEGED_PORT_BOUND; }
@Test void isValidShouldReturnFalseWhenNegative() { assertThat(Port.isValid(-1)) .isFalse(); }
@Test void isValidShouldReturnFalseWhenZero() { assertThat(Port.isValid(0)) .isFalse(); }
@Test void isValidShouldReturnTrueWhenOne() { assertThat(Port.isValid(1)) .isTrue(); }
@Test void isValidShouldReturnTrueWhenMaxValue() { assertThat(Port.isValid(Port.MAX_PORT_VALUE)) .isTrue(); }
@Test void isValidShouldReturnFalseWhenAboveMaxValue() { assertThat(Port.isValid(Port.MAX_PORT_VALUE + 1)) .isFalse(); }