9
9
import racingcar .ui .InputView ;
10
10
11
11
import java .io .ByteArrayInputStream ;
12
- import java .util .ArrayList ;
12
+ import java .util .List ;
13
13
import java .util .Scanner ;
14
14
15
15
import static org .assertj .core .api .Assertions .assertThat ;
@@ -30,34 +30,34 @@ void setUp() {
30
30
31
31
@ Test
32
32
@ DisplayName ("์ ์ง ์กฐ๊ฑด์ ๋ง์กฑํ๋ฉด ์ ์ง" )
33
- void move (){
34
- car .move (()-> true );
33
+ void move () {
34
+ car .move (() -> true );
35
35
assertThat (car .getMoveCount ()).isEqualTo (2 );
36
36
}
37
37
38
38
@ Test
39
39
@ DisplayName ("์ ์ง ์กฐ๊ฑด์ ๋ง์กฑํ์ง ์์ผ๋ฉด ๋ฉ์ถค" )
40
- void stop (){
41
- car .move (()-> false );
40
+ void stop () {
41
+ car .move (() -> false );
42
42
assertThat (car .getMoveCount ()).isEqualTo (1 );
43
43
}
44
44
45
45
@ Test
46
46
@ DisplayName ("์ ์ง ์กฐ๊ฑด์ ๋ง์กฑํ๋ฉด ๋ชจ๋ ์ ์ง" )
47
- void moveAll (){
48
- cars .moveAll (()-> true );
47
+ void moveAll () {
48
+ cars .moveAll (() -> true );
49
49
50
50
assertAll (
51
51
() -> assertThat (cars .getCurrentStatus ().get (0 ).getMoveCount ()).isEqualTo (2 ),
52
52
() -> assertThat (cars .getCurrentStatus ().get (1 ).getMoveCount ()).isEqualTo (2 ),
53
53
() -> assertThat (cars .getCurrentStatus ().get (2 ).getMoveCount ()).isEqualTo (2 )
54
- );
54
+ );
55
55
}
56
56
57
57
@ Test
58
58
@ DisplayName ("์ ์ง ์กฐ๊ฑด์ ๋ง์กฑํ์ง ์์ผ๋ฉด ๋ชจ๋ ๋ฉ์ถค" )
59
- void stopAll (){
60
- cars .moveAll (()-> false );
59
+ void stopAll () {
60
+ cars .moveAll (() -> false );
61
61
62
62
assertAll (
63
63
() -> assertThat (cars .getCurrentStatus ().get (0 ).getMoveCount ()).isEqualTo (1 ),
@@ -68,13 +68,13 @@ void stopAll(){
68
68
69
69
@ Test
70
70
@ DisplayName ("random ๊ฐ์ 0๊ณผ 9์ฌ์ด ๊ฐ" )
71
- void random (){
71
+ void random () {
72
72
assertThat (RandomGenerator .generate ()).isBetween (0 , 9 );
73
73
}
74
74
75
75
@ Test
76
76
@ DisplayName ("์๋์ฐจ ๋์๊ฐ 0๋ณด๋ค ์์ ๊ฒฝ์ฐ ์ค๋ฅ ๋ฆฌํด" )
77
- void inputCar (){
77
+ void inputCar () {
78
78
String input = "0" ;
79
79
InputView .setScanner (new Scanner (new ByteArrayInputStream (input .getBytes ())));
80
80
@@ -84,7 +84,7 @@ void inputCar(){
84
84
85
85
@ Test
86
86
@ DisplayName ("์๋ํ ํ์๊ฐ 0๋ณด๋ค ์์ ๊ฒฝ์ฐ ์ค๋ฅ ๋ฆฌํด" )
87
- void inputAttempts (){
87
+ void inputAttempts () {
88
88
String input = "0" ;
89
89
InputView .setScanner (new Scanner (new ByteArrayInputStream (input .getBytes ())));
90
90
@@ -95,9 +95,60 @@ void inputAttempts(){
95
95
@ Test
96
96
@ DisplayName ("๋ฐํ๋ ์๋์ฐจ List์ ํฌ๊ธฐ๋ ์
๋ ฅ๋ ํฌ๊ธฐ์ ๊ฐ๋ค." )
97
97
public void getCars () {
98
- ArrayList <Car > cars = RacingCar .getCars (CAR );
98
+ List <Car > cars = RacingCar .getCars (CAR );
99
99
assertThat (cars .size ()).isEqualTo (CAR );
100
100
}
101
101
102
+ @ Test
103
+ @ DisplayName ("์๋์ฐจ ์ด๋ฆ์ด ๊ณต๋์ผ ๊ฒฝ์ฐ ์ค๋ฅ ๋ฆฌํด" )
104
+ void inputCarName_empty () {
105
+ assertThatThrownBy (() -> new Car ("" ))
106
+ .isInstanceOf (IllegalArgumentException .class );
107
+ }
108
+
109
+ @ Test
110
+ @ DisplayName ("์๋์ฐจ ์ด๋ฆ์ด 5์ ์ด๊ณผํ ๊ฒฝ์ฐ ์ค๋ฅ ๋ฆฌํด" )
111
+ void inputCarName_5์์ด๊ณผ () {
112
+ assertThatThrownBy (() -> new Car ("hyundai" ))
113
+ .isInstanceOf (IllegalArgumentException .class );
114
+ }
115
+
116
+ @ Test
117
+ @ DisplayName ("์๋์ฐจ ์ด๋ฆ์ด ์ค๋ณต๋ ๊ฒฝ์ฐ ์ค๋ฅ ๋ฆฌํด" )
118
+ void inputCarName_์ค๋ณต๋์ด๋ฆ () {
119
+ String [] names = {"pobi" , "pobi" };
120
+ assertThatThrownBy (() -> Cars .fromNames (names ))
121
+ .isInstanceOf (IllegalArgumentException .class );
122
+ }
123
+
124
+ @ Test
125
+ @ DisplayName ("์๋์ฐจ ์ด๋ฆ์ ์ผํ๋ก ๊ตฌ๋ถ" )
126
+ void inputCarName_split () {
127
+ String input = "pobi,crong,honux" ;
128
+ InputView .setScanner (new Scanner (new ByteArrayInputStream (input .getBytes ())));
129
+ assertThat (InputView .inputdNameOfCar ()).containsExactly (input .split ("," ));
130
+
131
+ }
132
+
133
+ @ Test
134
+ @ DisplayName ("๋จ์ผ ์ฐ์น์ ๊ฒฐ์ " )
135
+ void getWinner () {
136
+ Car pobi = new Car ("pobi" );
137
+ Car crong = new Car ("crong" );
138
+ Cars cars = new Cars (List .of (pobi , crong ));
139
+ pobi .move (() -> true );
140
+
141
+ assertThat (cars .getWinners ()).containsExactly ("pobi" );
142
+ }
143
+
144
+ @ Test
145
+ @ DisplayName ("๊ณต๋ ์ฐ์น์ ๊ฒฐ์ " )
146
+ void getWinners () {
147
+ Car pobi = new Car ("pobi" );
148
+ Car crong = new Car ("crong" );
149
+ Cars cars = new Cars (List .of (pobi , crong ));
150
+
151
+ assertThat (cars .getWinners ()).containsExactly ("pobi" , "crong" );
152
+ }
102
153
103
154
}
0 commit comments