### Question:
RemoteEvent { public Map<Integer, TargetChange> getTargetChanges() { return targetChanges; } RemoteEvent(
      SnapshotVersion snapshotVersion,
      Map<Integer, TargetChange> targetChanges,
      Set<Integer> targetMismatches,
      Map<DocumentKey, MaybeDocument> documentUpdates,
      Set<DocumentKey> resolvedLimboDocuments); SnapshotVersion getSnapshotVersion(); Map<Integer, TargetChange> getTargetChanges(); Set<Integer> getTargetMismatches(); Map<DocumentKey, MaybeDocument> getDocumentUpdates(); Set<DocumentKey> getResolvedLimboDocuments(); @Override String toString();  }### Answer:
@Test public void testResumeTokenHandledPerTarget() { Map<Integer, TargetData> targetMap = activeQueries(1, 2); WatchChangeAggregator aggregator = createAggregator(targetMap, noOutstandingResponses, noExistingKeys); WatchTargetChange change1 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1)); aggregator.handleTargetChange(change1); ByteString resumeToken2 = ByteString.copyFromUtf8("resumeToken2"); WatchTargetChange change2 = new WatchTargetChange(WatchTargetChangeType.Current, asList(2), resumeToken2); aggregator.handleTargetChange(change2); RemoteEvent event = aggregator.createRemoteEvent(version(3)); assertEquals(2, event.getTargetChanges().size()); TargetChange mapping1 = targetChange(resumeToken, true, null, null, null); assertEquals(mapping1, event.getTargetChanges().get(1)); TargetChange mapping2 = targetChange(resumeToken2, true, null, null, null); assertEquals(mapping2, event.getTargetChanges().get(2)); }
@Test public void testLastResumeTokenWins() { Map<Integer, TargetData> targetMap = activeQueries(1, 2); WatchChangeAggregator aggregator = createAggregator(targetMap, noOutstandingResponses, noExistingKeys); WatchTargetChange change1 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1)); aggregator.handleTargetChange(change1); ByteString resumeToken2 = ByteString.copyFromUtf8("resumeToken2"); WatchTargetChange change2 = new WatchTargetChange(WatchTargetChangeType.Current, asList(1), resumeToken2); aggregator.handleTargetChange(change2); ByteString resumeToken3 = ByteString.copyFromUtf8("resumeToken3"); WatchTargetChange change3 = new WatchTargetChange(WatchTargetChangeType.Current, asList(2), resumeToken3); aggregator.handleTargetChange(change3); RemoteEvent event = aggregator.createRemoteEvent(version(3)); assertEquals(2, event.getTargetChanges().size()); TargetChange mapping1 = targetChange(resumeToken2, true, null, null, null); assertEquals(mapping1, event.getTargetChanges().get(1)); TargetChange mapping2 = targetChange(resumeToken3, true, null, null, null); assertEquals(mapping2, event.getTargetChanges().get(2)); }
@Test public void testSeparatesUpdates() { Map<Integer, TargetData> targetMap = activeQueries(1); Document newDoc = doc("docs/new", 1, map("key", "value")); DocumentChange newDocChange = new DocumentChange(asList(1), emptyList(), newDoc.getKey(), newDoc); Document existingDoc = doc("docs/existing", 1, map("some", "data")); DocumentChange existingDocChange = new DocumentChange(asList(1), emptyList(), existingDoc.getKey(), existingDoc); NoDocument deletedDoc = deletedDoc("docs/deleted", 1); DocumentChange deletedDocChange = new DocumentChange(asList(1), emptyList(), deletedDoc.getKey(), deletedDoc); NoDocument missingDoc = deletedDoc("docs/missing ", 1); DocumentChange missingDocChange = new DocumentChange(asList(1), emptyList(), missingDoc.getKey(), missingDoc); RemoteEvent event = createRemoteEvent( 3, targetMap, noOutstandingResponses, keySet(existingDoc.getKey(), deletedDoc.getKey()), newDocChange, existingDocChange, deletedDocChange, missingDocChange); TargetChange mapping = targetChange(resumeToken, false, asList(newDoc), asList(existingDoc), asList(deletedDoc)); assertEquals(mapping, event.getTargetChanges().get(1)); }