File tree 1 file changed +43
-0
lines changed
core-java-11/src/test/java/com/baeldung
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments