BAEL-3602 : Java 13 New Features
This commit is contained in:
parent
d17e102e39
commit
5d50eb7709
|
@ -0,0 +1,27 @@
|
|||
package com.baeldung.newfeatures;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SwitchExpressionsWithYieldUnitTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("preview")
|
||||
public void whenSwitchingOnOperationSquareMe_thenWillReturnSquare() {
|
||||
var me = 4;
|
||||
var operation = "squareMe";
|
||||
var result = switch (operation) {
|
||||
case "doubleMe" -> {
|
||||
yield me * 2;
|
||||
}
|
||||
case "squareMe" -> {
|
||||
yield me * me;
|
||||
}
|
||||
default -> me;
|
||||
};
|
||||
|
||||
assertEquals(result, 16);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.baeldung.newfeatures;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TextBlocksUnitTest {
|
||||
|
||||
@SuppressWarnings("preview")
|
||||
private static final String TEXT_BLOCK_JSON = """
|
||||
{
|
||||
"name" : "Baeldung",
|
||||
"website" : "https://www.baeldung.com/"
|
||||
}
|
||||
""";
|
||||
|
||||
@Test
|
||||
public void whenTextBlocks_thenStringOperationsWork() {
|
||||
|
||||
assertThat(TEXT_BLOCK_JSON.contains("Baeldung")).isTrue();
|
||||
assertThat(TEXT_BLOCK_JSON.indexOf("www")).isGreaterThan(0);
|
||||
assertThat(TEXT_BLOCK_JSON.length()).isGreaterThan(0);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue