Skip to content

Commit 2bec145

Browse files
authored
Merge pull request eugenp#5934 from rockoder/java11-string
Java 11 String APIs
2 parents 9297099 + 12e2e09 commit 2bec145

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.baeldung;
2+
3+
import static org.hamcrest.CoreMatchers.is;
4+
5+
import static org.junit.Assert.assertTrue;
6+
7+
import org.junit.Test;
8+
9+
public class NewStringAPIUnitTest {
10+
11+
@Test
12+
public void whenRepeatStringTwice_thenGetStringTwice() {
13+
String output = "La ".repeat(2) + "Land";
14+
15+
is(output).equals("La La Land");
16+
}
17+
18+
@Test
19+
public void whenStripString_thenReturnStringWithoutWhitespaces() {
20+
is("\n\t hello \u2005".strip()).equals("hello");
21+
}
22+
23+
@Test
24+
public void whenTrimAdvanceString_thenReturnStringWithWhitespaces() {
25+
is("\n\t hello \u2005".trim()).equals("hello \u2005");
26+
}
27+
28+
@Test
29+
public void whenBlankString_thenReturnTrue() {
30+
assertTrue("\n\t\u2005 ".isBlank());
31+
}
32+
33+
@Test
34+
public void whenMultilineString_thenReturnNonEmptyLineCount() {
35+
String multilineStr = "This is\n \n a multiline\n string.";
36+
37+
long lineCount = multilineStr.lines()
38+
.filter(String::isBlank)
39+
.count();
40+
41+
is(lineCount).equals(3L);
42+
}
43+
}

0 commit comments

Comments
 (0)