diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java index 241de3c5db8..311a6b775dd 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/AugmentationTests.java @@ -19,6 +19,8 @@ package org.elasticsearch.painless; +import org.apache.lucene.util.Constants; + import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -27,21 +29,25 @@ import java.util.Map; public class AugmentationTests extends ScriptTestCase { public void testStatic() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("ArrayList l = new ArrayList(); l.add(1); return l.getLength();")); assertEquals(1, exec("ArrayList l = new ArrayList(); l.add(1); return l.length;")); } public void testSubclass() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("List l = new ArrayList(); l.add(1); return l.getLength();")); assertEquals(1, exec("List l = new ArrayList(); l.add(1); return l.length;")); } public void testDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("def l = new ArrayList(); l.add(1); return l.getLength();")); assertEquals(1, exec("def l = new ArrayList(); l.add(1); return l.length;")); } public void testCapturingReference() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("int foo(Supplier t) { return t.get() }" + "ArrayList l = new ArrayList(); l.add(1);" + "return foo(l::getLength);")); @@ -54,16 +60,19 @@ public class AugmentationTests extends ScriptTestCase { } public void testIterable_Any() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(true, exec("List l = new ArrayList(); l.add(1); l.any(x -> x == 1)")); } public void testIterable_AsCollection() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(true, exec("List l = new ArrayList(); return l.asCollection() === l")); } public void testIterable_AsList() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(true, exec("List l = new ArrayList(); return l.asList() === l")); assertEquals(5, @@ -71,41 +80,49 @@ public class AugmentationTests extends ScriptTestCase { } public void testIterable_Each() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("List l = new ArrayList(); l.add(1); List l2 = new ArrayList(); l.each(l2::add); return l2.size()")); } public void testIterable_EachWithIndex() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(0, exec("List l = new ArrayList(); l.add(2); Map m = new HashMap(); l.eachWithIndex(m::put); return m.get(2)")); } public void testIterable_Every() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(false, exec("List l = new ArrayList(); l.add(1); l.add(2); l.every(x -> x == 1)")); } public void testIterable_FindResults() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("List l = new ArrayList(); l.add(1); l.add(2); l.findResults(x -> x == 1 ? x : null).size()")); } public void testIterable_GroupBy() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("List l = new ArrayList(); l.add(1); l.add(-1); l.groupBy(x -> x < 0 ? 'negative' : 'positive').size()")); } public void testIterable_Join() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("test,ing", exec("List l = new ArrayList(); l.add('test'); l.add('ing'); l.join(',')")); } public void testIterable_Sum() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(3.0D, exec("def l = [1,2]; return l.sum()")); assertEquals(5.0D, exec("List l = new ArrayList(); l.add(1); l.add(2); l.sum(x -> x + 1)")); } public void testCollection_Collect() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(Arrays.asList(2, 3), exec("List l = new ArrayList(); l.add(1); l.add(2); l.collect(x -> x + 1)")); assertEquals(asSet(2, 3), @@ -113,16 +130,19 @@ public class AugmentationTests extends ScriptTestCase { } public void testCollection_Find() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("List l = new ArrayList(); l.add(1); l.add(2); return l.find(x -> x == 2)")); } public void testCollection_FindAll() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(Arrays.asList(2), exec("List l = new ArrayList(); l.add(1); l.add(2); return l.findAll(x -> x == 2)")); } public void testCollection_FindResult() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("found", exec("List l = new ArrayList(); l.add(1); l.add(2); return l.findResult(x -> x > 1 ? 'found' : null)")); assertEquals("notfound", @@ -130,11 +150,13 @@ public class AugmentationTests extends ScriptTestCase { } public void testCollection_Split() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(Arrays.asList(Arrays.asList(2), Arrays.asList(1)), exec("List l = new ArrayList(); l.add(1); l.add(2); return l.split(x -> x == 2)")); } public void testMap_Collect() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(Arrays.asList("one1", "two2"), exec("Map m = new TreeMap(); m.one = 1; m.two = 2; m.collect((key,value) -> key + value)")); assertEquals(asSet("one1", "two2"), @@ -142,31 +164,37 @@ public class AugmentationTests extends ScriptTestCase { } public void testMap_Count() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("Map m = new TreeMap(); m.one = 1; m.two = 2; m.count((key,value) -> value == 2)")); } public void testMap_Each() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("Map m = new TreeMap(); m.one = 1; m.two = 2; Map m2 = new TreeMap(); m.each(m2::put); return m2.size()")); } public void testMap_Every() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(false, exec("Map m = new TreeMap(); m.one = 1; m.two = 2; m.every((key,value) -> value == 2)")); } public void testMap_Find() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("two", exec("Map m = new TreeMap(); m.one = 1; m.two = 2; return m.find((key,value) -> value == 2).key")); } public void testMap_FindAll() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(Collections.singletonMap("two", 2), exec("Map m = new TreeMap(); m.one = 1; m.two = 2; return m.findAll((key,value) -> value == 2)")); } public void testMap_FindResult() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("found", exec("Map m = new TreeMap(); m.one = 1; m.two = 2; return m.findResult((key,value) -> value == 2 ? 'found' : null)")); assertEquals("notfound", @@ -175,12 +203,14 @@ public class AugmentationTests extends ScriptTestCase { } public void testMap_FindResults() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(Arrays.asList("negative", "positive"), exec("Map m = new TreeMap(); m.a = -1; m.b = 1; " + "return m.findResults((key,value) -> value < 0 ? 'negative' : 'positive')")); } public void testMap_GroupBy() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); Map> expected = new HashMap<>(); expected.put("negative", Collections.singletonMap("a", -1)); expected.put("positive", Collections.singletonMap("b", 1)); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java index 668040d22b6..5dd2481c0f1 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/FunctionRefTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.painless; +import org.apache.lucene.util.Constants; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -32,32 +33,39 @@ import static org.hamcrest.Matchers.startsWith; public class FunctionRefTests extends ScriptTestCase { public void testStaticMethodReference() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("List l = new ArrayList(); l.add(2); l.add(1); l.sort(Integer::compare); return l.get(0);")); } public void testStaticMethodReferenceDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("def l = new ArrayList(); l.add(2); l.add(1); l.sort(Integer::compare); return l.get(0);")); } public void testVirtualMethodReference() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("List l = new ArrayList(); l.add(1); l.add(1); return l.stream().mapToInt(Integer::intValue).sum();")); } public void testVirtualMethodReferenceDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("def l = new ArrayList(); l.add(1); l.add(1); return l.stream().mapToInt(Integer::intValue).sum();")); } public void testQualifiedStaticMethodReference() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(true, exec("List l = [true]; l.stream().map(org.elasticsearch.painless.FeatureTest::overloadedStatic).findFirst().get()")); } public void testQualifiedStaticMethodReferenceDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(true, exec("def l = [true]; l.stream().map(org.elasticsearch.painless.FeatureTest::overloadedStatic).findFirst().get()")); } public void testQualifiedVirtualMethodReference() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); long instant = randomLong(); assertEquals(instant, exec( "List l = [params.d]; return l.stream().mapToLong(org.joda.time.ReadableDateTime::getMillis).sum()", @@ -65,6 +73,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testQualifiedVirtualMethodReferenceDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); long instant = randomLong(); assertEquals(instant, exec( "def l = [params.d]; return l.stream().mapToLong(org.joda.time.ReadableDateTime::getMillis).sum()", @@ -72,6 +81,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testCtorMethodReference() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(3.0D, exec("List l = new ArrayList(); l.add(1.0); l.add(2.0); " + "DoubleStream doubleStream = l.stream().mapToDouble(Double::doubleValue);" + @@ -82,6 +92,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testCtorMethodReferenceDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(3.0D, exec("def l = new ArrayList(); l.add(1.0); l.add(2.0); " + "def doubleStream = l.stream().mapToDouble(Double::doubleValue);" + @@ -92,6 +103,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testArrayCtorMethodRef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1.0D, exec("List l = new ArrayList(); l.add(1.0); l.add(2.0); " + "def[] array = l.stream().toArray(Double[]::new);" + @@ -99,6 +111,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testArrayCtorMethodRefDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1.0D, exec("def l = new ArrayList(); l.add(1.0); l.add(2.0); " + "def[] array = l.stream().toArray(Double[]::new);" + @@ -106,26 +119,31 @@ public class FunctionRefTests extends ScriptTestCase { } public void testCapturingMethodReference() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("5", exec("Integer x = Integer.valueOf(5); return Optional.empty().orElseGet(x::toString);")); assertEquals("[]", exec("List l = new ArrayList(); return Optional.empty().orElseGet(l::toString);")); } public void testCapturingMethodReferenceDefImpl() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("5", exec("def x = Integer.valueOf(5); return Optional.empty().orElseGet(x::toString);")); assertEquals("[]", exec("def l = new ArrayList(); return Optional.empty().orElseGet(l::toString);")); } public void testCapturingMethodReferenceDefInterface() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("5", exec("Integer x = Integer.valueOf(5); def opt = Optional.empty(); return opt.orElseGet(x::toString);")); assertEquals("[]", exec("List l = new ArrayList(); def opt = Optional.empty(); return opt.orElseGet(l::toString);")); } public void testCapturingMethodReferenceDefEverywhere() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("5", exec("def x = Integer.valueOf(5); def opt = Optional.empty(); return opt.orElseGet(x::toString);")); assertEquals("[]", exec("def l = new ArrayList(); def opt = Optional.empty(); return opt.orElseGet(l::toString);")); } public void testCapturingMethodReferenceMultipleLambdas() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("testingcdefg", exec( "String x = 'testing';" + "String y = 'abcdefg';" + @@ -134,6 +152,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testCapturingMethodReferenceMultipleLambdasDefImpls() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("testingcdefg", exec( "def x = 'testing';" + "def y = 'abcdefg';" + @@ -142,6 +161,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testCapturingMethodReferenceMultipleLambdasDefInterface() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("testingcdefg", exec( "String x = 'testing';" + "String y = 'abcdefg';" + @@ -150,6 +170,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testCapturingMethodReferenceMultipleLambdasDefEverywhere() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("testingcdefg", exec( "def x = 'testing';" + "def y = 'abcdefg';" + @@ -158,26 +179,31 @@ public class FunctionRefTests extends ScriptTestCase { } public void testOwnStaticMethodReference() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("int mycompare(int i, int j) { j - i } " + "List l = new ArrayList(); l.add(2); l.add(1); l.sort(this::mycompare); return l.get(0);")); } public void testOwnStaticMethodReferenceDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("int mycompare(int i, int j) { j - i } " + "def l = new ArrayList(); l.add(2); l.add(1); l.sort(this::mycompare); return l.get(0);")); } public void testInterfaceDefaultMethod() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("bar", exec("String f(BiFunction function) { function.apply('foo', 'bar') }" + "Map map = new HashMap(); f(map::getOrDefault)")); } public void testInterfaceDefaultMethodDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("bar", exec("String f(BiFunction function) { function.apply('foo', 'bar') }" + "def map = new HashMap(); f(map::getOrDefault)")); } public void testMethodMissing() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); Exception e = expectScriptThrows(IllegalArgumentException.class, () -> { exec("List l = [2, 1]; l.sort(Integer::bogus); return l.get(0);"); }); @@ -185,6 +211,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testQualifiedMethodMissing() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); Exception e = expectScriptThrows(IllegalArgumentException.class, () -> { exec("List l = [2, 1]; l.sort(org.joda.time.ReadableDateTime::bogus); return l.get(0);", false); }); @@ -192,6 +219,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testClassMissing() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); Exception e = expectScriptThrows(IllegalArgumentException.class, () -> { exec("List l = [2, 1]; l.sort(Bogus::bogus); return l.get(0);", false); }); @@ -199,6 +227,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testQualifiedClassMissing() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); Exception e = expectScriptThrows(IllegalArgumentException.class, () -> { exec("List l = [2, 1]; l.sort(org.joda.time.BogusDateTime::bogus); return l.get(0);", false); }); @@ -208,6 +237,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testNotFunctionalInterface() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("List l = new ArrayList(); l.add(2); l.add(1); l.add(Integer::bogus); return l.get(0);"); }); @@ -215,12 +245,14 @@ public class FunctionRefTests extends ScriptTestCase { } public void testIncompatible() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); expectScriptThrows(BootstrapMethodError.class, () -> { exec("List l = new ArrayList(); l.add(2); l.add(1); l.sort(String::startsWith); return l.get(0);"); }); } public void testWrongArity() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("Optional.empty().orElseGet(String::startsWith);"); }); @@ -228,6 +260,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testWrongArityNotEnough() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("List l = new ArrayList(); l.add(2); l.add(1); l.sort(String::isEmpty);"); }); @@ -235,6 +268,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testWrongArityDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("def y = Optional.empty(); return y.orElseGet(String::startsWith);"); }); @@ -242,6 +276,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testWrongArityNotEnoughDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("def l = new ArrayList(); l.add(2); l.add(1); l.sort(String::isEmpty);"); }); @@ -249,6 +284,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testReturnVoid() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); Throwable expected = expectScriptThrows(BootstrapMethodError.class, () -> { exec("StringBuilder b = new StringBuilder(); List l = [1, 2]; l.stream().mapToLong(b::setLength);"); }); @@ -257,6 +293,7 @@ public class FunctionRefTests extends ScriptTestCase { } public void testReturnVoidDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); Exception expected = expectScriptThrows(LambdaConversionException.class, () -> { exec("StringBuilder b = new StringBuilder(); def l = [1, 2]; l.stream().mapToLong(b::setLength);"); }); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java index 02ac0ad6a99..bce70a080db 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LambdaTests.java @@ -19,6 +19,8 @@ package org.elasticsearch.painless; +import org.apache.lucene.util.Constants; + import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -28,72 +30,87 @@ import static org.hamcrest.Matchers.containsString; public class LambdaTests extends ScriptTestCase { public void testNoArgLambda() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("Optional.empty().orElseGet(() -> 1);")); } public void testNoArgLambdaDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("def x = Optional.empty(); x.orElseGet(() -> 1);")); } public void testLambdaWithArgs() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("short", exec("List l = new ArrayList(); l.add('looooong'); l.add('short'); " + "l.sort((a, b) -> a.length() - b.length()); return l.get(0)")); } public void testLambdaWithTypedArgs() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("short", exec("List l = new ArrayList(); l.add('looooong'); l.add('short'); " + "l.sort((String a, String b) -> a.length() - b.length()); return l.get(0)")); } public void testPrimitiveLambdas() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(4, exec("List l = new ArrayList(); l.add(1); l.add(1); " + "return l.stream().mapToInt(x -> x + 1).sum();")); } public void testPrimitiveLambdasWithTypedArgs() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(4, exec("List l = new ArrayList(); l.add(1); l.add(1); " + "return l.stream().mapToInt(int x -> x + 1).sum();")); } public void testPrimitiveLambdasDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(4, exec("def l = new ArrayList(); l.add(1); l.add(1); " + "return l.stream().mapToInt(x -> x + 1).sum();")); } public void testPrimitiveLambdasWithTypedArgsDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(4, exec("def l = new ArrayList(); l.add(1); l.add(1); " + "return l.stream().mapToInt(int x -> x + 1).sum();")); } public void testPrimitiveLambdasConvertible() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("List l = new ArrayList(); l.add(1); l.add(1); " + "return l.stream().mapToInt(byte x -> x).sum();")); } public void testPrimitiveArgs() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("int applyOne(IntFunction arg) { arg.apply(1) } applyOne(x -> x + 1)")); } public void testPrimitiveArgsTyped() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("int applyOne(IntFunction arg) { arg.apply(1) } applyOne(int x -> x + 1)")); } public void testPrimitiveArgsTypedOddly() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2L, exec("long applyOne(IntFunction arg) { arg.apply(1) } applyOne(long x -> x + 1)")); } public void testMultipleStatements() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("int applyOne(IntFunction arg) { arg.apply(1) } applyOne(x -> { def y = x + 1; return y })")); } public void testUnneededCurlyStatements() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("int applyOne(IntFunction arg) { arg.apply(1) } applyOne(x -> { x + 1 })")); } /** interface ignores return value */ public void testVoidReturn() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("List list = new ArrayList(); " + "list.add(2); " + "List list2 = new ArrayList(); " @@ -103,6 +120,7 @@ public class LambdaTests extends ScriptTestCase { /** interface ignores return value */ public void testVoidReturnDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("def list = new ArrayList(); " + "list.add(2); " + "List list2 = new ArrayList(); " @@ -111,16 +129,19 @@ public class LambdaTests extends ScriptTestCase { } public void testTwoLambdas() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("testingcdefg", exec( "org.elasticsearch.painless.FeatureTest test = new org.elasticsearch.painless.FeatureTest(2,3);" + "return test.twoFunctionsOfX(x -> 'testing'.concat(x), y -> 'abcdefg'.substring(y))")); } public void testNestedLambdas() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("Optional.empty().orElseGet(() -> Optional.empty().orElseGet(() -> 1));")); } public void testLambdaInLoop() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(100, exec("int sum = 0; " + "for (int i = 0; i < 100; i++) {" + " sum += Optional.empty().orElseGet(() -> 1);" + @@ -129,14 +150,17 @@ public class LambdaTests extends ScriptTestCase { } public void testCapture() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(5, exec("int x = 5; return Optional.empty().orElseGet(() -> x);")); } public void testTwoCaptures() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals("1test", exec("int x = 1; String y = 'test'; return Optional.empty().orElseGet(() -> x + y);")); } public void testCapturesAreReadOnly() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("List l = new ArrayList(); l.add(1); l.add(1); " + "return l.stream().mapToInt(x -> { l = null; return x + 1 }).sum();"); @@ -146,12 +170,14 @@ public class LambdaTests extends ScriptTestCase { @AwaitsFix(bugUrl = "def type tracking") public void testOnlyCapturesAreReadOnly() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(4, exec("List l = new ArrayList(); l.add(1); l.add(1); " + "return l.stream().mapToInt(x -> { x += 1; return x }).sum();")); } /** Lambda parameters shouldn't be able to mask a variable already in scope */ public void testNoParamMasking() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("int x = 0; List l = new ArrayList(); l.add(1); l.add(1); " + "return l.stream().mapToInt(x -> { x += 1; return x }).sum();"); @@ -160,20 +186,24 @@ public class LambdaTests extends ScriptTestCase { } public void testCaptureDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(5, exec("int x = 5; def y = Optional.empty(); y.orElseGet(() -> x);")); } public void testNestedCapture() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(1, exec("boolean x = false; int y = 1;" + "return Optional.empty().orElseGet(() -> x ? 5 : Optional.empty().orElseGet(() -> y));")); } public void testNestedCaptureParams() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(2, exec("int foo(Function f) { return f.apply(1) }" + "return foo(x -> foo(y -> x + 1))")); } public void testWrongArity() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("Optional.empty().orElseGet(x -> x);"); }); @@ -181,6 +211,7 @@ public class LambdaTests extends ScriptTestCase { } public void testWrongArityDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("def y = Optional.empty(); return y.orElseGet(x -> x);"); }); @@ -188,6 +219,7 @@ public class LambdaTests extends ScriptTestCase { } public void testWrongArityNotEnough() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("List l = new ArrayList(); l.add(1); l.add(1); " + "return l.stream().mapToInt(() -> 5).sum();"); @@ -196,6 +228,7 @@ public class LambdaTests extends ScriptTestCase { } public void testWrongArityNotEnoughDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); IllegalArgumentException expected = expectScriptThrows(IllegalArgumentException.class, () -> { exec("def l = new ArrayList(); l.add(1); l.add(1); " + "return l.stream().mapToInt(() -> 5).sum();"); @@ -204,14 +237,17 @@ public class LambdaTests extends ScriptTestCase { } public void testLambdaInFunction() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(5, exec("def foo() { Optional.empty().orElseGet(() -> 5) } return foo();")); } public void testLambdaCaptureFunctionParam() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); assertEquals(5, exec("def foo(int x) { Optional.empty().orElseGet(() -> x) } return foo(5);")); } public void testReservedCapture() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); String compare = "boolean compare(Supplier s, def v) {s.get() == v}"; assertEquals(true, exec(compare + "compare(() -> new ArrayList(), new ArrayList())")); assertEquals(true, exec(compare + "compare(() -> { new ArrayList() }, new ArrayList())")); @@ -236,6 +272,7 @@ public class LambdaTests extends ScriptTestCase { } public void testReturnVoid() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); Throwable expected = expectScriptThrows(ClassCastException.class, () -> { exec("StringBuilder b = new StringBuilder(); List l = [1, 2]; l.stream().mapToLong(i -> b.setLength(i))"); }); @@ -243,6 +280,7 @@ public class LambdaTests extends ScriptTestCase { } public void testReturnVoidDef() { + assumeFalse("JDK is JDK 9", Constants.JRE_IS_MINIMUM_JAVA9); // If we can catch the error at compile time we do Exception expected = expectScriptThrows(ClassCastException.class, () -> { exec("StringBuilder b = new StringBuilder(); def l = [1, 2]; l.stream().mapToLong(i -> b.setLength(i))");