From 214b5a0bd61f74210a22d9e2789bd6bb135e32ef Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Sat, 30 Apr 2011 14:19:15 +0200 Subject: =?UTF-8?q?Tests=20f=C3=BCr=20Event=20und=20Event1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@20 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/util/Event1Test.java | 82 ++++++++++++++++++++++++++++++++++++ test/jrummikub/util/EventTest.java | 83 +++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 test/jrummikub/util/Event1Test.java create mode 100644 test/jrummikub/util/EventTest.java (limited to 'test/jrummikub/util') 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 testEvent = new Event1(); + testEvent.add(new IListener1() { + + @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 testEvent = new Event1(); + testEvent.add(new IListener1() { + + @Override + public void fire(Integer n) { + fired += n; + + } + }); + testEvent.add(new IListener1() { + + @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 testEvent = new Event1(); + testEvent.add(new IListener1() { + + @Override + public void fire(Integer n) { + fired += n; + + } + }); + IListener1 rem = new IListener1() { + + @Override + public void fire(Integer n) { + fail(); + } + }; + testEvent.add(rem); + testEvent.remove(rem); + testEvent.fire(10); + assertEquals(fired, 10); + } +} diff --git a/test/jrummikub/util/EventTest.java b/test/jrummikub/util/EventTest.java new file mode 100644 index 0000000..0802247 --- /dev/null +++ b/test/jrummikub/util/EventTest.java @@ -0,0 +1,83 @@ +package jrummikub.util; + +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; + +public class EventTest { + boolean fired, fired2; + + @Test + public void singleListener() { + fired = false; + Event testEvent = new Event(); + testEvent.add(new IListener() { + + @Override + public void fire() { + fired = true; + + } + }); + assertFalse(fired); + testEvent.fire(); + assertTrue(fired); + fired = false; + testEvent.fire(); + assertTrue(fired); + } + + @Test + public void twoListeners() { + fired = false; + fired2 = false; + Event testEvent = new Event(); + testEvent.add(new IListener() { + + @Override + public void fire() { + fired = true; + + } + }); + testEvent.add(new IListener() { + + @Override + public void fire() { + fired2 = true; + + } + }); + assertFalse(fired); + assertFalse(fired2); + testEvent.fire(); + assertTrue(fired); + assertTrue(fired2); + + } + + @Test public void removeListener() { + fired = false; + Event testEvent = new Event(); + testEvent.add(new IListener() { + + @Override + public void fire() { + fired = true; + + } + }); + IListener rem = new IListener() { + + @Override + public void fire() { + fail(); + } + }; + testEvent.add(rem); + testEvent.remove(rem); + testEvent.fire(); + assertTrue(fired); + } + +} -- cgit v1.2.3