### Question:
DiffApplyingPrimitiveLongIterator extends PrimitiveLongBaseIterator implements PrimitiveLongResourceIterator { static LongIterator augment( LongIterator source, LongSet addedElements, LongSet removedElements ) { return new DiffApplyingPrimitiveLongIterator( source, addedElements, removedElements, null ); } private  DiffApplyingPrimitiveLongIterator( LongIterator source, LongSet addedElements,
            LongSet removedElements,
            @Nullable Resource resource ); @Override void close();  }### Answer:
@Test public void iterateOnlyOverAddedElementsWhenSourceIsEmpty() { LongIterator emptySource = ImmutableEmptyLongIterator.INSTANCE; LongSet added = LongHashSet.newSetWith( 1L, 2L ); LongSet removed = LongHashSet.newSetWith( 3L ); LongIterator iterator = DiffApplyingPrimitiveLongIterator.augment( emptySource, added, removed ); Set<Long> resultSet = toSet( iterator ); assertThat( resultSet, containsInAnyOrder(1L, 2L) ); }
@Test public void appendSourceElementsDuringIteration() { LongIterator source = iterator( 4L, 5L ); LongSet added = LongHashSet.newSetWith( 1L, 2L ); LongSet removed = LongHashSet.newSetWith( 3L ); LongIterator iterator = DiffApplyingPrimitiveLongIterator.augment( source, added, removed ); Set<Long> resultSet = toSet( iterator ); assertThat( resultSet, containsInAnyOrder(1L, 2L, 4L, 5L) ); }
@Test public void doNotIterateTwiceOverSameElementsWhenItsPartOfSourceAndAdded() { LongIterator source = iterator( 4L, 5L ); LongSet added = LongHashSet.newSetWith( 1L, 4L ); LongSet removed = LongHashSet.newSetWith( 3L ); LongIterator iterator = DiffApplyingPrimitiveLongIterator.augment( source, added, removed ); Long[] values = ArrayUtils.toObject( asArray( iterator ) ); assertThat( values, arrayContainingInAnyOrder( 1L, 4L, 5L ) ); assertThat( values, arrayWithSize( 3 ) ); }
@Test public void doNotIterateOverDeletedElement() { LongIterator source = iterator( 3L, 5L ); LongSet added = LongHashSet.newSetWith( 1L ); LongSet removed = LongHashSet.newSetWith( 3L ); LongIterator iterator = DiffApplyingPrimitiveLongIterator.augment( source, added, removed ); Set<Long> resultSet = toSet( iterator ); assertThat( resultSet, containsInAnyOrder(1L, 5L) ); }