diff --git a/core-java/src/test/java/org/baeldung/java/collections/CollectionsConcatenateUnitTest.java b/core-java/src/test/java/org/baeldung/java/collections/CollectionsConcatenateUnitTest.java index 0d913db1bd..d43075c925 100644 --- a/core-java/src/test/java/org/baeldung/java/collections/CollectionsConcatenateUnitTest.java +++ b/core-java/src/test/java/org/baeldung/java/collections/CollectionsConcatenateUnitTest.java @@ -2,6 +2,9 @@ package org.baeldung.java.collections; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.IterableUtils; import org.junit.Assert; import org.junit.Test; @@ -107,4 +110,26 @@ public class CollectionsConcatenateUnitTest { } return list; } + + @Test + public void givenUsingApacheCommons_whenConcatenatingUsingUnion_thenCorrect() { + Collection collectionA = asList("S", "T"); + Collection collectionB = asList("U", "V"); + + Iterable combinedIterables = CollectionUtils.union(collectionA, collectionB); + Collection collectionCombined = Lists.newArrayList(combinedIterables); + + Assert.assertEquals(asList("S", "T", "U", "V"), collectionCombined); + } + + @Test + public void givenUsingApacheCommons_whenConcatenatingUsingChainedIterable_thenCorrect() { + Collection collectionA = asList("S", "T"); + Collection collectionB = asList("U", "V"); + + Iterable combinedIterables = IterableUtils.chainedIterable(collectionA, collectionB); + Collection collectionCombined = Lists.newArrayList(combinedIterables); + + Assert.assertEquals(asList("S", "T", "U", "V"), collectionCombined); + } }