-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathViewTest.java
More file actions
76 lines (55 loc) · 1.76 KB
/
ViewTest.java
File metadata and controls
76 lines (55 loc) · 1.76 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
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class ViewTest {
OutputStream out;
@BeforeEach
void beforeEach() {
out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));
}
@Test
void guessView() {
InputStream in = new ByteArrayInputStream("123\n".getBytes());
View.resetScanner(in);
int num1 = View.guessView();
Assertions.assertThat(num1).isEqualTo(123);
}
@Test
void hintViewNothing() {
ResultDto resultDto = new ResultDto(0, 0);
View.hintView(resultDto);
Assertions.assertThat(out.toString().trim()).isEqualTo("낫싱");
}
@Test
void hintViewStrike() {
ResultDto resultDto = new ResultDto(2, 0);
View.hintView(resultDto);
Assertions.assertThat(out.toString().trim()).isEqualTo("2스트라이크");
}
@Test
void hintViewBall() {
ResultDto resultDto = new ResultDto(0, 3);
View.hintView(resultDto);
Assertions.assertThat(out.toString().trim()).isEqualTo("3볼");
}
@Test
void hintViewBoth() {
ResultDto resultDto = new ResultDto(1, 1);
View.hintView(resultDto);
Assertions.assertThat(out.toString().trim()).isEqualTo("1볼 1스트라이크");
}
@Test
void successView() {
InputStream in = new ByteArrayInputStream("1\n".getBytes());
View.resetScanner(in);
int num1 = View.guessView();
Assertions.assertThat(num1).isEqualTo(1);
}
}