### Question:
UniqueTransform extends DocumentTransform.DefaultDocumentTransform { @Nullable @Override public Entry<Key,Document> apply(@Nullable Entry<Key,Document> keyDocumentEntry) { if (keyDocumentEntry != null) { try { if (isDuplicate(keyDocumentEntry.getValue())) { keyDocumentEntry = null; } } catch (IOException ioe) { log.error("Failed to convert document to bytes. Returning document as unique.", ioe); } } return keyDocumentEntry; } UniqueTransform(Set<String> fields);  UniqueTransform(BaseQueryLogic<Entry<Key,Value>> logic, Set<String> fields); Predicate<Entry<Key,Document>> getUniquePredicate(); @Nullable @Override Entry<Key,Document> apply(@Nullable Entry<Key,Document> keyDocumentEntry);  }### Answer:
@Test public void testUniqueness() { Random random = new Random(2000); List<Document> input = new ArrayList<>(); for (int i = 0; i < 100; i++) { input.add(createDocument(random, false)); } Set<String> fields = new HashSet<>(); int expected = input.size(); while (expected > input.size() / 2 || expected < 10) { fields.clear(); while (fields.size() < 3) { fields.add("Attr" + random.nextInt(100)); } expected = countUniqueness(input, fields); } Transformer docToEntry = input1 -> { Document d = (Document) input1; return Maps.immutableEntry(d.getMetadata(), d); }; TransformIterator inputIterator = new TransformIterator(input.iterator(), docToEntry); fields = fields.stream().map(field -> (random.nextBoolean() ? '$' + field : field)).collect(Collectors.toSet()); UniqueTransform transform = new UniqueTransform(fields); Iterator iter = Iterators.transform(inputIterator, transform); List<Object> eventList = Lists.newArrayList(); while (iter.hasNext()) { Object next = iter.next(); if (next != null) { eventList.add(next); } } Assert.assertEquals(expected, eventList.size()); Assert.assertNull(transform.apply(null)); }