-
Notifications
You must be signed in to change notification settings - Fork 906
Expand file tree
/
Copy pathStringTest.java
More file actions
86 lines (70 loc) · 2.05 KB
/
StringTest.java
File metadata and controls
86 lines (70 loc) · 2.05 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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;
public class StringTest {
@Test
void replace() {
String actual = "abc".replace("b", "d");
assertThat(actual).isEqualTo("adc");
}
/**
* 학습테스트 - 요구사항 1 : split()
*/
@Test
void split_test1() {
// given
String givenStr = "1,2";
// when
String[] splitResult = givenStr.split(",");
// then
assertThat(splitResult).containsExactly("1", "2");
}
@Test
void split_test2() {
// given
String givenStr = "1";
// when
String[] splitResult = givenStr.split(",");
// then
assertThat(splitResult).containsExactly("1");
}
/**
* 학습테스트 - 요구사항 2 : subString()
*/
@Test
void subString_test() {
// given
String givenStr = "(1,2)";
// when
String result = givenStr.substring(1, 4);
// then
assertThat(result).isEqualTo("1,2");
}
/**
* 학습테스트 - 요구사항 3 : charAt()
*/
@Test
@DisplayName("Stirng클래스의 charAt() 메소드로 특정 위치의 문자를 가져온다.")
void charAt_success_test() {
// given
String givenStr = "abc";
// when
char result = givenStr.charAt(1);
// then
assertThat(result).isEqualTo("b");
}
@Test
@DisplayName("Stirng클래스의 charAt() 메소드로 특정 위치의 문자를 가져오다가, 위치 값을 벗어나면 StringIndexOutOfBoundsException이 발생한다.")
void charAt_fail_test() {
// given
String givenStr = "abc";
// when
// then
assertThatThrownBy(() -> {
givenStr.charAt(5);
}).isInstanceOf(IndexOutOfBoundsException.class)
.hasMessageContaining("String index out of range: 5");
}
}