Merge pull request #8506 from sampada07/BAEL-3602

BAEL-3602 : Java 13 New Features
This commit is contained in:
Eric Martin 2020-01-18 20:17:39 -06:00 committed by GitHub
commit 01bdad3566
2 changed files with 66 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(16, result);
}
}

View File

@ -0,0 +1,39 @@
package com.baeldung.newfeatures;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
public class TextBlocksUnitTest {
private static final String JSON_STRING = "{\r\n" + "\"name\" : \"Baeldung\",\r\n" + "\"website\" : \"https://www.%s.com/\"\r\n" + "}";
@SuppressWarnings("preview")
private static final String TEXT_BLOCK_JSON = """
{
"name" : "Baeldung",
"website" : "https://www.%s.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);
}
@SuppressWarnings("removal")
@Test
public void whenTextBlocks_thenFormattedWorksAsFormat() {
assertThat(TEXT_BLOCK_JSON.formatted("baeldung")
.contains("www.baeldung.com")).isTrue();
assertThat(String.format(JSON_STRING, "baeldung")
.contains("www.baeldung.com")).isTrue();
}
}