Browse Source
Added Cli class for centralized I/O management and getPrintStream() method with test.
Added Cli class for centralized I/O management and getPrintStream() method with test.
Updated other classes for Cli class integration.feature-cli
Nick Stolbov
3 years ago
12 changed files with 89 additions and 73 deletions
-
16src/main/java/Application/Cli.java
-
10src/main/java/Application/Menu.java
-
4src/main/java/Application/MenuManager.java
-
6src/main/java/Game/Game.java
-
38src/main/java/Game/TicTacToe/Board.java
-
9src/main/java/Main.java
-
35src/test/java/Application/CliTest.java
-
2src/test/java/Application/MenuManagerTest.java
-
4src/test/java/Application/MenuTest.java
-
29src/test/java/Game/GameTest.java
-
2src/test/java/Game/TicTacToe/BoardTest.java
-
7src/test/java/Game/TictactoeTest.java
@ -0,0 +1,16 @@ |
|||
package Application; |
|||
|
|||
import java.io.PrintStream; |
|||
|
|||
public class Cli { |
|||
|
|||
private PrintStream printStream; |
|||
|
|||
public Cli(PrintStream printStream) { |
|||
this.printStream = printStream; |
|||
} |
|||
|
|||
public PrintStream getPrintStream() { |
|||
return this.printStream; |
|||
} |
|||
} |
@ -1,17 +1,18 @@ |
|||
import Application.Cli; |
|||
import Game.Tictactoe; |
|||
|
|||
import java.util.Scanner; |
|||
|
|||
public class Main { |
|||
|
|||
public static void main(String[] args){ |
|||
System.out.println("Hello world!"); |
|||
public static void main(String[] args) { |
|||
Tictactoe ttt = new Tictactoe(); |
|||
Cli cli = new Cli(System.out); |
|||
Scanner scan = new Scanner(System.in); |
|||
ttt.print(); |
|||
ttt.print(cli); |
|||
while (scan.hasNext()) { |
|||
ttt.update(scan.next()); |
|||
ttt.print(); |
|||
ttt.print(cli); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
package Application; |
|||
|
|||
import org.junit.jupiter.api.AfterEach; |
|||
import org.junit.jupiter.api.BeforeEach; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import java.io.ByteArrayOutputStream; |
|||
import java.io.PrintStream; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals; |
|||
|
|||
class CliTest { |
|||
|
|||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); |
|||
private final PrintStream originalOut = System.out; |
|||
|
|||
Cli cli; |
|||
|
|||
@BeforeEach |
|||
void setUp() { |
|||
System.setOut(new PrintStream(outContent)); |
|||
cli = new Cli(System.out); |
|||
} |
|||
|
|||
@AfterEach |
|||
void tearDown() { |
|||
System.setOut(originalOut); |
|||
} |
|||
|
|||
@Test |
|||
void getPrintStream() { |
|||
cli.getPrintStream().println("Hello World!"); |
|||
assertEquals("Hello World!\n", outContent.toString().replaceAll("\r", "")); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue