summaryrefslogtreecommitdiffstats
path: root/test/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'test/jrummikub')
-rw-r--r--test/jrummikub/util/Event1Test.java25
-rw-r--r--test/jrummikub/util/Event2Test.java29
-rw-r--r--test/jrummikub/util/EventTest.java25
3 files changed, 79 insertions, 0 deletions
diff --git a/test/jrummikub/util/Event1Test.java b/test/jrummikub/util/Event1Test.java
index 3f8839d..c3f388e 100644
--- a/test/jrummikub/util/Event1Test.java
+++ b/test/jrummikub/util/Event1Test.java
@@ -80,4 +80,29 @@ public class Event1Test {
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);
+ }
}
diff --git a/test/jrummikub/util/Event2Test.java b/test/jrummikub/util/Event2Test.java
index 6d1958e..c258ddf 100644
--- a/test/jrummikub/util/Event2Test.java
+++ b/test/jrummikub/util/Event2Test.java
@@ -93,4 +93,33 @@ public class Event2Test {
assertEquals(fired, 10);
assertEquals(fired2, 20);
}
+
+ @Test
+ public void removeListenerByConnection() {
+ fired = 0;
+ fired2 = 0;
+ Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
+ testEvent.add(new IListener2<Integer, Integer>() {
+
+ @Override
+ public void handle(Integer n, Integer m) {
+ fired += n;
+ fired2 += m;
+ }
+ });
+ IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() {
+
+ @Override
+ public void handle(Integer n, Integer m) {
+ fail();
+ }
+ };
+ assertEquals(fired, 0);
+ assertEquals(fired2, 0);
+ Connection connection = testEvent.add(rem);
+ connection.remove();
+ testEvent.emit(10, 20);
+ assertEquals(fired, 10);
+ assertEquals(fired2, 20);
+ }
}
diff --git a/test/jrummikub/util/EventTest.java b/test/jrummikub/util/EventTest.java
index 15bd632..f8c505c 100644
--- a/test/jrummikub/util/EventTest.java
+++ b/test/jrummikub/util/EventTest.java
@@ -79,5 +79,30 @@ public class EventTest {
testEvent.emit();
assertTrue(fired);
}
+
+ @Test
+ public void removeListenerByConnection() {
+ fired = false;
+ Event testEvent = new Event();
+ testEvent.add(new IListener() {
+
+ @Override
+ public void handle() {
+ fired = true;
+
+ }
+ });
+ IListener rem = new IListener() {
+
+ @Override
+ public void handle() {
+ fail();
+ }
+ };
+ Connection connection = testEvent.add(rem);
+ connection.remove();
+ testEvent.emit();
+ assertTrue(fired);
+ }
}