File tree Expand file tree Collapse file tree 4 files changed +37
-10
lines changed
src/test/java/io/suhan/lotto/model Expand file tree Collapse file tree 4 files changed +37
-10
lines changed Original file line number Diff line number Diff line change 1313public class NumberPoolTest {
1414 @ Test
1515 void 특정_범위를_가진_Pool을_생성할_수_있다 () {
16- NumberPool pool = NumberPool .of (1 , 10 );
16+ // given
17+ int from = 1 ;
18+ int to = 10 ;
1719
18- assertThat (pool .getNumbers ()).hasSize (10 );
20+ // when
21+ NumberPool pool = NumberPool .of (from , to );
22+
23+ // then
24+ assertThat (pool .getNumbers ()).hasSize (to - from + 1 );
1925 }
2026
2127 @ Test
2228 void from은_to보다_클_수_없다 () {
29+ // given
30+ int from = 2 ;
31+ int to = 1 ;
2332 String expectedMessage = "from 값은 to 값보다 작아야 합니다." ;
2433
25- assertThatThrownBy (() -> NumberPool .of (2 , 1 ))
34+ // when and then
35+ assertThatThrownBy (() -> NumberPool .of (from , to ))
2636 .isInstanceOf (IllegalArgumentException .class )
2737 .hasMessage (expectedMessage );
2838 }
2939
3040 @ Test
3141 void 범위의_크기는_LOTTO_SIZE보다_커야_한다 () {
42+ // given
43+ int from = Lotto .LOTTO_NUMBER_MIN ;
44+ int to = Lotto .LOTTO_NUMBER_MIN + Lotto .LOTTO_SIZE - 2 ;
3245 String expectedMessage = "범위의 크기는 " + Lotto .LOTTO_SIZE + " 보다 커야 합니다." ;
3346
34- assertThatThrownBy (() -> NumberPool .of (Lotto .LOTTO_NUMBER_MIN , Lotto .LOTTO_NUMBER_MIN + Lotto .LOTTO_SIZE - 2 ))
47+ // when and then
48+ assertThatThrownBy (() -> NumberPool .of (from , to ))
3549 .isInstanceOf (IllegalArgumentException .class )
3650 .hasMessage (expectedMessage );
3751 }
Original file line number Diff line number Diff line change @@ -34,15 +34,16 @@ void setUp() {
3434
3535 @ Test
3636 void 당첨번호와_로또를_비교할_수_있다 () {
37+ // given
3738 registry .add (winningLotto );
38-
3939 LottoNumber bonusNumber = new LottoNumber (7 );
40-
4140 DrawExecutor executor = new DrawExecutor (registry , winningLotto , bonusNumber );
42- executor .execute ();
4341
42+ // when
43+ executor .execute ();
4444 List <DrawResult > results = executor .getResults ();
4545
46+ // then
4647 SoftAssertions .assertSoftly ((softly ) -> {
4748 softly .assertThat (results ).hasSize (1 );
4849 softly .assertThat (results .get (0 ).getMatchedCount ()).isEqualTo (Lotto .LOTTO_SIZE );
@@ -51,11 +52,12 @@ void setUp() {
5152
5253 @ Test
5354 void 보너스_번호는_당첨번호와_중복될_수_없다 () {
55+ // given
5456 Lotto lotto = LottoFactory .createLotto (LottoType .AUTOMATIC );
5557 registry .add (lotto );
56-
5758 LottoNumber bonusNumber = new LottoNumber (6 );
5859
60+ // when and then
5961 assertThatThrownBy (() -> {
6062 DrawExecutor executor = new DrawExecutor (registry , winningLotto , bonusNumber );
6163 executor .execute ();
Original file line number Diff line number Diff line change 1313public class PurchaseExecutorTest {
1414 @ Test
1515 void 금액에_맞는_로또를_구매할_수_있다 () {
16+ // given
1617 LottoRegistry registry = new LottoRegistry ();
1718 int count = 5 ;
1819 int balance = PRICE_PER_LOTTO * count ;
1920
2021 PurchaseExecutor executor = new PurchaseExecutor (registry , balance , 0 );
22+
23+ // when
2124 executor .execute ();
2225
26+ // then
2327 assertThat (registry .getLottos ()).hasSize (count );
2428 }
2529}
Original file line number Diff line number Diff line change 1212public class LottoNumberTest {
1313 @ Test
1414 void 유효한_번호를_생성할_수_있다 () {
15- LottoNumber number = new LottoNumber (Lotto .LOTTO_NUMBER_MIN );
15+ // given
16+ int validNumber = Lotto .LOTTO_NUMBER_MIN ;
1617
17- assertThat (Lotto .LOTTO_NUMBER_MIN ).isEqualTo (number .getValue ());
18+ // when
19+ LottoNumber lottoNumber = new LottoNumber (validNumber );
20+
21+ // then
22+ assertThat (lottoNumber .getValue ()).isEqualTo (validNumber );
1823 }
1924
2025 @ Test
2126 void 번호는_범위를_벗어날_수_없다 () {
27+ // given
2228 String expectedMessage = "로또 번호는 " + Lotto .LOTTO_NUMBER_MIN + "~" + Lotto .LOTTO_NUMBER_MAX + " 사이여야 합니다." ;
2329
30+ // when and then
2431 SoftAssertions .assertSoftly ((softly ) -> {
2532 softly .assertThatThrownBy (() -> new LottoNumber (Lotto .LOTTO_NUMBER_MIN - 1 ))
2633 .isInstanceOf (IllegalArgumentException .class )
You can’t perform that action at this time.
0 commit comments