File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed
core-java-modules/core-java-13/src/test/java/com/baeldung/newfeatures Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments