-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringTest.java
51 lines (40 loc) · 1.36 KB
/
StringTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.github.hubertwo.playground.java11.string;
import org.junit.jupiter.api.Test;
import java.util.stream.Collectors;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
class StringTest {
@Test
void isBlank() {
assertThat(" ".isBlank()).isTrue();
assertThat("".isBlank()).isTrue();
assertThat("""
""".isBlank()).isTrue();
}
@Test
void lines() {
String givenString = """
This is multiline String.
That will be co converted
to Stream of lines and joined by space.
""";
String actualString = givenString.lines()
.collect(Collectors.joining(" "));
assertThat(actualString).isEqualTo("""
This is multiline String. \
That will be co converted to Stream of lines and joined by space.""");
}
@Test
void repeat() {
assertThat("X".repeat(0)).isEqualTo("");
assertThat("X".repeat(1)).isEqualTo("X");
assertThat("X".repeat(2)).isEqualTo("XX");
assertThrows(IllegalArgumentException.class,
() -> "X".repeat(-1)
);
}
@Test
void strip() {
assertThat(" XXX ".strip()).isEqualTo("XXX");
}
}