Skip to content

Commit 3f61fa1

Browse files
author
sampada
committed
BAEL-3602 : Java 13 New Features
1 parent 3e119f2 commit 3f61fa1

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

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(result, 16);
25+
}
26+
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
@SuppressWarnings("preview")
10+
private static final String TEXT_BLOCK_JSON = """
11+
{
12+
"name" : "Baeldung",
13+
"website" : "https://www.baeldung.com/"
14+
}
15+
""";
16+
17+
@Test
18+
public void whenTextBlocks_thenStringOperationsWork() {
19+
20+
assertThat(TEXT_BLOCK_JSON.contains("Baeldung")).isTrue();
21+
assertThat(TEXT_BLOCK_JSON.indexOf("www")).isGreaterThan(0);
22+
assertThat(TEXT_BLOCK_JSON.length()).isGreaterThan(0);
23+
24+
}
25+
}

0 commit comments

Comments
 (0)