File tree Expand file tree Collapse file tree
core-java-modules/core-java-13/src/test/java/com/baeldung/newfeatures Expand file tree Collapse file tree 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 (result , 16 );
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+ @ 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+ }
You can’t perform that action at this time.
0 commit comments