summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/util/Event1Test.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/jrummikub/util/Event1Test.java')
-rw-r--r--test/jrummikub/util/Event1Test.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/test/jrummikub/util/Event1Test.java b/test/jrummikub/util/Event1Test.java
new file mode 100644
index 0000000..b7e56bf
--- /dev/null
+++ b/test/jrummikub/util/Event1Test.java
@@ -0,0 +1,82 @@
+package jrummikub.util;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+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 fire(Integer n) {
+ fired += n;
+
+ }
+ });
+ assertEquals(fired, 0);
+ testEvent.fire(10);
+ assertEquals(fired, 10);
+ testEvent.fire(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 fire(Integer n) {
+ fired += n;
+
+ }
+ });
+ testEvent.add(new IListener1<Integer>() {
+
+ @Override
+ public void fire(Integer n) {
+ fired2 -= n;
+
+ }
+ });
+ assertEquals(fired, 0);
+ assertEquals(fired2, 0);
+ testEvent.fire(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 fire(Integer n) {
+ fired += n;
+
+ }
+ });
+ IListener1<Integer> rem = new IListener1<Integer>() {
+
+ @Override
+ public void fire(Integer n) {
+ fail();
+ }
+ };
+ testEvent.add(rem);
+ testEvent.remove(rem);
+ testEvent.fire(10);
+ assertEquals(fired, 10);
+ }
+}