@@ -23,7 +23,15 @@ public class DeepDive09
2323 public void exceptionsShouldProvideInformation () throws Exception
2424 {
2525 Chain c = createChain ();
26+ //the answer is "surprise", but why? be sure to use the debugger to follow the execution path.
2627 int answer = c .get ("a" ).get ("b" ).get (___ ).get ("d" ).get ("e" ).value ;
28+ Assert .assertEquals (2048 , answer );
29+ }
30+ @ Test
31+ public void exceptionsShouldProvideUsefulInformation () throws Exception
32+ {
33+ Chain c = createChain ();
34+ int answer = c .get ("a" ).get (___ ).get ("c" ).get ("d" ).get ("e" ).value ;
2735 //the answer is "surprise", but why? be sure to use the debugger to follow the execution path.
2836 Assert .assertEquals (2048 , answer );
2937 }
@@ -36,6 +44,15 @@ public void exceptionsShouldExplainPreconditions() throws Exception
3644 int fun = game .play ();
3745 Assert .assertEquals (11 , fun );
3846 }
47+ @ Test
48+ public void exceptionsShouldExplainAllPreconditions () throws Exception
49+ {
50+ Game game = new Game ();
51+ /* Add needed line here -- game.turnOn(1); -- need to figure out how to abstract this */
52+ //game.turnOn(1);
53+ int fun = game .play ();
54+ Assert .assertEquals (11 , fun );
55+ }
3956 /**
4057 * Ignore the following, It's needed to run the homework
4158 *
@@ -49,26 +66,8 @@ public void exceptionsShouldExplainPreconditions() throws Exception
4966 *
5067 *
5168 */
52- private int call (int a , int b , int c )
53- {
54- if (((a + c ) / 2 ) == b ) { throw new FormattedException ("%s is not a valid input for (%s, %s, %s)" , b , a , b ,
55- c ); }
56- return a + b + c ;
57- }
58- private static class Game
59- {
60- boolean on = false ;
61- public void turnOn ()
62- {
63- on = true ;
64- }
65- public int play ()
66- {
67- if (!on ) { throw new FormattedException (
68- "Before you can play a game you need to turn it on.\n game.turnOn()" ); }
69- return 11 ;
70- }
71- }
69+ public String ___ = "You need to fill in the blank ___" ;
70+ public Integer ____ = -99 ;
7271 private static class Chain
7372 {
7473 private String label ;
@@ -102,6 +101,29 @@ public _____(String message, Exception originalException)
102101 super (message , originalException );
103102 }
104103 }
105- public String ___ = "You need to fill in the blank ___" ;
106- public Integer ____ = -99 ;
104+ private int call (int a , int b , int c )
105+ {
106+ if (((a + c ) / 2 ) == b ) { throw new FormattedException ("%s is not a valid input for (%s, %s, %s)" , b , a , b ,
107+ c ); }
108+ return a + b + c ;
109+ }
110+ private static class Game
111+ {
112+ boolean on = false ;
113+ public void turnOn ()
114+ {
115+ on = true ;
116+ }
117+ public void turnOn (int howMany )
118+ {
119+ on = true ;
120+ }
121+ public int play ()
122+ {
123+ if (!on ) { throw new FormattedException (
124+ "Before you can play a game you need to turn it on.\n game.turnOn()" ); }
125+ //shows use of 'magic numbers'
126+ return 11 ;
127+ }
128+ }
107129}
0 commit comments