From a963a123f73a0dde67d7c8f0c6ebb88a1e43aac4 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 12 Jan 2020 10:17:05 -0500 Subject: [PATCH] Sort methods. --- .../collections4/IteratorUtilsTest.java | 370 +++++++++--------- 1 file changed, 185 insertions(+), 185 deletions(-) diff --git a/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java b/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java index ce2291b48..87d943771 100644 --- a/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java @@ -436,6 +436,11 @@ public class IteratorUtilsTest { } } + @Test(expected = NullPointerException.class) + public void testAsEnumerationNull() { + IteratorUtils.asEnumeration(null); + } + @Test public void testAsIterable() { final List list = new ArrayList<>(); @@ -467,6 +472,37 @@ public class IteratorUtilsTest { } } + @Test(expected = NullPointerException.class) + public void testAsIterator() { + final Vector vector = new Vector<>(); + vector.addElement("zero"); + vector.addElement("one"); + Enumeration en = vector.elements(); + assertTrue("create instance fail", IteratorUtils.asIterator(en) instanceof Iterator); + IteratorUtils.asIterator(null); + } + + @Test + public void testAsIteratorNull() { + Collection coll = new ArrayList(); + coll.add("test"); + final Vector vector = new Vector<>(); + vector.addElement("test"); + vector.addElement("one"); + Enumeration en = vector.elements(); + assertTrue("create instance fail", IteratorUtils.asIterator(en, coll) instanceof Iterator); + try { + IteratorUtils.asIterator(null, coll); + } catch (NullPointerException npe) { + // + } + try { + IteratorUtils.asIterator(en, null); + } catch (NullPointerException npe) { + // + } + } + @Test public void testAsMultipleIterable() { final List list = new ArrayList<>(); @@ -504,6 +540,16 @@ public class IteratorUtilsTest { } } + @Test + public void testChainedIterator() { + ArrayList arrayList = new ArrayList(); + Iterator ie = arrayList.iterator(); + assertTrue("create instance fail", IteratorUtils.chainedIterator(ie) instanceof Iterator); + final Collection> coll = new ArrayList(); + assertTrue("create instance fail", IteratorUtils.chainedIterator(coll) instanceof Iterator); + + } + /** * Tests methods collatedIterator(...) */ @@ -553,6 +599,42 @@ public class IteratorUtilsTest { assertEquals(combinedList, result); } + @Test(expected = NullPointerException.class) + public void testCollatedIteratorCollectionNull() { + Collection> coll = new ArrayList<>(); + coll.add(collectionOdd.iterator()); + // natural ordering + Iterator it = IteratorUtils.collatedIterator(null, coll); + List result = IteratorUtils.toList(it); + assertEquals(6, result.size()); + IteratorUtils.collatedIterator(null, (Collection>) null); + } + + @Test(expected = NullPointerException.class) + public void testCollatedIteratorNull() { + ArrayList arrayList = new ArrayList(); + // natural ordering + Iterator it = IteratorUtils.collatedIterator(null, collectionOdd.iterator(), collectionOdd.iterator(), + collectionOdd.iterator()); + + List result = IteratorUtils.toList(it); + assertEquals(18, result.size()); + + it = IteratorUtils.collatedIterator(null, collectionOdd.iterator()); + result = IteratorUtils.toList(it); + assertEquals(collectionOdd, result); + + final Comparator reverseComparator = ComparatorUtils + .reversedComparator(ComparatorUtils.naturalComparator()); + + Collections.reverse(collectionOdd); + + it = IteratorUtils.collatedIterator(reverseComparator, collectionOdd.iterator()); + result = IteratorUtils.toList(it); + assertEquals(collectionOdd, result); + IteratorUtils.collatedIterator(null, arrayList.iterator(), arrayList.listIterator(), null); + } + // ----------------------------------------------------------------------- /** * Test empty iterator @@ -758,6 +840,41 @@ public class IteratorUtilsTest { } } + @Test + public void testFilteredIterator() { + ArrayList arrayList = new ArrayList(); + Iterator ie = arrayList.iterator(); + try { + IteratorUtils.filteredIterator(ie, null); + } catch (NullPointerException npe) { + // + } + try { + IteratorUtils.filteredIterator(null, null); + } catch (NullPointerException npe) { + // + } + } + + @Test + public void testFilteredListIterator() { + List arrayList = new ArrayList(); + arrayList.add("test"); + Predicate predicate = INSTANCE; + assertTrue("create instance fail", + IteratorUtils.filteredListIterator(arrayList.listIterator(), predicate) instanceof ListIterator); + try { + IteratorUtils.filteredListIterator(null, predicate); + } catch (NullPointerException npe) { + // + } + try { + IteratorUtils.filteredListIterator(arrayList.listIterator(), null); + } catch (NullPointerException npe) { + // + } + } + @Test public void testFind() { Predicate testPredicate = equalPredicate((Number) 4); @@ -906,6 +1023,26 @@ public class IteratorUtilsTest { } } + @Test(expected = NullPointerException.class) + public void testLoopingIterator() { + ArrayList arrayList = new ArrayList(); + arrayList.add("test"); + Collection coll = new ArrayList(); + coll.add("test"); + Iterator ie = arrayList.iterator(); + assertTrue("create instance fail", IteratorUtils.loopingIterator(coll) instanceof ResettableIterator); + IteratorUtils.loopingIterator(null); + } + + @Test(expected = NullPointerException.class) + public void testLoopingListIterator() { + ArrayList arrayList = new ArrayList(); + arrayList.add("test"); + Iterator ie = arrayList.iterator(); + assertTrue("create instance fail", IteratorUtils.loopingListIterator(arrayList) instanceof ResettableIterator); + IteratorUtils.loopingListIterator(null); + } + /** * Tests method nodeListIterator(Node) */ @@ -967,6 +1104,38 @@ public class IteratorUtilsTest { } } + @Test + public void testObjectGraphIterator() { + assertTrue("create instance fail", IteratorUtils.objectGraphIterator(null, null) instanceof Iterator); + } + + @Test(expected = NullPointerException.class) + public void testPeekingIterator() { + ArrayList arrayList = new ArrayList(); + Iterator ie = arrayList.iterator(); + assertTrue("create instance fail", IteratorUtils.peekingIterator(ie) instanceof Iterator); + IteratorUtils.peekingIterator(null); + + } + + @Test(expected = NullPointerException.class) + public void testPushBackIterator() { + ArrayList arrayList = new ArrayList(); + Iterator ie = arrayList.iterator(); + assertTrue("create instance fail", IteratorUtils.pushbackIterator(ie) instanceof Iterator); + IteratorUtils.pushbackIterator(null); + } + + @Test + public void testSingletonIterator() { + assertTrue("create instance fail", IteratorUtils.singletonIterator(new Object()) instanceof ResettableIterator); + } + + @Test + public void testSingletonListIterator() { + assertTrue("create instance fail", IteratorUtils.singletonListIterator(new Object()) instanceof Iterator); + } + @Test public void testToArray() { final List list = new ArrayList<>(); @@ -1059,6 +1228,22 @@ public class IteratorUtilsTest { } } + @Test + public void testTransformedIterator() { + ArrayList arrayList = new ArrayList(); + Iterator ie = arrayList.iterator(); + try { + IteratorUtils.transformedIterator(ie, null); + } catch (NullPointerException npe) { + // + } + try { + IteratorUtils.transformedIterator(null, null); + } catch (NullPointerException npe) { + // + } + } + /** * Test remove() for an immutable Iterator. */ @@ -1222,23 +1407,6 @@ public class IteratorUtilsTest { assertTrue(listIterator.hasNext()); } - @Test(expected = NullPointerException.class) - public void testPushBackIterator() { - ArrayList arrayList = new ArrayList(); - Iterator ie = arrayList.iterator(); - assertTrue("create instance fail", IteratorUtils.pushbackIterator(ie) instanceof Iterator); - IteratorUtils.pushbackIterator(null); - } - - @Test(expected = NullPointerException.class) - public void testPeekingIterator() { - ArrayList arrayList = new ArrayList(); - Iterator ie = arrayList.iterator(); - assertTrue("create instance fail", IteratorUtils.peekingIterator(ie) instanceof Iterator); - IteratorUtils.peekingIterator(null); - - } - @Test(expected = NullPointerException.class) public void testUnmodifiableMapIterator() { Set set = new LinkedHashSet<>(); @@ -1248,36 +1416,6 @@ public class IteratorUtilsTest { } - @Test - public void testChainedIterator() { - ArrayList arrayList = new ArrayList(); - Iterator ie = arrayList.iterator(); - assertTrue("create instance fail", IteratorUtils.chainedIterator(ie) instanceof Iterator); - final Collection> coll = new ArrayList(); - assertTrue("create instance fail", IteratorUtils.chainedIterator(coll) instanceof Iterator); - - } - - @Test - public void testSingletonIterator() { - assertTrue("create instance fail", IteratorUtils.singletonIterator(new Object()) instanceof ResettableIterator); - } - - @Test - public void testSingletonListIterator() { - assertTrue("create instance fail", IteratorUtils.singletonListIterator(new Object()) instanceof Iterator); - } - - @Test(expected = NullPointerException.class) - public void testAsEnumerationNull() { - IteratorUtils.asEnumeration(null); - } - - @Test - public void testObjectGraphIterator() { - assertTrue("create instance fail", IteratorUtils.objectGraphIterator(null, null) instanceof Iterator); - } - @Test public void testZippingIterator() { ArrayList arrayList = new ArrayList(); @@ -1285,142 +1423,4 @@ public class IteratorUtilsTest { assertTrue("create instance fail", IteratorUtils.zippingIterator(ie, ie, ie) instanceof ZippingIterator); assertTrue("create instance fail", IteratorUtils.zippingIterator(ie, ie) instanceof ZippingIterator); } - - @Test - public void testFilteredIterator() { - ArrayList arrayList = new ArrayList(); - Iterator ie = arrayList.iterator(); - try { - IteratorUtils.filteredIterator(ie, null); - } catch (NullPointerException npe) { - // - } - try { - IteratorUtils.filteredIterator(null, null); - } catch (NullPointerException npe) { - // - } - } - - @Test - public void testTransformedIterator() { - ArrayList arrayList = new ArrayList(); - Iterator ie = arrayList.iterator(); - try { - IteratorUtils.transformedIterator(ie, null); - } catch (NullPointerException npe) { - // - } - try { - IteratorUtils.transformedIterator(null, null); - } catch (NullPointerException npe) { - // - } - } - - @Test(expected = NullPointerException.class) - public void testAsIterator() { - final Vector vector = new Vector<>(); - vector.addElement("zero"); - vector.addElement("one"); - Enumeration en = vector.elements(); - assertTrue("create instance fail", IteratorUtils.asIterator(en) instanceof Iterator); - IteratorUtils.asIterator(null); - } - - @Test - public void testAsIteratorNull() { - Collection coll = new ArrayList(); - coll.add("test"); - final Vector vector = new Vector<>(); - vector.addElement("test"); - vector.addElement("one"); - Enumeration en = vector.elements(); - assertTrue("create instance fail", IteratorUtils.asIterator(en, coll) instanceof Iterator); - try { - IteratorUtils.asIterator(null, coll); - } catch (NullPointerException npe) { - // - } - try { - IteratorUtils.asIterator(en, null); - } catch (NullPointerException npe) { - // - } - } - - @Test(expected = NullPointerException.class) - public void testLoopingIterator() { - ArrayList arrayList = new ArrayList(); - arrayList.add("test"); - Collection coll = new ArrayList(); - coll.add("test"); - Iterator ie = arrayList.iterator(); - assertTrue("create instance fail", IteratorUtils.loopingIterator(coll) instanceof ResettableIterator); - IteratorUtils.loopingIterator(null); - } - - @Test(expected = NullPointerException.class) - public void testLoopingListIterator() { - ArrayList arrayList = new ArrayList(); - arrayList.add("test"); - Iterator ie = arrayList.iterator(); - assertTrue("create instance fail", IteratorUtils.loopingListIterator(arrayList) instanceof ResettableIterator); - IteratorUtils.loopingListIterator(null); - } - - @Test(expected = NullPointerException.class) - public void testCollatedIteratorNull() { - ArrayList arrayList = new ArrayList(); - // natural ordering - Iterator it = IteratorUtils.collatedIterator(null, collectionOdd.iterator(), collectionOdd.iterator(), - collectionOdd.iterator()); - - List result = IteratorUtils.toList(it); - assertEquals(18, result.size()); - - it = IteratorUtils.collatedIterator(null, collectionOdd.iterator()); - result = IteratorUtils.toList(it); - assertEquals(collectionOdd, result); - - final Comparator reverseComparator = ComparatorUtils - .reversedComparator(ComparatorUtils.naturalComparator()); - - Collections.reverse(collectionOdd); - - it = IteratorUtils.collatedIterator(reverseComparator, collectionOdd.iterator()); - result = IteratorUtils.toList(it); - assertEquals(collectionOdd, result); - IteratorUtils.collatedIterator(null, arrayList.iterator(), arrayList.listIterator(), null); - } - - @Test(expected = NullPointerException.class) - public void testCollatedIteratorCollectionNull() { - Collection> coll = new ArrayList<>(); - coll.add(collectionOdd.iterator()); - // natural ordering - Iterator it = IteratorUtils.collatedIterator(null, coll); - List result = IteratorUtils.toList(it); - assertEquals(6, result.size()); - IteratorUtils.collatedIterator(null, (Collection>) null); - } - - @Test - public void testFilteredListIterator() { - List arrayList = new ArrayList(); - arrayList.add("test"); - Predicate predicate = INSTANCE; - assertTrue("create instance fail", - IteratorUtils.filteredListIterator(arrayList.listIterator(), predicate) instanceof ListIterator); - try { - IteratorUtils.filteredListIterator(null, predicate); - } catch (NullPointerException npe) { - // - } - try { - IteratorUtils.filteredListIterator(arrayList.listIterator(), null); - } catch (NullPointerException npe) { - // - } - } }