Refactor map test in PairTest
This commit is contained in:
parent
fc3f9c790f
commit
9e4a50d4e4
|
@ -26,18 +26,29 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.lang3.AbstractLangTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* Test the Pair class.
|
||||
*/
|
||||
public class PairTest extends AbstractLangTest {
|
||||
|
||||
public static Stream<Class<? extends Map>> mapClassFactory() {
|
||||
return Stream.of(ConcurrentHashMap.class, ConcurrentSkipListMap.class, HashMap.class, TreeMap.class, WeakHashMap.class, LinkedHashMap.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccept() {
|
||||
final Pair<String, String> pair1 = Pair.of("A", "D");
|
||||
|
@ -128,6 +139,16 @@ public class PairTest extends AbstractLangTest {
|
|||
assertEquals("(Key,Value)", String.format("%1$s", pair));
|
||||
}
|
||||
|
||||
@ParameterizedTest()
|
||||
@MethodSource("org.apache.commons.lang3.tuple.PairTest#mapClassFactory()")
|
||||
public <K, V> void testMapEntries(final Class<Map<Integer, String>> clazz) throws InstantiationException, IllegalAccessException {
|
||||
testMapEntry(clazz.newInstance());
|
||||
}
|
||||
|
||||
public <K, V> void testMapEntries(final Map<Integer, String> map) {
|
||||
testMapEntry(map);
|
||||
}
|
||||
|
||||
private void testMapEntry(final Map<Integer, String> map) {
|
||||
map.put(0, "foo");
|
||||
final Entry<Integer, String> entry = map.entrySet().iterator().next();
|
||||
|
@ -145,16 +166,6 @@ public class PairTest extends AbstractLangTest {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapEntryConcurrentHashMap() {
|
||||
testMapEntry(new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapEntryHashMap() {
|
||||
testMapEntry(new HashMap<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfNonNull() {
|
||||
assertThrows(NullPointerException.class, () -> Pair.ofNonNull(null, null));
|
||||
|
|
Loading…
Reference in New Issue