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:19 UTC

[05/11] incubator-tinkerpop git commit: Add tests for ScriptEngineLambdaSupplier.

Add tests for ScriptEngineLambdaSupplier.


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

Branch: refs/heads/master
Commit: 63e3e5a34a5a421402e3a03aedc49694298e257b
Parents: e88ce99
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu May 21 15:17:50 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu May 21 15:55:04 2015 -0400

----------------------------------------------------------------------
 .../util/function/ScriptEngineLambdaTest.java   | 93 ++++++++++++++++++++
 1 file changed, 93 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/63e3e5a3/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/function/ScriptEngineLambdaTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/function/ScriptEngineLambdaTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/function/ScriptEngineLambdaTest.java
new file mode 100644
index 0000000..5e70c6a
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/function/ScriptEngineLambdaTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class ScriptEngineLambdaTest {
+
+    @Test
+    public void shouldCallAsFunction() {
+        final ScriptEngineLambda lambda = new ScriptEngineLambda("nashorn", "1+a");
+        assertEquals(11.0, lambda.apply(10));
+    }
+
+    @Test
+    public void shouldCallAsSupplier() {
+        final ScriptEngineLambda lambda = new ScriptEngineLambda("nashorn", "11");
+        assertEquals(11, lambda.get());
+    }
+
+    @Test
+    public void shouldCallAsPredicate() {
+        final ScriptEngineLambda lambda = new ScriptEngineLambda("nashorn", "a > 10");
+        assertThat(lambda.test(100), is(true));
+    }
+
+    @Test
+    public void shouldCallAsConsumer() {
+        final ScriptEngineLambda lambda = new ScriptEngineLambda("nashorn", "a.setData('test')");
+        final Junk junk = new Junk();
+        lambda.accept(junk);
+        assertEquals("test", junk.getData());
+    }
+
+    @Test
+    public void shouldCallAsBiConsumer() {
+        final ScriptEngineLambda lambda = new ScriptEngineLambda("nashorn", "a.setData('testa');b.setData('testb')");
+        final Junk junkA = new Junk();
+        final Junk junkB = new Junk();
+        lambda.accept(junkA, junkB);
+
+        assertEquals("testa", junkA.getData());
+        assertEquals("testb", junkB.getData());
+    }
+
+    @Test
+    public void shouldCallAsTriConsumer() {
+        final ScriptEngineLambda lambda = new ScriptEngineLambda("nashorn", "a.setData('testa');b.setData('testb');c.setData('testc')");
+        final Junk junkA = new Junk();
+        final Junk junkB = new Junk();
+        final Junk junkC = new Junk();
+        lambda.accept(junkA, junkB, junkC);
+
+        assertEquals("testa", junkA.getData());
+        assertEquals("testb", junkB.getData());
+        assertEquals("testc", junkC.getData());
+    }
+
+    public static class Junk {
+        private String data = "";
+
+        public String getData() {
+            return data;
+        }
+
+        public void setData(final String x) {
+            data = x;
+        }
+    }
+}