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  * @modules jdk.incubator.code
15  * @run main TestJavaVersionCheckerForLambdas
16  * @run junit/othervm TestJavaVersionCheckerForLambdas
17  */
18 public class TestJavaVersionCheckerForLambdas {
19 
20     public static void main(String[] args) throws IOException { // transform $CM classfile
21         String testClassName = TestJavaVersionCheckerForLambdas.class.getName();
22         Path testClassesDir = Path.of(System.getProperty("test.classes"));
23         Path innerClassPath = testClassesDir.resolve(testClassName + "$$CM.class");
24         byte[] newInnerBytes = TestJavaVersionCheckerForMethods.changeCompileTimeVersion(innerClassPath, Runtime.version().feature() - 1);
25         Files.write(innerClassPath, newInnerBytes);
26     }
27 
28     @Test
29     void test() throws ReflectiveOperationException, IOException {
30         IntBinaryOperator l = (@Reflect IntBinaryOperator) (a, b) -> Math.max(a, b);
31         Assertions.assertThrows(UnsupportedOperationException.class, () -> Op.ofLambda(l));
32     }
33 }