summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-05-01 00:18:55 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-05-01 00:18:55 +0200
commit5e7c489921f3141e62f229646d7f16c7b691be3d (patch)
treed1d4c269f92a0ef4da0447af1bbd6455f0aae7a8 /test
parentb8fa08c9bb502b08e643c84c656f31cf0ad23f4d (diff)
downloadJRummikub-5e7c489921f3141e62f229646d7f16c7b691be3d.tar
JRummikub-5e7c489921f3141e62f229646d7f16c7b691be3d.zip
Add 2-argument events
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@43 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test')
-rw-r--r--test/jrummikub/util/Event2Test.java95
-rw-r--r--test/jrummikub/util/EventTest.java1
2 files changed, 95 insertions, 1 deletions
diff --git a/test/jrummikub/util/Event2Test.java b/test/jrummikub/util/Event2Test.java
new file mode 100644
index 0000000..cbfecd5
--- /dev/null
+++ b/test/jrummikub/util/Event2Test.java
@@ -0,0 +1,95 @@
+package jrummikub.util;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class Event2Test {
+
+ int fired, fired2, fired3, fired4;
+
+ @Test
+ public void singleListener() {
+ fired = 0;
+ fired2 = 0;
+ Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
+ testEvent.add(new IListener2<Integer, Integer>() {
+
+ @Override
+ public void fire(Integer n, Integer m) {
+ fired += n;
+ fired2 += m;
+ }
+ });
+ assertEquals(fired, 0);
+ assertEquals(fired2, 0);
+ testEvent.fire(10, 5);
+ assertEquals(fired, 10);
+ assertEquals(fired2, 5);
+ testEvent.fire(20, 45);
+ assertEquals(fired, 30);
+ assertEquals(fired2, 50);
+ }
+
+ @Test
+ public void twoListeners() {
+ fired = 0;
+ fired2 = 0;
+ fired3 = 0;
+ fired4 = 0;
+ Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
+ testEvent.add(new IListener2<Integer, Integer>() {
+
+ @Override
+ public void fire(Integer n, Integer m) {
+ fired += n;
+ fired2 += m;
+ }
+ });
+ testEvent.add(new IListener2<Integer, Integer>() {
+
+ @Override
+ public void fire(Integer n, Integer m) {
+ fired3 -= n;
+ fired4 -= m;
+ }
+ });
+ assertEquals(fired, 0);
+ assertEquals(fired2, 0);
+ assertEquals(fired3, 0);
+ assertEquals(fired4, 0);
+ testEvent.fire(5, 10);
+ assertEquals(fired, 5);
+ assertEquals(fired2, 10);
+ assertEquals(fired3, -5);
+ assertEquals(fired4, -10);
+ }
+
+ @Test public void removeListener() {
+ fired = 0;
+ fired2 = 0;
+ Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
+ testEvent.add(new IListener2<Integer, Integer>() {
+
+ @Override
+ public void fire(Integer n, Integer m) {
+ fired += n;
+ fired2 += m;
+ }
+ });
+ IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() {
+
+ @Override
+ public void fire(Integer n, Integer m) {
+ fail();
+ }
+ };
+ assertEquals(fired, 0);
+ assertEquals(fired2, 0);
+ testEvent.add(rem);
+ testEvent.remove(rem);
+ testEvent.fire(10, 20);
+ assertEquals(fired, 10);
+ assertEquals(fired2, 20);
+ }
+}
diff --git a/test/jrummikub/util/EventTest.java b/test/jrummikub/util/EventTest.java
index 0802247..0595306 100644
--- a/test/jrummikub/util/EventTest.java
+++ b/test/jrummikub/util/EventTest.java
@@ -1,6 +1,5 @@
package jrummikub.util;
-import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;