Skip to content

Commit 01bdad3

Browse files
authored
Merge pull request #8506 from sampada07/BAEL-3602
BAEL-3602 : Java 13 New Features
2 parents 1abef2a + a77f352 commit 01bdad3

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.newfeatures;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
7+
public class SwitchExpressionsWithYieldUnitTest {
8+
9+
@Test
10+
@SuppressWarnings("preview")
11+
public void whenSwitchingOnOperationSquareMe_thenWillReturnSquare() {
12+
var me = 4;
13+
var operation = "squareMe";
14+
var result = switch (operation) {
15+
case "doubleMe" -> {
16+
yield me * 2;
17+
}
18+
case "squareMe" -> {
19+
yield me * me;
20+
}
21+
default -> me;
22+
};
23+
24+
assertEquals(16, result);
25+
}
26+
27+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.baeldung.newfeatures;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.Test;
6+
7+
public class TextBlocksUnitTest {
8+
9+
private static final String JSON_STRING = "{\r\n" + "\"name\" : \"Baeldung\",\r\n" + "\"website\" : \"https://www.%s.com/\"\r\n" + "}";
10+
11+
@SuppressWarnings("preview")
12+
private static final String TEXT_BLOCK_JSON = """
13+
{
14+
"name" : "Baeldung",
15+
"website" : "https://www.%s.com/"
16+
}
17+
""";
18+
19+
@Test
20+
public void whenTextBlocks_thenStringOperationsWork() {
21+
22+
assertThat(TEXT_BLOCK_JSON.contains("Baeldung")).isTrue();
23+
assertThat(TEXT_BLOCK_JSON.indexOf("www")).isGreaterThan(0);
24+
assertThat(TEXT_BLOCK_JSON.length()).isGreaterThan(0);
25+
26+
}
27+
28+
@SuppressWarnings("removal")
29+
@Test
30+
public void whenTextBlocks_thenFormattedWorksAsFormat() {
31+
assertThat(TEXT_BLOCK_JSON.formatted("baeldung")
32+
.contains("www.baeldung.com")).isTrue();
33+
34+
assertThat(String.format(JSON_STRING, "baeldung")
35+
.contains("www.baeldung.com")).isTrue();
36+
37+
}
38+
39+
}

0 commit comments

Comments
 (0)