BAEL-3602 : Java 13 New Features

This commit is contained in:
sampada 2020-01-10 17:43:48 +05:30
parent d17e102e39
commit 5d50eb7709
2 changed files with 52 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}