Host { public static Host parseConfString(String ipAndPort, int defaultPort) { return parse(ipAndPort, Optional.of(defaultPort)); } @VisibleForTesting  Host(String hostName, int port); static ImmutableList<Host> parseHosts(String hostsString); static ImmutableList<Host> parseHosts(String hostsString, int defaultPort); static Host from(String hostname, int port); static Host parseConfString(String ipAndPort, int defaultPort); static Host parseConfString(String ipAndPort); static Host parse(String ipAndPort, Optional<Integer> defaultPort); String getHostName(); int getPort(); @Override final int hashCode(); @Override final boolean equals(Object object); String asString(); @Override String toString();  }
@Test void parseConfStringShouldParseConfWithIpAndPort() { int expectedPort = 44; String expectedIp = "142.145.254.111"; String ipAndPort = expectedIp + ":" + 44; Host actual = Host.parseConfString(ipAndPort); assertThat(actual).isEqualTo(new Host(expectedIp, expectedPort)); }
@Test void parseConfStringShouldParseConfWithHostanmeAndPort() { int expectedPort = 44; String host = "host"; Host actual = Host.parseConfString(host + ":" + expectedPort); assertThat(actual).isEqualTo(new Host(host, expectedPort)); }
@Test void parseConfStringShouldParseConfWithHostOnlyWhenDefaultPortIsProvided() { String ipAndPort = "142.145.254.111"; String expectedIp = "142.145.254.111"; Host actual = Host.parseConfString(ipAndPort, DEFAULT_PORT); assertThat(actual).isEqualTo(new Host(expectedIp, DEFAULT_PORT)); }
@Test void parseConfStringShouldFailWhenConfigIsAnEmptyString() { assertThatIllegalArgumentException() .isThrownBy(() -> Host.parseConfString("")); }
@Test void parseConfStringShouldFailWhenOnlyHostnameAndNoDefaultPort() { assertThatIllegalArgumentException() .isThrownBy(() -> Host.parseConfString("hostnameOnly")); }
@Test void parseConfStringShouldFailWhenNegativePort() { assertThatIllegalArgumentException() .isThrownBy(() -> Host.parseConfString("host:-1")); }
@Test void parseConfStringShouldFailWhenZeroPort() { assertThatIllegalArgumentException() .isThrownBy(() -> Host.parseConfString("host:0")); }
@Test void parseConfStringShouldFailWhenTooHighPort() { assertThatIllegalArgumentException() .isThrownBy(() -> Host.parseConfString("host:65536")); }
@Test void parseConfStringShouldFailWhenConfigIsANullString() { assertThatNullPointerException() .isThrownBy(() -> Host.parseConfString(null)); }
@Test void parseConfStringShouldFailWhenConfigIsInvalid() { assertThatIllegalArgumentException() .isThrownBy(() -> Host.parseConfString("10.10.10.10:42:43")); }