Skip to content

Commit b939a70

Browse files
authored
Add Java 19 test class ... (#19)
- Virtual Threads - Pattern Matching for Switch
1 parent 343b774 commit b939a70

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ This project includes unit tests for key functionalities introduced in each Java
3030
- [Java 16](src/test/java/pl/mperor/lab/java/Java16.java)
3131
- [Java 17](src/test/java/pl/mperor/lab/java/Java17.java)
3232
- [Java 18](src/test/java/pl/mperor/lab/java/Java18.java)
33+
- [Java 19](src/test/java/pl/mperor/lab/java/Java19.java)
3334

3435
For detailed examples and tests of each feature, please refer to the individual source files linked above.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)