diff options
| author | mo <mo.khan@gmail.com> | 2019-06-18 16:44:53 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2019-06-18 16:44:53 -0600 |
| commit | f9ce5bc529295696c841afc7c17c5b61083a8082 (patch) | |
| tree | 54f0249d54c94c9a391e3df82ae81713023c1b18 /src/Q4 | |
| parent | 82589bb93e5b3d7a4c99394c1486c08e1d63eec4 (diff) | |
try to create a testable API using constructor injection
Diffstat (limited to 'src/Q4')
| -rw-r--r-- | src/Q4/RandomSumGame.java | 6 | ||||
| -rw-r--r-- | src/Q4/RandomSumGameTest.java | 3 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/Q4/RandomSumGame.java b/src/Q4/RandomSumGame.java index e5b6ce0..7976288 100644 --- a/src/Q4/RandomSumGame.java +++ b/src/Q4/RandomSumGame.java @@ -1,5 +1,6 @@ package Q4; +import java.io.*; import java.util.*; public class RandomSumGame { @@ -9,6 +10,11 @@ public class RandomSumGame { private int sum; private int valuePoint; private String status; + private PrintStream out; + + public RandomSumGame(PrintStream out) { + this.out = out; + } public void play(int d1, int d2) {} diff --git a/src/Q4/RandomSumGameTest.java b/src/Q4/RandomSumGameTest.java index 3a5e26c..41c0923 100644 --- a/src/Q4/RandomSumGameTest.java +++ b/src/Q4/RandomSumGameTest.java @@ -1,6 +1,7 @@ package ca.mokhan.test; import Q4.*; +import java.io.*; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -10,7 +11,7 @@ public class RandomSumGameTest extends TestCase { public RandomSumGameTest(String testName) { super(testName); - this.subject = new RandomSumGame(); + this.subject = new RandomSumGame(new PrintStream(new ByteArrayOutputStream())); } public static Test suite() { |
