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); } }