Skip to content

Commit 02d8d56

Browse files
committed
Update test class for Java 12 & 13 ...
- samples only for standard features - markdown javadoc for JEPs - organize classes related to Java 12 & 13 - improve code readability
1 parent 1c527a8 commit 02d8d56

File tree

6 files changed

+71
-27
lines changed

6 files changed

+71
-27
lines changed

src/test/java/pl/mperor/lab/java/Java11.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,6 @@ public void testTransferTo() throws Exception {
7070
}
7171
}
7272

73-
@Test
74-
public void testTeeingCollector() {
75-
List<String> words = List.of("one", "two", "three");
76-
77-
SimpleEntry<Integer, Long> pair = words.stream().collect(Collectors.teeing(
78-
Collectors.summingInt(String::length),
79-
Collectors.counting(),
80-
SimpleEntry::new)
81-
);
82-
83-
Assertions.assertEquals(11, pair.getKey());
84-
Assertions.assertEquals(3, pair.getValue());
85-
}
86-
8773
@Test
8874
public void testCollectionToArray() {
8975
Assertions.assertArrayEquals(new String[]{"x", "y", "z"}, List.of("x", "y", "z").toArray(String[]::new));

src/test/java/pl/mperor/lab/java/Java12.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,26 @@
99
import java.security.MessageDigest;
1010
import java.security.NoSuchAlgorithmException;
1111
import java.text.NumberFormat;
12+
import java.util.AbstractMap;
13+
import java.util.List;
1214
import java.util.Locale;
15+
import java.util.concurrent.CompletableFuture;
16+
import java.util.stream.Collectors;
1317

14-
/**
15-
* Java 12 (March 2019)
16-
*/
18+
/// Java 12™ (March 2019)
19+
/// [JDK 12](https://openjdk.org/projects/jdk/12)
20+
///
21+
/// - STANDARD FEATURES:
22+
/// - 230: Microbenchmark Suite
23+
/// - 334: JVM Constants API
24+
/// - 340: One AArch64 Port, Not Two
25+
/// - 341: Default CDS Archives (`-Xshare:dump`)
26+
/// - 344: Abortable Mixed Collections for G1
27+
/// - 346: Promptly Return Unused Committed Memory from G1 (`-XX:SoftMaxHeapSize`)
28+
///
29+
/// - PREVIEW & INCUBATOR:
30+
/// - 189: Shenandoah: A Low-Pause-Time Garbage Collector "Experimental" (`-XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC`)
31+
/// - 325: Switch Expressions (Preview)
1732
public class Java12 {
1833

1934
@Test
@@ -60,4 +75,29 @@ public void testCompactNumberFormat() {
6075
Assertions.assertEquals("1.02M", shortNumberFormat.format(1_020_000));
6176
}
6277

78+
@Test
79+
public void testTeeingCollector() {
80+
List<String> words = List.of("one", "two", "three");
81+
82+
AbstractMap.SimpleEntry<Integer, Long> pair = words.stream().collect(Collectors.teeing(
83+
Collectors.summingInt(String::length),
84+
Collectors.counting(),
85+
AbstractMap.SimpleEntry::new)
86+
);
87+
88+
Assertions.assertEquals(11, pair.getKey());
89+
Assertions.assertEquals(3, pair.getValue());
90+
}
91+
92+
@Test
93+
public void testCompletableExceptionallyCompose() {
94+
var errorThrowingPlanA = CompletableFuture.supplyAsync(() -> 1 / 0);
95+
var noErrorPlanB = CompletableFuture.supplyAsync(() -> 0);
96+
97+
errorThrowingPlanA.exceptionallyComposeAsync(ex -> {
98+
Assertions.assertInstanceOf(ArithmeticException.class, ex);
99+
return noErrorPlanB;
100+
}).thenAccept(result -> Assertions.assertEquals(0, result));
101+
}
102+
63103
}

src/test/java/pl/mperor/lab/java/Java13.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,27 @@
33
import org.junit.jupiter.api.Assertions;
44
import org.junit.jupiter.api.Test;
55

6-
import java.util.Locale;
6+
import java.io.IOException;
7+
import java.net.ServerSocket;
78

8-
/**
9-
* Java 13 (September 2019)
10-
*/
9+
/// Java 13™ (September 2019)
10+
/// [JDK 13](https://openjdk.org/projects/jdk/13)
11+
///
12+
/// - STANDARD FEATURES:
13+
/// - 353: Reimplement the Legacy Socket API (`-Djdk.net.usePlainSocketImpl`)
14+
/// - 350: Dynamic CDS (Class-Data Sharing) Archives (`-XX:ArchiveClassesAtExit=hello.jsa`)
15+
/// - 351: ZGC: Uncommit Unused Memory (`-XX:+UseZGC`)
16+
///
17+
/// - PREVIEW & INCUBATOR:
18+
/// - 354: Switch Expressions (Preview)
19+
/// - 355: Text Blocks (Preview)
1120
public class Java13 {
21+
22+
@Test
23+
public void testServerSocketImpl() throws IOException {
24+
try (ServerSocket serverSocket = new ServerSocket(8013)) {
25+
Assertions.assertNotNull(serverSocket);
26+
}
27+
}
28+
1229
}

src/test/java/pl/mperor/lab/java/Java15.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ public void testNashornEngineRemoved() {
103103
}
104104

105105
@Test
106-
public void testDatagramSocket() throws SocketException {
107-
DatagramSocket datagramSocket = new DatagramSocket();
108-
Assertions.assertNotNull(datagramSocket);
106+
public void testDatagramSocketImpl() throws SocketException {
107+
try (DatagramSocket datagramSocket = new DatagramSocket(8015)) {
108+
Assertions.assertNotNull(datagramSocket);
109+
}
109110
}
110111

111112
}

src/test/java/pl/mperor/lab/java/Java18.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testDefaultCharsetIsUTF8() throws IOException {
5252

5353
@Test
5454
public void testSimpleWebServer() throws IOException, InterruptedException {
55-
HttpServer server = HttpServer.create(new InetSocketAddress(9000), 0);
55+
HttpServer server = HttpServer.create(new InetSocketAddress(8018), 0);
5656
server.createContext("/hello", exchange -> {
5757
String response = "Hello World!";
5858
exchange.sendResponseHeaders(200, response.getBytes().length);
@@ -62,7 +62,7 @@ public void testSimpleWebServer() throws IOException, InterruptedException {
6262
});
6363
server.start();
6464
Assertions.assertNotNull(server);
65-
Assertions.assertEquals("Hello World!", curlResponse("http://127.0.0.1:9000/hello"));
65+
Assertions.assertEquals("Hello World!", curlResponse("http://127.0.0.1:8018/hello"));
6666

6767
server.stop(0);
6868
}

src/test/java/pl/mperor/lab/java/Java4.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void testImageIO() throws IOException {
9292
}
9393
@Test
9494
public void testServerClientSocketChannel() throws IOException, InterruptedException {
95-
int port = 8888;
95+
int port = 8004;
9696
CountDownLatch serverReadyLatch = new CountDownLatch(1);
9797

9898
var executorService = Executors.newSingleThreadExecutor();

0 commit comments

Comments
 (0)