File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
main/java/com/iluwatar/callback
test/java/com/iluwatar/callback Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .iluwatar .callback ;
2+
3+ /**
4+ *
5+ * This example generates the exact same output as {@link App} however the callback has been
6+ * defined as a Lambdas expression.
7+ *
8+ */
9+ public class LambdasApp {
10+
11+ /**
12+ * Program entry point
13+ */
14+ public static void main (String [] args ) {
15+ Task task = new SimpleTask ();
16+ Callback c = () -> System .out .println ("I'm done now." );
17+ task .executeWith (c );
18+ }
19+ }
Original file line number Diff line number Diff line change @@ -36,4 +36,22 @@ public void call() {
3636 assertEquals ("Callback called twice" , new Integer (2 ), callingCount );
3737
3838 }
39+
40+ @ Test
41+ public void testWithLambdasExample () {
42+ Callback callback = () -> callingCount ++;
43+
44+ Task task = new SimpleTask ();
45+
46+ assertEquals ("Initial calling count of 0" , new Integer (0 ), callingCount );
47+
48+ task .executeWith (callback );
49+
50+ assertEquals ("Callback called once" , new Integer (1 ), callingCount );
51+
52+ task .executeWith (callback );
53+
54+ assertEquals ("Callback called twice" , new Integer (2 ), callingCount );
55+
56+ }
3957}
You can’t perform that action at this time.
0 commit comments