1 import jdk.incubator.code.Op;
2 import jdk.incubator.code.Reflect;
3 import org.junit.jupiter.api.Assertions;
4 import org.junit.jupiter.api.Test;
5
6 import java.io.IOException;
7 import java.nio.file.Files;
8 import java.nio.file.Path;
9 import java.util.function.IntBinaryOperator;
10
11 /*
12 * @test
13 * @summary Test that java version check we do in op building methods is working
14 * @run main TestJavaVersionCheckerForLambdas
15 * @run junit/othervm TestJavaVersionCheckerForLambdas
16 */
17 public class TestJavaVersionCheckerForLambdas {
18
19 public static void main(String[] args) throws IOException { // transform $CM classfile
20 String testClassName = TestJavaVersionCheckerForLambdas.class.getName();
21 Path testClassesDir = Path.of(System.getProperty("test.classes"));
22 Path innerClassPath = testClassesDir.resolve(testClassName + "$$CM.class");
23 byte[] newInnerBytes = TestJavaVersionCheckerForMethods.changeCompileTimeVersion(innerClassPath, Runtime.version().feature() - 1);
24 Files.write(innerClassPath, newInnerBytes);
25 }
26
27 @Test
28 void test() throws ReflectiveOperationException, IOException {
29 IntBinaryOperator l = (@Reflect IntBinaryOperator) (a, b) -> Math.max(a, b);
30 Assertions.assertThrows(UnsupportedOperationException.class, () -> Op.ofQuotable(l));
31 }
32 }