-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathApplicationTest.java
More file actions
85 lines (66 loc) · 2.29 KB
/
ApplicationTest.java
File metadata and controls
85 lines (66 loc) · 2.29 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
package racingcar;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class ApplicationTest {
void clearInputStream() {
System.setIn(new ByteArrayInputStream(new byte[0])); // 빈 스트림으로 설정
}
@Test
void 올바른_이름_입력() {
// given
String input = "car1,car2,car3\n"; // Console 입력을 위해 줄바꿈 추가
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
// when
String result = Application.getName();
// then
assertThat(result).isEqualTo(input.trim());
}
@Test
void 올바르지_않은_이름_입력() {
// given
String input = ""; // 빈 문자열 입력
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
// when & then
assertThatThrownBy(Application::getName)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("이름이 공백이거나, 구분자가 없거나, 구분자로만 입력되어 있습니다.");
}
@Test
void 올바른_숫자_입력() {
// given
String input = "5\n";
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
// when
String result = Application.getNum();
// then
assertThat(result).isEqualTo("5");
}
@Test
void 올바르지_않은_숫자_입력() {
// given
String input = "0\n"; // 0 입력
InputStream in = new ByteArrayInputStream(input.getBytes());
System.setIn(in);
// when & then
assertThatThrownBy(Application::getNum)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("음수 혹은 0은 입력할 수 없습니다.");
}
@Test
void result_allCarsTied_printsTiedMessage() {
// given
String[] nameList = {"car1", "car2", "car3"};
int num = 3;
// when
Application.result(nameList, num);
//then 결과출력
}
}