CassandraDependenciesJob { static String parsePort(String contactPoints) { Set<Integer> ports = Sets.newLinkedHashSet(); for (String contactPoint : contactPoints.split(",", -1)) { HostAndPort parsed = HostAndPort.fromString(contactPoint); ports.add(parsed.getPortOrDefault(9042)); } return ports.size() == 1 ? String.valueOf(ports.iterator().next()) : "9042"; } CassandraDependenciesJob(Builder builder); static Builder builder(); void run();  }
@Test public void parsePort_ignoresHostSection() { assertThat(parsePort("1.1.1.1:9142")) .isEqualTo("9142"); }
@Test public void parsePort_multiple_consistent() { assertThat(parsePort("1.1.1.1:9143,2.2.2.2:9143")) .isEqualTo("9143"); }
@Test public void parsePort_defaultsTo9042() { assertThat(parsePort("1.1.1.1")) .isEqualTo("9042"); }
@Test public void parsePort_defaultsTo9042_multi() { assertThat(parsePort("1.1.1.1:9143,2.2.2.2")) .isEqualTo("9042"); }