You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/03/10 13:49:39 UTC

incubator-tinkerpop git commit: Add tests to IteratorUtils for convertToList.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master f3d99939c -> 243f01062


Add tests to IteratorUtils for convertToList.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/243f0106
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/243f0106
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/243f0106

Branch: refs/heads/master
Commit: 243f01062cc9b0a330f17a8661c1a41d48c08d75
Parents: f3d9993
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 08:49:17 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 08:49:17 2015 -0400

----------------------------------------------------------------------
 .../util/iterator/IteratorUtilsTest.java        | 65 ++++++++++++++++++++
 1 file changed, 65 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/243f0106/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
index a9bfe4b..a0b60d9 100644
--- a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtilsTest.java
@@ -89,6 +89,71 @@ public class IteratorUtilsTest {
         assertIterator(IteratorUtils.convertToIterator("test1"), 1);
     }
 
+    @Test
+    public void shouldConvertIterableToList() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertIterator(IteratorUtils.convertToList(iterable).iterator(), iterable.size());
+    }
+
+    @Test
+    public void shouldConvertIteratorToList() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertIterator(IteratorUtils.convertToList(iterable.iterator()).iterator(), iterable.size());
+    }
+
+    @Test
+    public void shouldConvertArrayToList() {
+        final String[] iterable = new String[3];
+        iterable[0] = "test1";
+        iterable[1] = "test2";
+        iterable[2] = "test3";
+        assertIterator(IteratorUtils.convertToList(iterable).iterator(), iterable.length);
+    }
+
+    @Test
+    public void shouldConvertThrowableToList() {
+        final Exception ex = new Exception("test1");
+        assertIterator(IteratorUtils.convertToList(ex).iterator(), 1);
+    }
+
+    @Test
+    public void shouldConvertStreamToList() {
+        final List<String> iterable = new ArrayList<>();
+        iterable.add("test1");
+        iterable.add("test2");
+        iterable.add("test3");
+        assertIterator(IteratorUtils.convertToList(iterable.stream()).iterator(), iterable.size());
+    }
+
+    @Test
+    public void shouldConvertMapToList() {
+        final Map<String,String> m = new HashMap<>();
+        m.put("key1", "val1");
+        m.put("key2", "val2");
+        m.put("key3", "val3");
+
+        final Iterator itty = IteratorUtils.convertToList(m).iterator();
+        for (int ix = 0; ix < m.size(); ix++) {
+            final Map.Entry entry = (Map.Entry) itty.next();
+            assertEquals("key" + (ix + 1), entry.getKey());
+            assertEquals("val" + (ix + 1), entry.getValue());
+        }
+
+        assertFalse(itty.hasNext());
+    }
+
+    @Test
+    public void shouldConvertAnythingElseToListByWrapping() {
+        assertIterator(IteratorUtils.convertToList("test1").iterator(), 1);
+    }
+
+
     public <S> void assertIterator(final Iterator<S> itty, final int size) {
         for (int ix = 0; ix < size; ix++) {
             assertEquals("test" + (ix + 1), itty.next());