diff options
Diffstat (limited to 'test/jrummikub/util/Event1Test.java')
-rw-r--r-- | test/jrummikub/util/Event1Test.java | 205 |
1 files changed, 106 insertions, 99 deletions
diff --git a/test/jrummikub/util/Event1Test.java b/test/jrummikub/util/Event1Test.java index c3f388e..6d61882 100644 --- a/test/jrummikub/util/Event1Test.java +++ b/test/jrummikub/util/Event1Test.java @@ -4,105 +4,112 @@ import static org.junit.Assert.*; import org.junit.Test; +/** + * Test class for {@link Event1} + */ public class Event1Test { - int fired, fired2; - - @Test - public void singleListener() { - fired = 0; - Event1<Integer> testEvent = new Event1<Integer>(); - testEvent.add(new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fired += n; - - } - }); - assertEquals(fired, 0); - testEvent.emit(10); - assertEquals(fired, 10); - testEvent.emit(20); - assertEquals(fired, 30); - } - - @Test - public void twoListeners() { - fired = 0; - fired2 = 0; - Event1<Integer> testEvent = new Event1<Integer>(); - testEvent.add(new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fired += n; - - } - }); - testEvent.add(new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fired2 -= n; - - } - }); - assertEquals(fired, 0); - assertEquals(fired2, 0); - testEvent.emit(5); - assertEquals(fired, 5); - assertEquals(fired2, -5); - - } - - @Test - public void removeListener() { - fired = 0; - Event1<Integer> testEvent = new Event1<Integer>(); - testEvent.add(new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fired += n; - - } - }); - IListener1<Integer> rem = new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fail(); - } - }; - testEvent.add(rem); - testEvent.remove(rem); - testEvent.emit(10); - assertEquals(fired, 10); - } - - @Test - public void removeListenerByConnection() { - fired = 0; - Event1<Integer> testEvent = new Event1<Integer>(); - testEvent.add(new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fired += n; - - } - }); - IListener1<Integer> rem = new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fail(); - } - }; - Connection connection = testEvent.add(rem); - connection.remove(); - testEvent.emit(10); - assertEquals(fired, 10); - } + int fired, fired2; + + /** */ + @Test + public void singleListener() { + fired = 0; + Event1<Integer> testEvent = new Event1<Integer>(); + testEvent.add(new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fired += n; + + } + }); + assertEquals(fired, 0); + testEvent.emit(10); + assertEquals(fired, 10); + testEvent.emit(20); + assertEquals(fired, 30); + } + + /** */ + @Test + public void twoListeners() { + fired = 0; + fired2 = 0; + Event1<Integer> testEvent = new Event1<Integer>(); + testEvent.add(new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fired += n; + + } + }); + testEvent.add(new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fired2 -= n; + + } + }); + assertEquals(fired, 0); + assertEquals(fired2, 0); + testEvent.emit(5); + assertEquals(fired, 5); + assertEquals(fired2, -5); + + } + + /** */ + @Test + public void removeListener() { + fired = 0; + Event1<Integer> testEvent = new Event1<Integer>(); + testEvent.add(new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fired += n; + + } + }); + IListener1<Integer> rem = new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fail(); + } + }; + testEvent.add(rem); + testEvent.remove(rem); + testEvent.emit(10); + assertEquals(fired, 10); + } + + /** */ + @Test + public void removeListenerByConnection() { + fired = 0; + Event1<Integer> testEvent = new Event1<Integer>(); + testEvent.add(new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fired += n; + + } + }); + IListener1<Integer> rem = new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fail(); + } + }; + Connection connection = testEvent.add(rem); + connection.remove(); + testEvent.emit(10); + assertEquals(fired, 10); + } } |