From 41fe3c93b3f0c880ce550fda4cd6ad6f30d3e99c Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Wed, 8 Jun 2011 17:11:44 +0200 Subject: =?UTF-8?q?Test=20f=C3=BCr=20util=20und=20save=20control?= 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@387 72836036-5685-4462-b002-a69064685172 --- test/jrummikub/util/Event3Test.java | 153 ++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 test/jrummikub/util/Event3Test.java (limited to 'test/jrummikub/util') diff --git a/test/jrummikub/util/Event3Test.java b/test/jrummikub/util/Event3Test.java new file mode 100644 index 0000000..34aa851 --- /dev/null +++ b/test/jrummikub/util/Event3Test.java @@ -0,0 +1,153 @@ +package jrummikub.util; + +import static org.junit.Assert.*; + +import org.junit.Test; + +/** + * Test class for {@link Event2} + */ +public class Event3Test { + + int fired, fired2, fired3, fired4, fired5, fired6; + + /** */ + @Test + public void singleListener() { + fired = 0; + fired2 = 0; + fired3 = 0; + Event3 testEvent = new Event3(); + testEvent.add(new IListener3() { + + @Override + public void handle(Integer n, Integer m, Integer o) { + fired += n; + fired2 += m; + fired3 += o; + } + }); + assertEquals(fired, 0); + assertEquals(fired2, 0); + assertEquals(fired3, 0); + testEvent.emit(10, 5, 3); + assertEquals(fired, 10); + assertEquals(fired2, 5); + assertEquals(fired3, 3); + testEvent.emit(20, 45, 42); + assertEquals(fired, 30); + assertEquals(fired2, 50); + assertEquals(fired3, 45); + } + + /** */ + @Test + public void twoListeners() { + fired = 0; + fired2 = 0; + fired3 = 0; + fired4 = 0; + fired5 = 0; + fired6 = 0; + Event3 testEvent = new Event3(); + testEvent.add(new IListener3() { + + @Override + public void handle(Integer n, Integer m, Integer o) { + fired += n; + fired2 += m; + fired3 += o; + } + }); + testEvent.add(new IListener3() { + + @Override + public void handle(Integer n, Integer m, Integer o) { + fired4 -= n; + fired5 -= m; + fired6 -= o; + } + }); + assertEquals(fired, 0); + assertEquals(fired2, 0); + assertEquals(fired3, 0); + assertEquals(fired4, 0); + assertEquals(fired5, 0); + assertEquals(fired6, 0); + testEvent.emit(5, 10, 4); + assertEquals(fired, 5); + assertEquals(fired2, 10); + assertEquals(fired3, 4); + assertEquals(fired4, -5); + assertEquals(fired5, -10); + assertEquals(fired6, -4); + } + + /** */ + @Test + public void removeListener() { + fired = 0; + fired2 = 0; + fired3 = 0; + Event3 testEvent = new Event3(); + testEvent.add(new IListener3() { + + @Override + public void handle(Integer n, Integer m, Integer o) { + fired += n; + fired2 += m; + fired3 += o; + } + }); + IListener3 rem = new IListener3() { + + @Override + public void handle(Integer n, Integer m, Integer o) { + fail(); + } + }; + assertEquals(fired, 0); + assertEquals(fired2, 0); + assertEquals(fired3, 0); + testEvent.add(rem); + testEvent.remove(rem); + testEvent.emit(10, 20, 30); + assertEquals(fired, 10); + assertEquals(fired2, 20); + assertEquals(fired3, 30); + } + + /** */ + @Test + public void removeListenerByConnection() { + fired = 0; + fired2 = 0; + fired3 = 0; + Event3 testEvent = new Event3(); + testEvent.add(new IListener3() { + + @Override + public void handle(Integer n, Integer m, Integer o) { + fired += n; + fired2 += m; + fired3 += o; + } + }); + IListener3 rem = new IListener3() { + + @Override + public void handle(Integer n, Integer m, Integer o) { + fail(); + } + }; + assertEquals(fired, 0); + assertEquals(fired2, 0); + assertEquals(fired3, 0); + Connection connection = testEvent.add(rem); + connection.remove(); + testEvent.emit(10, 20, 30); + assertEquals(fired, 10); + assertEquals(fired2, 20); + assertEquals(fired3, 30); + } +} -- cgit v1.2.3