File tree Expand file tree Collapse file tree 1 file changed +25
-5
lines changed
callback/src/test/java/com/iluwatar/callback Expand file tree Collapse file tree 1 file changed +25
-5
lines changed Original file line number Diff line number Diff line change 22
33import org .junit .Test ;
44
5- import com . iluwatar . callback . App ;
5+ import static org . junit . Assert . assertEquals ;
66
77/**
8- *
9- * Application test
8+ * Add a field as a counter. Every time the callback method is called increment this
9+ * field. Unit test checks that the field is being incremented.
1010 *
11+ * Could be done with mock objects as well where the call method call is verified.
1112 */
1213public class AppTest {
1314
15+ private Integer callingCount = 0 ;
16+
1417 @ Test
1518 public void test () {
16- String [] args = {};
17- App .main (args );
19+ Callback callback = new Callback () {
20+ @ Override
21+ public void call () {
22+ callingCount ++;
23+ }
24+ };
25+
26+ Task task = new SimpleTask ();
27+
28+ assertEquals ("Initial calling count of 0" , new Integer (0 ), callingCount );
29+
30+ task .executeWith (callback );
31+
32+ assertEquals ("Callback called once" , new Integer (1 ), callingCount );
33+
34+ task .executeWith (callback );
35+
36+ assertEquals ("Callback called twice" , new Integer (2 ), callingCount );
37+
1838 }
1939}
You can’t perform that action at this time.
0 commit comments