Added test for formatted()
@@ -6,11 +6,13 @@ 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.baeldung.com/"
+ "website" : "https://www.%s.com/"
}
""";
@@ -22,4 +24,16 @@ public class TextBlocksUnitTest {
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();
+
+ }
+
}
