### Question:
ShardSetFinder { public Map<String, MongoClient> findShardSets(MongoClient mongoS) { DBCursor find = mongoS.getDB("admin").getSisterDB("config") .getCollection("shards").find(); Map<String, MongoClient> shardSets = new HashMap<String, MongoClient>(); while (find.hasNext()) { DBObject next = find.next(); System.out.println("Adding " + next); String key = (String) next.get("_id"); shardSets.put(key, getMongoClient(buildServerAddressList(next))); } find.close(); return shardSets; }  Map<String, MongoClient> findShardSets(MongoClient mongoS); MongoClient getMongoClient(List<ServerAddress> shardSet);  }### Answer:
@Test public void findReplicaSetsForShards() { MongoClient mc = mock(MongoClient.class); DB adminDB = mock(DB.class); DB configDB = mock(DB.class); DBCollection shardCol = mock(DBCollection.class); DBCursor replCur = mock(DBCursor.class); when(mc.getDB("admin")).thenReturn(adminDB); when(adminDB.getSisterDB("config")).thenReturn(configDB); when(configDB.getCollection("shards")).thenReturn(shardCol); when(shardCol.find()).thenReturn(replCur); when(replCur.next()).thenReturn( new BasicDBObject("_id", "s0").append("host", "s0/localhost:37017,localhost:37018,localhost:37019"), new BasicDBObject("_id", "s1").append("host", "s1/localhost:47017,localhost:47018,localhost:47019"), new BasicDBObject("_id", "s2").append("host", "s2/localhost:57017,localhost:57018,localhost:57019")); when(replCur.hasNext()).thenReturn(true, true, true, false); ShardSetFinder finder = new ShardSetFinder(); Map<String, List<String>> expected = new HashMap<String, List<String>>(); expected.put( "s0", Arrays.asList(new String[] { "localhost:37017", "localhost:37018", "localhost:37019" })); expected.put( "s1", Arrays.asList(new String[] { "localhost:47017", "localhost:47018", "localhost:47019" })); expected.put( "s2", Arrays.asList(new String[] { "localhost:57017", "localhost:57018", "localhost:57019" })); Map<String, MongoClient> actual = finder.findShardSets(mc); System.out.println(expected); }