1+ package pl .mperor .lab .java ;
2+
3+ import org .junit .jupiter .api .Assertions ;
4+ import org .junit .jupiter .api .Test ;
5+ import pl .mperor .lab .TestUtils ;
6+ import pl .mperor .lab .TestUtils .ReadableOut ;
7+
8+ /**
9+ * Java 19 (September 2022)
10+ */
11+ public class Java19 {
12+
13+ @ Test
14+ public void testRecordPatternDeconstruct () {
15+ record Point (int x , int y ) {}
16+ record LineSegment (Point start , Point end ) {}
17+ Object obj = new LineSegment (new Point (0 ,1 ), new Point (1 , 2 ));
18+
19+ if (obj instanceof LineSegment (Point (int x , int y ), Point end )) {
20+ Assertions .assertEquals (0 , x );
21+ Assertions .assertEquals (1 , y );
22+ Assertions .assertEquals (new Point (1 ,2 ), end );
23+ }
24+ }
25+
26+ @ Test
27+ public void testVirtualThreads () throws InterruptedException {
28+ ReadableOut out = TestUtils .setTempSystemOut ();
29+ Thread virtualThread = Thread .startVirtualThread (() ->
30+ System .out .print ("Hello from Virtual Thread!" )
31+ );
32+ virtualThread .join ();
33+ TestUtils .resetSystemOut ();
34+
35+ Assertions .assertTrue (virtualThread .isDaemon () && virtualThread .isVirtual ());
36+ Assertions .assertEquals (Thread .NORM_PRIORITY , virtualThread .getPriority ());
37+ Assertions .assertEquals ("Hello from Virtual Thread!" , out .all ());
38+ }
39+
40+ }
0 commit comments