class 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";
  }

}

class CassandraDependenciesJobTest {

  @Test
  public void parsePort_defaultsTo9042() {

    assertThat(parsePort("1.1.1.1"))
        .isEqualTo("9042");
  }

}