BAEL-2181 complete commit (#5294)
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CombiningArraysUnitTest {
|
||||
private static final String first[] = {
|
||||
"One",
|
||||
"Two",
|
||||
"Three"
|
||||
};
|
||||
|
||||
private static final String second[] = {
|
||||
"Four",
|
||||
"Five",
|
||||
"Six"
|
||||
};
|
||||
|
||||
private static final String expected[] = {
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Four",
|
||||
"Five",
|
||||
"Six"
|
||||
};
|
||||
|
||||
@Test
|
||||
public void givenTwoArrays_whenUsingNativeJava_thenArraysCombined() {
|
||||
assertArrayEquals(expected, CombiningArrays.usingNativeJava(first, second));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoArrays_whenUsingObjectStreams_thenArraysCombined() {
|
||||
assertArrayEquals(expected, CombiningArrays.usingJava8ObjectStream(first, second));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoArrays_whenUsingFlatMaps_thenArraysCombined() {
|
||||
assertArrayEquals(expected, CombiningArrays.usingJava8FlatMaps(first, second));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoArrays_whenUsingApacheCommons_thenArraysCombined() {
|
||||
assertArrayEquals(expected, CombiningArrays.usingApacheCommons(first, second));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoArrays_whenUsingGuava_thenArraysCombined() {
|
||||
assertArrayEquals(expected, CombiningArrays.usingGuava(first, second));
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CombiningListsUnitTest {
|
||||
private static final List<Object> first = Arrays.asList(new Object[]{
|
||||
"One",
|
||||
"Two",
|
||||
"Three"
|
||||
});
|
||||
|
||||
private static final List<Object> second = Arrays.asList(new Object[]{
|
||||
"Four",
|
||||
"Five",
|
||||
"Six"
|
||||
});
|
||||
|
||||
private static final List<Object> expected = Arrays.asList(new Object[]{
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Four",
|
||||
"Five",
|
||||
"Six"
|
||||
});
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenUsingNativeJava_thenArraysCombined() {
|
||||
assertThat(CombiningLists.usingNativeJava(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenUsingObjectStreams_thenArraysCombined() {
|
||||
assertThat(CombiningLists.usingJava8ObjectStream(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenUsingFlatMaps_thenArraysCombined() {
|
||||
assertThat(CombiningLists.usingJava8FlatMaps(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenUsingApacheCommons_thenArraysCombined() {
|
||||
assertThat(CombiningLists.usingApacheCommons(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoLists_whenUsingGuava_thenArraysCombined() {
|
||||
assertThat(CombiningLists.usingGuava(first, second), is(expected));
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CombiningMapsUnitTest {
|
||||
private static final Map<String, String> first = new HashMap<>();
|
||||
private static final Map<String, String> second = new HashMap<>();
|
||||
private static Map<String, String> expected = new HashMap<>();
|
||||
|
||||
static {
|
||||
first.put("one", "first String");
|
||||
first.put("two", "second String");
|
||||
|
||||
second.put("three", "third String");
|
||||
second.put("four", "fourth String");
|
||||
|
||||
expected.put("one", "first String");
|
||||
expected.put("two", "second String");
|
||||
expected.put("three", "third String");
|
||||
expected.put("four", "fourth String");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoMaps_whenUsingNativeJava_thenMapsCombined() {
|
||||
assertThat(CombiningMaps.usingPlainJava(first, second), is(expected));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenTwoMaps_whenUsingForEach_thenMapsCombined() {
|
||||
assertThat(CombiningMaps.usingJava8ForEach(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoMaps_whenUsingFlatMaps_thenMapsCombined() {
|
||||
assertThat(CombiningMaps.usingJava8FlatMaps(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoMaps_whenUsingApacheCommons_thenMapsCombined() {
|
||||
assertThat(CombiningMaps.usingApacheCommons(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoMaps_whenUsingGuava_thenMapsCombined() {
|
||||
assertThat(CombiningMaps.usingGuava(first, second), is(expected));
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
|
||||
package com.baeldung.combiningcollections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CombiningSetsUnitTest {
|
||||
private static final Set<Object> first = new HashSet<Object>(Arrays.asList(new Object[] { "One", "Two", "Three" }));
|
||||
|
||||
private static final Set<Object> second = new HashSet<Object>(Arrays.asList(new Object[] { "Four", "Five", "Six" }));
|
||||
|
||||
private static final Set<Object> expected = new HashSet<Object>(Arrays
|
||||
.asList(new Object[] { "One", "Two", "Three", "Four", "Five", "Six" }));
|
||||
|
||||
@Test
|
||||
public void givenTwoSets_whenUsingNativeJava_thenArraysCombined() {
|
||||
assertThat(CombiningSets.usingNativeJava(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoSets_whenUsingObjectStreams_thenArraysCombined() {
|
||||
assertThat(CombiningSets.usingJava8ObjectStream(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoSets_whenUsingFlatMaps_thenArraysCombined() {
|
||||
assertThat(CombiningSets.usingJava8FlatMaps(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoSets_whenUsingApacheCommons_thenArraysCombined() {
|
||||
assertThat(CombiningSets.usingApacheCommons(first, second), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoSets_whenUsingGuava_thenArraysCombined() {
|
||||
assertThat(CombiningSets.usingGuava(first, second), is(expected));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user