-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐ง Modify : ํ์ผ/ํด๋ ์์ /์ญ์ /์์น ๋ณ๊ฒฝ
๐ค Refactor : ์ฝ๋ ๋ฆฌํฉํ ๋ง โ Test : ํ ์คํธ ์ฝ๋ ์ถ๊ฐ 1. ํตํฉ ํ ์คํธ๋ฅผ ์ํด์ ๋์๋ฅผ ๋ฐ์์ํค๋ Random ๊ฐ์ฒด๋ฅผ mockํ ํ์๊ฐ ์๋ค. 2. MoneyToPurchaseLotto ๋ด๋ถ์์ Random์ ์์ฑํ๋ฉด mock ๊ฐ์ฒด๋ฅผ ์ฃผ์ ํ ์ ์๋ค. 3. args์ฒ๋ผ randome ๊ฐ์ฒด๋ฅผ ์ธ๋ถ์์ ์ฃผ์ ํ๊ธฐ ์ํด ํ๋ก๊ทธ๋จ์ Game์ผ๋ก ํ๋ฒ ๋ ๊ฐ์๋ค. 4. testํ ๋ mock random ๊ฐ์ฒด๋ฅผ Game์ ์ฃผ์ ํด์ ํตํฉํ ์คํธ๋ฅผ ์งํํ ์ ์๋ค.
- Loading branch information
Showing
7 changed files
with
1,611 additions
and
84 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,6 @@ private void printInputHeader() { | |
} | ||
|
||
public void close() { | ||
scanner.close(); | ||
// scanner.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,10 @@ | ||
package lotto; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.util.Scanner; | ||
|
||
import lotto.controller.MoneyConsoleInput; | ||
import lotto.controller.MoneyToPurchaseLotto; | ||
import lotto.controller.PurchaseLottoToPrize; | ||
import lotto.controller.WinningBonusConsoleInput; | ||
import lotto.controller.WinningLottoConsoleInput; | ||
import lotto.model.bonus.BonusOutputDto; | ||
import lotto.model.bonus.IBonusOutput; | ||
import lotto.model.lotto.winning.IWinningLottoOutput; | ||
import lotto.model.money.IMoneyInput; | ||
import java.util.Random; | ||
|
||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
if (args.length < 3) { | ||
args = new String[]{"8000", "1,2,3,4,5,6", "7"}; // ์ฌ์ฉ์ ์ ๋ ฅ์ ๊ฐ์ ํ๋ ๊ฑธ๋ก ์์ | ||
} | ||
ByteArrayInputStream actual = new ByteArrayInputStream( | ||
String.join(System.lineSeparator(), args).getBytes()); | ||
System.setIn(actual); | ||
Scanner scanner = new Scanner(System.in); | ||
// ๊ตฌ์ ๊ธ์ก ์ ๋ ฅ | ||
IMoneyInput money; | ||
try (var console = MoneyConsoleInput.of(scanner)) { | ||
money = console.getInput(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
// ๋ก๋ ๊ตฌ๋งค | ||
var purchasedLotto = MoneyToPurchaseLotto.of().tryConvert(money); | ||
|
||
// ๋น์ฒจ ๋ก๋ ๋ฒํธ ์ ๋ ฅ | ||
IWinningLottoOutput winningLotto; | ||
try (var console = WinningLottoConsoleInput.of(scanner)) { | ||
winningLotto = IWinningLottoOutput.of(console.getInput()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
// ๋ณด๋์ค ๋ฒํธ ์ ๋ ฅ | ||
IBonusOutput bonusNumber; | ||
try (var console = WinningBonusConsoleInput.of(winningLotto, scanner)) { | ||
bonusNumber = BonusOutputDto.of(console.getInput()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
// ๋น์ฒจ ํต๊ณ ์ถ๋ ฅ | ||
PurchaseLottoToPrize.of(winningLotto, bonusNumber).tryConvert(purchasedLotto); | ||
Game game = new Game(args, new Random()); | ||
game.runGame(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package lotto; | ||
|
||
import lotto.controller.*; | ||
import lotto.model.bonus.BonusOutputDto; | ||
import lotto.model.bonus.IBonusOutput; | ||
import lotto.model.lotto.winning.IWinningLottoOutput; | ||
import lotto.model.money.IMoneyInput; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.util.Random; | ||
import java.util.Scanner; | ||
|
||
public class Game { | ||
private final String[] args; | ||
private final Random random; | ||
public Game(String[] args, Random random) { | ||
this.args = args; | ||
this.random = random; | ||
} | ||
|
||
public void runGame(){ | ||
|
||
if (args.length >= 3) { | ||
ByteArrayInputStream actual = new ByteArrayInputStream( | ||
String.join(System.lineSeparator(), args).getBytes()); | ||
System.setIn(actual); | ||
} | ||
|
||
Scanner scanner = new Scanner(System.in); | ||
// ๊ตฌ์ ๊ธ์ก ์ ๋ ฅ | ||
IMoneyInput money; | ||
try (var console = MoneyConsoleInput.of(scanner)) { | ||
money = console.getInput(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
// ๋ก๋ ๊ตฌ๋งค | ||
var purchasedLotto = MoneyToPurchaseLotto.of(random).tryConvert(money); | ||
|
||
// ๋น์ฒจ ๋ก๋ ๋ฒํธ ์ ๋ ฅ | ||
IWinningLottoOutput winningLotto; | ||
try (var console = WinningLottoConsoleInput.of(scanner)) { | ||
winningLotto = IWinningLottoOutput.of(console.getInput()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
// ๋ณด๋์ค ๋ฒํธ ์ ๋ ฅ | ||
IBonusOutput bonusNumber; | ||
try (var console = WinningBonusConsoleInput.of(winningLotto, scanner)) { | ||
bonusNumber = BonusOutputDto.of(console.getInput()); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
// ๋น์ฒจ ํต๊ณ ์ถ๋ ฅ | ||
PurchaseLottoToPrize.of(winningLotto, bonusNumber).tryConvert(purchasedLotto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters