### Question:
KeyspaceHelper { public static Set<String> getDatacentersForKeyspace(Metadata metadata, String keyspace) { Set<String> datacenters = new HashSet<>(); Map<String, String> replication = metadata.getKeyspace(keyspace).getReplication(); String replicationClass = replication.get(REPLICATION_CLASS); if (replicationClass.endsWith("NetworkTopologyStrategy")) { for (String key : replication.keySet()) { if (!REPLICATION_CLASS.equals(key)) { datacenters.add(key); } } } else { for (Host host : metadata.getAllHosts()) { datacenters.add(host.getDatacenter()); } } return datacenters; } private  KeyspaceHelper(); static Set<String> getDatacentersForKeyspace(Metadata metadata, String keyspace); static Set<String> getDatacenters(Metadata metadata);  }### Answer:
@Test public void testGetDatacentersWithNetworkTopologyStrategy() { replicationMap.put("class", "org.apache.cassandra.locator.NetworkTopologyStrategy"); replicationMap.put("dc1", "3"); replicationMap.put("dc2", "3"); Collection<String> datacenters = KeyspaceHelper.getDatacentersForKeyspace(metadata, keyspaceName); assertThat(datacenters).containsOnly("dc1", "dc2"); }
@Test public void testGetDatacentersWithSimpleStrategy() { replicationMap.put("class", "org.apache.cassandra.locator.SimpleStrategy"); replicationMap.put("replication_factor", "3"); Host host1 = mock(Host.class); Host host2 = mock(Host.class); Set<Host> hosts = new HashSet<>(); hosts.add(host1); hosts.add(host2); when(metadata.getAllHosts()).thenReturn(hosts); when(host1.getDatacenter()).thenReturn("dc1"); when(host2.getDatacenter()).thenReturn("dc2"); Collection<String> datacenters = KeyspaceHelper.getDatacentersForKeyspace(metadata, keyspaceName); assertThat(datacenters).containsOnly("dc1", "dc2"); }