From 675e75818fe40ba0b745388655e5dac9c852afe2 Mon Sep 17 00:00:00 2001 From: MikeZyeman Date: Fri, 8 Oct 2021 09:51:14 +0200 Subject: [PATCH] + Created UnitTest for class Game --- test/GameTest.java | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/test/GameTest.java b/test/GameTest.java index b721aa7..6de9bc4 100644 --- a/test/GameTest.java +++ b/test/GameTest.java @@ -1,9 +1,36 @@ import static org.junit.jupiter.api.Assertions.*; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + + class GameTest { - @org.junit.jupiter.api.Test - void checkTest() { + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + private final PrintStream originalOut = System.out; + private final PrintStream originalErr = System.err; + + @Before + public void setUpStreams() { + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + } + @After + public void restoreStreams() { + System.setOut(originalOut); + System.setErr(originalErr); + } + + @Test + void checkTest() { + System.out.println("hello"); + assertEquals("hello", outContent.toString()); } } \ No newline at end of file