-
Notifications
You must be signed in to change notification settings - Fork 906
Expand file tree
/
Copy pathStringTest.java
More file actions
52 lines (41 loc) · 1.2 KB
/
StringTest.java
File metadata and controls
52 lines (41 loc) · 1.2 KB
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
52
package study;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class StringTest {
@Test
void replace() {
String actual = "abc".replace("b", "d");
assertThat(actual).isEqualTo("adc");
}
@Test
void split(){
String[] actual = "1,2".split(",");
assertThat(actual).contains("1","2");
}
@Test
void spilt2(){
String[] actual = "1".split(",");
assertThat(actual).containsExactly("1");
}
@Test
void subString(){
String actual = "(1,2)".substring(1,4);
assertThat(actual).isEqualTo("1,2");
}
@Test
void charAt(){
char actual = "abc".charAt(1);
assertThat(actual).isEqualTo('b');
}
@Test
@DisplayName("charAtExceptionText")
void chatAtException(){
assertThatThrownBy(() -> {
char c = "abc".charAt(4);
}).isInstanceOf(StringIndexOutOfBoundsException.class)
.hasMessageContaining("String index out of range: 4");
}
}