Commit f9ce5bc

mo <mo.khan@gmail.com>
2019-06-18 22:44:53
try to create a testable API using constructor injection
1 parent 82589bb
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) {}
 
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() {