NetworkStrategy implements ReplicationStrategy { @Override public String createCqlStatement() { if (getDataCenters().isEmpty()) { throw new IllegalStateException("There has to be at least one datacenter in order to use NetworkTopologyStrategy."); } StringBuilder builder = new StringBuilder(); builder.append("{") .append("'class':'").append(getName()).append("',"); builder.append(join(",", dataCenters.keySet().stream().map(dc -> "'" + dc + "':" + dataCenters.get(dc)) .collect(toSet()))); builder.append("}"); return builder.toString(); }  @Override String getName(); @Override String createCqlStatement(); NetworkStrategy with(String datacenter, int replicationFactor); Map<String, Integer> getDataCenters();  }
@Test(expected = IllegalStateException.class) public void shouldThrowExceptionWhenNoDatacenterGiven() { String json = new NetworkStrategy() .createCqlStatement(); assertThat(json, is(equalTo("{'class':'NetworkTopologyStrategy'}"))); }