Skip to content

Commit 83c2fbd

Browse files
author
Richard Jones
committed
Add unit test to show that the callback method is called.
1 parent 7ab799c commit 83c2fbd

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

callback/src/test/java/com/iluwatar/callback/AppTest.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,38 @@
22

33
import 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
*/
1213
public 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
}

0 commit comments

Comments
 (0)