1 import org.testng.Assert;
 2 import org.testng.annotations.Test;
 3 
 4 import jdk.incubator.code.Quotable;
 5 import java.util.function.IntUnaryOperator;
 6 import java.util.stream.IntStream;
 7 
 8 /*
 9  * @test
10  * @summary test that invoking Quotable#quoted returns the same instance
11  * @modules jdk.incubator.code
12  * @run testng QuotedSameInstanceTest
13  */
14 
15 public class QuotedSameInstanceTest {
16 
17     private static final Quotable q1 = (Quotable & Runnable) () -> {
18     };
19 
20     @Test
21     void testWithOneThread() {
22         Assert.assertSame(q1.quoted(), q1.quoted());
23     }
24 
25     interface QuotableIntUnaryOperator extends IntUnaryOperator, Quotable { }
26     private static final QuotableIntUnaryOperator q2 = x -> x;
27 
28     @Test
29     void testWithMultiThreads() {
30         Object[] quotedObjects = IntStream.range(0, 1024).parallel().mapToObj(__ -> q2.quoted()).toArray();
31         for (int i = 1; i < quotedObjects.length; i++) {
32             Assert.assertSame(quotedObjects[i], quotedObjects[i - 1]);
33         }
34     }
35 }