### Question:
ConsistentHash { public List<T> getNUniqueNodesFor(Object key, int n) { if (circle.isEmpty()) { return Collections.emptyList(); } if (n > realNodes.size()) { n = realNodes.size(); } List<T> list = new ArrayList<>(n); int hash = hashFunction.hash(key); for (int i = 0; i < n; i++) { if (!circle.containsKey(hash)) { SortedMap<Integer, T> tailMap = circle.tailMap(hash); hash = tailMap.isEmpty() ? circle.firstKey() : tailMap.firstKey(); } T candidate = circle.get(hash); if (!list.contains(candidate)) { list.add(candidate); } else { i--; } hash++; } return list; } ConsistentHash(int numberOfReplicas, Collection<T> nodes);  ConsistentHash(HashFunction hashFunction, int numberOfReplicas, Collection<T> nodes); T getNodeFor(Object key); List<T> getNUniqueNodesFor(Object key, int n); List<T> getNUniqueNodesFor(Object key, int n, List<String> disasterList);  }### Answer:
@Test public void getNUniqueNodesFor() { String key = "test"; List<TestNode> uniqueNodes = consistentHash.getNUniqueNodesFor(key, 3); LOGGER.info("getNUniqueNodesFor key: {}, result: {}", key, uniqueNodes); assertNotNull(uniqueNodes); assertEquals(uniqueNodes.size(), new HashSet<>(uniqueNodes).size()); }
@Test public void getNUniqueNodesForRealNodesSize() { String key = "test"; List<TestNode> uniqueNodes = consistentHash.getNUniqueNodesFor(key, testNodes.size()); LOGGER.info("getNUniqueNodesForRealNodesSize key: {}, result: {}", key, uniqueNodes); assertNotNull(uniqueNodes); assertEquals(testNodes.size(), new HashSet<>(uniqueNodes).size()); }
@Test public void getNUniqueNodesForMoreThanRealNodesSize() { String key = "test"; List<TestNode> uniqueNodes = consistentHash.getNUniqueNodesFor(key, testNodes.size() + 1); LOGGER .info("getNUniqueNodesForMoreThanRealNodesSize key: {}, result: {}", key, uniqueNodes); assertNotNull(uniqueNodes); assertEquals(testNodes.size(), new HashSet<>(uniqueNodes).size()); }
@Test public void getNUniqueNodesForZero() { String key = "test"; List<TestNode> uniqueNodes = consistentHash.getNUniqueNodesFor(key, 0); LOGGER.info("getNUniqueNodesForZero key: {}, result: {}", key, uniqueNodes); assertNotNull(uniqueNodes); assertTrue(uniqueNodes.isEmpty()); }