-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathStringTest.java
More file actions
51 lines (44 loc) · 1.36 KB
/
StringTest.java
File metadata and controls
51 lines (44 loc) · 1.36 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
package study;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.*;
public class StringTest {
@Test
@DisplayName("String 치환")
void replace() {
String actual = "abc".replace("b", "d");
assertThat(actual).isEqualTo("adc");
}
@Test
@DisplayName("String \',\'로 split")
void split() {
String[] actual = "1,2".split(",");
assertThat(actual).containsExactly("1", "2");
}
@Test
@DisplayName("String 문자 하나일때 split")
void splitOne() {
String[] actual = "1".split(",");
assertThat(actual).containsExactly("1");
}
@Test
@DisplayName("String 앞뒤 자르기")
void splitBracket() {
String actual = "(1,2)".substring(1, 4);
assertThat(actual).isEqualTo("1,2");
}
@Test
@DisplayName("String 인덱스 접근")
void getChar() {
char actual = "abc".charAt(1);
assertThat(actual).isEqualTo('b');
}
@Test
@DisplayName("String 인덱스 벗어날 때 예외 처리")
void getCharException() {
assertThatExceptionOfType(IndexOutOfBoundsException.class)
.isThrownBy(() -> {
char actual = "abc".charAt(3);
}).withMessageMatching("Index \\d+ out of bounds for length \\d+");
}
}