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/05/21 21:55:23 UTC

[09/11] incubator-tinkerpop git commit: Add tests for FunctionUtils.

Add tests for FunctionUtils.


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

Branch: refs/heads/master
Commit: fe83dc8d1818842b19ae3802d4591eb1959950f3
Parents: 63e3e5a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 21 15:35:54 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu May 21 15:55:04 2015 -0400

----------------------------------------------------------------------
 .../util/function/FunctionUtilsTest.java        | 135 +++++++++++++++++++
 1 file changed, 135 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fe83dc8d/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/function/FunctionUtilsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/function/FunctionUtilsTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/function/FunctionUtilsTest.java
new file mode 100644
index 0000000..4a8778d
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/function/FunctionUtilsTest.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.util.function;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class FunctionUtilsTest {
+    @Test
+    public void shouldWrapInRuntimeIfFunctionThrows() {
+        final Exception t = new Exception();
+        try {
+            FunctionUtils.wrapFunction(FunctionUtilsTest::throwIt).apply(t);
+        } catch (Exception ex) {
+            assertThat(ex, instanceOf(RuntimeException.class));
+            assertSame(t, ex.getCause());
+        }
+    }
+
+    @Test
+    public void shouldNoReWrapInRuntimeIfFunctionThrows() {
+        final Exception t = new RuntimeException();
+        try {
+            FunctionUtils.wrapFunction(FunctionUtilsTest::throwIt).apply(t);
+        } catch (Exception ex) {
+            assertThat(ex, instanceOf(RuntimeException.class));
+            assertNull(ex.getCause());
+        }
+    }
+
+    @Test
+    public void shouldWrapInRuntimeIfConsumerThrows() {
+        final Exception t = new Exception();
+        try {
+            FunctionUtils.wrapConsumer((Exception a) -> {
+                throw a;
+            }).accept(t);
+        } catch (Exception ex) {
+            assertThat(ex, instanceOf(RuntimeException.class));
+            assertSame(t, ex.getCause());
+        }
+    }
+
+    @Test
+    public void shouldNoReWrapInRuntimeIfConsumerThrows() {
+        final Exception t = new RuntimeException();
+        try {
+            FunctionUtils.wrapConsumer((Exception a) -> {
+                throw a;
+            }).accept(t);
+        } catch (Exception ex) {
+            assertThat(ex, instanceOf(RuntimeException.class));
+            assertNull(ex.getCause());
+        }
+    }
+
+    @Test
+    public void shouldWrapInRuntimeIfBiConsumerThrows() {
+        final Exception t = new Exception();
+        try {
+            FunctionUtils.wrapBiConsumer((Exception a, String x) -> {
+                throw a;
+            }).accept(t, "test");
+        } catch (Exception ex) {
+            assertThat(ex, instanceOf(RuntimeException.class));
+            assertSame(t, ex.getCause());
+        }
+    }
+
+    @Test
+    public void shouldNoReWrapInRuntimeIfBiConsumerThrows() {
+        final Exception t = new RuntimeException();
+        try {
+            FunctionUtils.wrapBiConsumer((Exception a, String x) -> {
+                throw a;
+            }).accept(t, "test");
+        } catch (Exception ex) {
+            assertThat(ex, instanceOf(RuntimeException.class));
+            assertNull(ex.getCause());
+        }
+    }
+
+    @Test
+    public void shouldWrapInRuntimeIfSupplierThrows() {
+        final Exception t = new Exception();
+        try {
+            FunctionUtils.wrapSupplier(() -> {
+                throw t;
+            }).get();
+        } catch (Exception ex) {
+            assertThat(ex, instanceOf(RuntimeException.class));
+            assertSame(t, ex.getCause());
+        }
+    }
+
+    @Test
+    public void shouldNoReWrapInRuntimeIfSupplierThrows() {
+        final Exception t = new RuntimeException();
+        try {
+            FunctionUtils.wrapSupplier(() -> {
+                throw t;
+            }).get();
+        } catch (Exception ex) {
+            assertThat(ex, instanceOf(RuntimeException.class));
+            assertNull(ex.getCause());
+        }
+    }
+
+    static int throwIt(final Exception t) throws Exception {
+        throw t;
+    }
+}