From 53824198db2bade71c895c91caab14f338139fd2 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Thu, 5 May 2011 19:49:59 +0200 Subject: Added tests for Connection git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@150 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/util/Event1Test.java | 25 +++++++++++++++++++++++++ test/jrummikub/util/Event2Test.java | 29 +++++++++++++++++++++++++++++ test/jrummikub/util/EventTest.java | 25 +++++++++++++++++++++++++ 3 files changed, 79 insertions(+) (limited to 'test') 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 testEvent = new Event1(); + testEvent.add(new IListener1() { + + @Override + public void handle(Integer n) { + fired += n; + + } + }); + IListener1 rem = new IListener1() { + + @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 testEvent = new Event2(); + testEvent.add(new IListener2() { + + @Override + public void handle(Integer n, Integer m) { + fired += n; + fired2 += m; + } + }); + IListener2 rem = new IListener2() { + + @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); + } } -- cgit v1.2.3