diff options
Diffstat (limited to 'test/jrummikub')
-rw-r--r-- | test/jrummikub/control/RoundControlTest.java | 17 | ||||
-rw-r--r-- | test/jrummikub/control/TurnControlTest.java | 37 | ||||
-rw-r--r-- | test/jrummikub/model/GameStateTest.java | 6 | ||||
-rw-r--r-- | test/jrummikub/model/HandTest.java | 12 | ||||
-rw-r--r-- | test/jrummikub/model/StoneHeapTest.java | 20 | ||||
-rw-r--r-- | test/jrummikub/model/StoneSetTest.java | 34 | ||||
-rw-r--r-- | test/jrummikub/model/StoneTrayTest.java | 18 | ||||
-rw-r--r-- | test/jrummikub/model/TableTest.java | 29 | ||||
-rw-r--r-- | test/jrummikub/util/Event1Test.java | 205 | ||||
-rw-r--r-- | test/jrummikub/util/Event2Test.java | 219 | ||||
-rw-r--r-- | test/jrummikub/util/EventTest.java | 8 |
11 files changed, 369 insertions, 236 deletions
diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java index f183505..6c8dffe 100644 --- a/test/jrummikub/control/RoundControlTest.java +++ b/test/jrummikub/control/RoundControlTest.java @@ -26,12 +26,18 @@ import jrummikub.view.MockView; import org.junit.Before; import org.junit.Test; +/** + * Tests for {@link RoundControl} + */ public class RoundControlTest { private MockView view; private MockGameState testGameState; private RoundControl testRound; private MockTable newTable; + /** + * For each test create a round control initialized by a mock model and view + */ @Before public void setup() { view = new MockView(); @@ -86,7 +92,7 @@ public class RoundControlTest { view.displayStartTurnPanel = false; } - // TODO hier weitermachen + /** */ @Test public void testDealStone() { testRound.deal(); @@ -97,12 +103,14 @@ public class RoundControlTest { assertEquals(28, testGameState.getActivePlayer().getHand().getSize()); } + /** */ @Test public void testDeal() { testRound.deal(); checkCorrectlyDealed(); } + /** */ @Test public void testStartRound() { testRound.startRound(); @@ -111,6 +119,7 @@ public class RoundControlTest { checkTurnStartSetUp(); } + /** */ @Test public void testTableDisplay() { testRound.startRound(); @@ -120,6 +129,7 @@ public class RoundControlTest { view.getPlayerPanel().endTurnEvent.emit(); } + /** */ @Test public void testTableValidHandChanged() { testRound.startRound(); @@ -139,6 +149,7 @@ public class RoundControlTest { checkTurnStartSetUp(); } + /** */ @Test public void testTableInvalidHandChanged() { testRound.startRound(); @@ -160,6 +171,7 @@ public class RoundControlTest { checkTurnStartSetUp(); } + /** */ @Test public void testTableValidHandUnchanged() { testRound.startRound(); @@ -179,6 +191,7 @@ public class RoundControlTest { checkTurnStartSetUp(); } + /** */ @Test public void testTableInvalidHandUnchanged() { testRound.startRound(); @@ -198,6 +211,7 @@ public class RoundControlTest { checkTurnStartSetUp(); } + /** */ @Test public void testWinning() { testRound.startRound(); @@ -217,6 +231,7 @@ public class RoundControlTest { assertTrue(view.displayWinPanel); } + /** */ @Test public void testTableDifference() { MockTable oldTable = new MockTable(); diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java index 4d6d0c2..197623e 100644 --- a/test/jrummikub/control/TurnControlTest.java +++ b/test/jrummikub/control/TurnControlTest.java @@ -34,6 +34,9 @@ import jrummikub.view.MockView; import org.junit.Before; import org.junit.Test; +/** + * Tests for {@link TurnControl} + */ public class TurnControlTest { static class AccessibleTable extends Table { StoneSet[] getSetArray() { @@ -93,6 +96,7 @@ public class TurnControlTest { assertFalse(stoneSetsModel.hasNext()); } + /** */ @Before public void setUp() { mockView = new MockView(); @@ -102,6 +106,7 @@ public class TurnControlTest { testControl = new TurnControl(mockHand, mockTable, mockView, mockTimer); } + /** */ @Test public void startTimer() { testControl.startTurn(); @@ -109,6 +114,7 @@ public class TurnControlTest { assertTrue(mockTimer.timerRunning); } + /** */ @SuppressWarnings("unchecked") @Test public void showInitialHand() { @@ -134,6 +140,7 @@ public class TurnControlTest { assertFalse(mockView.displayStartTurnPanel); } + /** */ @Test public void viewEndOfTurn() { testControl.startTurn(); @@ -156,6 +163,7 @@ public class TurnControlTest { assertTrue(mockView.playerPanel.endTurnEvent.listeners.isEmpty()); } + /** */ @Test public void timerEndOfTurn() { testControl.startTurn(); @@ -177,6 +185,7 @@ public class TurnControlTest { assertFalse(mockTimer.timerRunning); } + /** */ @Test public void deselctOnEndOfTurn() { testControl.startTurn(); @@ -190,6 +199,7 @@ public class TurnControlTest { assertCollection(new ArrayList<Stone>()); } + /** */ @Test public void selectStoneInHand() { testControl.startTurn(); @@ -209,6 +219,7 @@ public class TurnControlTest { } + /** */ @Test public void collectStoneInHand() { testControl.startTurn(); @@ -232,6 +243,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(secondStone)); } + /** */ @Test public void deselectStoneInCollection() { testControl.startTurn(); @@ -248,6 +260,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(secondStone)); } + /** */ @Test public void reorderCollection() { testControl.startTurn(); @@ -264,6 +277,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(secondStone, firstStone)); } + /** */ @Test public void deselectWholeCollection() { testControl.startTurn(); @@ -283,6 +297,7 @@ public class TurnControlTest { assertCollection(new ArrayList<Stone>()); } + /** */ @Test public void selectStoneOnTable() { testControl.startTurn(); @@ -302,6 +317,7 @@ public class TurnControlTest { } + /** */ @Test public void collectStoneOnTable() { testControl.startTurn(); @@ -325,6 +341,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(secondStone)); } + /** */ @Test public void selectSetOnTable() { testControl.startTurn(); @@ -347,6 +364,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(stone3, stone4)); } + /** */ @Test public void collectSetOnTable() { testControl.startTurn(); @@ -369,6 +387,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(stone1, stone2, stone3, stone4)); } + /** */ @Test public void rangeSelectOnTableReverse() { testControl.startTurn(); @@ -389,6 +408,7 @@ public class TurnControlTest { } + /** */ @Test public void rangeSelectOnTable() { testControl.startTurn(); @@ -409,6 +429,7 @@ public class TurnControlTest { } + /** */ @Test public void rangeCollectOnTable() { testControl.startTurn(); @@ -432,6 +453,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3)); } + /** */ @Test public void rangeFailSelect() { testControl.startTurn(); @@ -456,6 +478,7 @@ public class TurnControlTest { } + /** */ @Test public void rangeFailCollect() { testControl.startTurn(); @@ -479,6 +502,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(stone1, stone2)); } + /** */ @Test public void rangeSelectOnHandReverse() { testControl.startTurn(); @@ -498,6 +522,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(stone1, stone2, stone3)); } + /** */ @Test public void rangeSelectOnHand() { testControl.startTurn(); @@ -517,6 +542,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(stone1, stone2, stone3)); } + /** */ @Test public void rangeCollectOnHand() { testControl.startTurn(); @@ -539,6 +565,7 @@ public class TurnControlTest { assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3)); } + /** */ @Test public void rangeFailSelectHand() { testControl.startTurn(); @@ -560,6 +587,7 @@ public class TurnControlTest { } + /** */ @Test public void rangeFailCollectHand() { testControl.startTurn(); @@ -587,6 +615,7 @@ public class TurnControlTest { assertEquals(expectedStones, selectedStones); } + /** */ @Test public void testAddLeft() { AccessibleTable table = new AccessibleTable(); @@ -703,6 +732,7 @@ public class TurnControlTest { assertSame(newSet2.get(5), blackFive); } + /** */ @Test public void testAddRight() { AccessibleTable table = new AccessibleTable(); @@ -819,6 +849,7 @@ public class TurnControlTest { assertSame(newSet2.get(5), redThree); } + /** */ @Test public void testAddNewSet() { AccessibleTable table = new AccessibleTable(); @@ -908,7 +939,7 @@ public class TurnControlTest { checkTableDisplay(table); checkHandDisplay(mockHand); } - + /** */ @Test public void testSortByGroups() { testControl.startTurn(); @@ -969,6 +1000,7 @@ public class TurnControlTest { checkHandDisplay(mockHand); } + /** */ @Test public void testSortByRuns() { testControl.startTurn(); @@ -1029,6 +1061,7 @@ public class TurnControlTest { checkHandDisplay(mockHand); } + /** */ @Test public void testDropHandValid() { testControl.startTurn(); @@ -1056,7 +1089,7 @@ public class TurnControlTest { } assertEquals(expected, handStones); } - + /** */ @Test public void testDropHandInvalid() { testControl.startTurn(); diff --git a/test/jrummikub/model/GameStateTest.java b/test/jrummikub/model/GameStateTest.java index e1de06c..5681904 100644 --- a/test/jrummikub/model/GameStateTest.java +++ b/test/jrummikub/model/GameStateTest.java @@ -6,15 +6,19 @@ import java.awt.Color; import org.junit.Before; import org.junit.Test; - +/** + * Test class for {@link GameState} + */ public class GameStateTest { private IGameState testGame; + /** */ @Before public void createGame() { testGame = new GameState(); } + /** */ @Test public void nextActiveTest() { // All there? diff --git a/test/jrummikub/model/HandTest.java b/test/jrummikub/model/HandTest.java index d913caf..46aa978 100644 --- a/test/jrummikub/model/HandTest.java +++ b/test/jrummikub/model/HandTest.java @@ -5,16 +5,20 @@ import static org.junit.Assert.assertEquals; import org.junit.Before;
import org.junit.Test;
-
+/**
+ * Test class for {@link Hand}
+ */
public class HandTest {
Hand hand;
+ /** */
@Before
public void setUp() {
hand = new Hand();
}
+ /** */
@Test
public void testSimpleDrop() {
Stone stone1 = new Stone(1, RED);
@@ -30,6 +34,7 @@ public class HandTest { assertEquals(new Position(2.5f, 0), hand.getPosition(stone3));
}
+ /** */
@Test
public void testSingleEdgeDrop() {
Stone stone1 = new Stone(2, RED);
@@ -42,6 +47,7 @@ public class HandTest { assertEquals(new Position(1, 0), hand.getPosition(stone2));
}
+ /** */
@Test
public void testNearEdgeDrop() {
Stone stone1 = new Stone(2, RED);
@@ -54,6 +60,7 @@ public class HandTest { assertEquals(new Position(1, 0), hand.getPosition(stone2));
}
+ /** */
@Test
public void testNearEdgeMiddleDrop() {
Stone stone1 = new Stone(1, RED);
@@ -69,6 +76,7 @@ public class HandTest { assertEquals(new Position(1, 0), hand.getPosition(stone3));
}
+ /** */
@Test
public void testNearRightEdgeDrop() {
Stone stone1 = new Stone(2, BLUE);
@@ -81,6 +89,7 @@ public class HandTest { assertEquals(new Position(12, 1), hand.getPosition(stone2));
}
+ /** */
@Test
public void testRightWrapDrop() {
Stone stone1 = new Stone(12, ORANGE);
@@ -93,6 +102,7 @@ public class HandTest { assertEquals(new Position(12.5f, 0), hand.getPosition(stone2));
}
+ /** */
@Test
public void testLeftWrapDrop() {
Stone stone1 = new Stone(1, ORANGE);
diff --git a/test/jrummikub/model/StoneHeapTest.java b/test/jrummikub/model/StoneHeapTest.java index 01f5da3..9fd375a 100644 --- a/test/jrummikub/model/StoneHeapTest.java +++ b/test/jrummikub/model/StoneHeapTest.java @@ -8,21 +8,29 @@ import java.util.Map; import org.junit.*; import static org.junit.Assert.*; +/** + * Tests for {@link StoneHeap} + */ public class StoneHeapTest { private StoneHeap testHeap; + /** */ @Before public void createHeap() { testHeap = new StoneHeap(); } - // Is the right number of Stones in heap? + /** + * Is the right number of Stones in heap? + */ @Test public void fullStoneHeap() { assertEquals(106, testHeap.heap.size()); } - // Enough stones of each color in heap? + /** + * Enough stones of each color in heap? + */ @Test public void fullColor() { Map<StoneColor, Integer> counters = new HashMap<StoneColor, Integer>(); @@ -40,7 +48,9 @@ public class StoneHeapTest { } } - // Enough Jokers? + /** + * Enough Jokers? + */ @Test public void fullJoker() { int countJoker = 0; @@ -51,14 +61,14 @@ public class StoneHeapTest { assertEquals(2, countJoker); } - // Draw Stone Test + /** */ @Test public void drawStoneTest() { assertNotNull(testHeap.drawStone()); assertEquals(105, testHeap.heap.size()); } - // Draw Stones Test + /** */ @Test public void drawStonesTest() { List<Stone> testStones = testHeap.drawStones(5); diff --git a/test/jrummikub/model/StoneSetTest.java b/test/jrummikub/model/StoneSetTest.java index b98d3d8..2575f22 100644 --- a/test/jrummikub/model/StoneSetTest.java +++ b/test/jrummikub/model/StoneSetTest.java @@ -11,21 +11,25 @@ import static jrummikub.model.StoneSet.Type.*; import org.junit.*; import static org.junit.Assert.*; +/** + * Tests for {@link StoneSet} + */ public class StoneSetTest { - // Is Valid-Test - // valid - public void assertSet(StoneSet.Type expectedType, List<Stone> stones) { + private void assertSet(StoneSet.Type expectedType, List<Stone> stones) { StoneSet set = new StoneSet(stones); assertSame(expectedType, set.classify()); } + // valid + /** */ @Test public void doubleJoker() { assertSet(GROUP, Arrays.asList(new Stone(RED), new Stone(BLACK), new Stone(1, BLACK))); } + /** */ @Test public void groups() { assertSet(GROUP, Arrays.asList(new Stone(1, RED), new Stone(1, BLACK), @@ -34,6 +38,7 @@ public class StoneSetTest { new Stone(1, BLUE), new Stone(1, ORANGE))); } + /** */ @Test public void runs() { assertSet(RUN, @@ -42,6 +47,7 @@ public class StoneSetTest { new Stone(6, BLUE))); } + /** */ @Test public void singleJoker() { assertSet(GROUP, @@ -51,17 +57,18 @@ public class StoneSetTest { } // invalid - + /** */ @Test public void outOfBounds() { - assertSet(INVALID, - Arrays.asList(new Stone(RED), new Stone(1, RED), new Stone(2, RED))); - assertSet(INVALID, - Arrays.asList(new Stone(12, RED), new Stone(13, RED), new Stone(RED))); + assertSet(INVALID, Arrays.asList(new Stone(RED), new Stone(1, RED), + new Stone(2, RED))); + assertSet(INVALID, Arrays.asList(new Stone(12, RED), + new Stone(13, RED), new Stone(RED))); assertSet(INVALID, Arrays.asList(new Stone(RED), new Stone(BLACK), new Stone(1, RED), new Stone(2, RED))); } + /** */ @Test public void sameColor() { assertSet(INVALID, @@ -70,6 +77,7 @@ public class StoneSetTest { new Stone(1, BLACK), new Stone(1, ORANGE), new Stone(RED))); } + /** */ @Test public void incorrectOrder() { assertSet(INVALID, @@ -80,6 +88,7 @@ public class StoneSetTest { Arrays.asList(new Stone(4, RED), new Stone(RED), new Stone(5, RED))); } + /** */ @Test public void otherInvalid() { @@ -91,11 +100,12 @@ public class StoneSetTest { assertSet(INVALID, Arrays.asList(new Stone(4, BLUE), new Stone(5, RED), new Stone(6, RED))); // Regression test: - assertSet(INVALID, Arrays.asList(new Stone(12, ORANGE), - new Stone(12, BLACK), new Stone(7, BLUE))); + assertSet(INVALID, Arrays.asList(new Stone(12, ORANGE), new Stone(12, + BLACK), new Stone(7, BLUE))); } // invalid Split + /** */ @Test public void testSplitInvalidLow() { StoneSet testSet = createTestSet(); @@ -103,6 +113,7 @@ public class StoneSetTest { } + /** */ @Test public void testSplitInvalidHigh() { StoneSet testSet = createTestSet(); @@ -110,6 +121,7 @@ public class StoneSetTest { } // valid Split + /** */ @Test public void testSplitValid() { StoneSet testSet = createTestSet(); @@ -133,6 +145,7 @@ public class StoneSetTest { } // join + /** */ @Test public void testJoin() { StoneSet testSet = createTestSet(); @@ -148,6 +161,7 @@ public class StoneSetTest { } // iterator + /** */ @Test public void testIterator() { StoneSet testSet = createTestSet(); diff --git a/test/jrummikub/model/StoneTrayTest.java b/test/jrummikub/model/StoneTrayTest.java index 1c8b241..84fc799 100644 --- a/test/jrummikub/model/StoneTrayTest.java +++ b/test/jrummikub/model/StoneTrayTest.java @@ -7,7 +7,9 @@ import jrummikub.util.Pair; import org.junit.*; import static org.junit.Assert.*; - +/** + * Tests for {@link StoneTray} + */ public class StoneTrayTest { class Thing implements Sizeable { private float width; @@ -30,12 +32,13 @@ public class StoneTrayTest { } private StoneTray<Thing> testTray; - + /** */ @Before public void createTray() { testTray = new StoneTray<Thing>(); } + /** */ @Test public void testDrop() { Thing firstThing = new Thing(3, 4); @@ -50,6 +53,7 @@ public class StoneTrayTest { assertEquals(8.5, secondPosition.getY(), 0.00001); } + /** */ @Test public void testDropNull() { testTray.drop(null, new Position(0, 0)); @@ -57,6 +61,7 @@ public class StoneTrayTest { } // Leftshift + /** */ @Test public void testLeftDrop() { Thing firstThing = new Thing(5, 5); @@ -72,6 +77,7 @@ public class StoneTrayTest { } // Rightshift + /** */ @Test public void testRightDrop() { Thing firstThing = new Thing(5, 5); @@ -87,6 +93,7 @@ public class StoneTrayTest { } // Upshift + /** */ @Test public void testUpDrop() { Thing firstThing = new Thing(5, 5); @@ -102,6 +109,7 @@ public class StoneTrayTest { } // Downshift + /** */ @Test public void testDownDrop() { Thing firstThing = new Thing(5, 5); @@ -116,6 +124,7 @@ public class StoneTrayTest { assertEquals(-2, secondPosition.getY(), 0.00001); } + /** */ @Test public void testDoubleShift() { Thing firstThing = new Thing(5, 5); @@ -137,6 +146,7 @@ public class StoneTrayTest { assertEquals(1, thirdPosition.getY(), 0.00001); } + /** */ @Test public void testWrongPickUp() { Thing firstThing = new Thing(5, 5); @@ -145,6 +155,7 @@ public class StoneTrayTest { assertNull(testTray.pickUp(testPosition)); } + /** */ @Test public void testPickUpByObject() { Thing firstThing = new Thing(5, 5); @@ -158,6 +169,7 @@ public class StoneTrayTest { assertTrue(testTray.iterator().hasNext()); } + /** */ @Test public void testRightPickUp() { Thing firstThing = new Thing(5, 5); @@ -169,6 +181,7 @@ public class StoneTrayTest { assertNull(testTray.pickUp(testPosition)); } + /** */ @Test public void testIterate() { List<Thing> testThings = new ArrayList<Thing>(); @@ -191,6 +204,7 @@ public class StoneTrayTest { assertTrue(testPositions.isEmpty()); } + /** */ @Test public void testClone() { Thing firstThing = new Thing(5, 5); diff --git a/test/jrummikub/model/TableTest.java b/test/jrummikub/model/TableTest.java index a806e14..0d53aed 100644 --- a/test/jrummikub/model/TableTest.java +++ b/test/jrummikub/model/TableTest.java @@ -12,22 +12,28 @@ import java.util.Arrays; import org.junit.Before; import org.junit.Test; +/** + * Tests for {@link Table} + */ public class TableTest { Table testTable; + /** */ @Before public void setup() { testTable = new Table(); } + /** */ @Test public void testIsValid() { testTable.drop( - new StoneSet(Arrays.asList(new Stone(RED), new Stone(BLACK), new Stone( - 1, BLACK))), new Position(0, 0)); + new StoneSet(Arrays.asList(new Stone(RED), new Stone(BLACK), + new Stone(1, BLACK))), new Position(0, 0)); testTable.drop( - new StoneSet(Arrays.asList(new Stone(1, RED), new Stone(2, RED), - new Stone(3, RED))), new Position(0, 0)); + new StoneSet(Arrays.asList(new Stone(1, RED), + new Stone(2, RED), new Stone(3, RED))), new Position(0, + 0)); assertTrue(testTable.isValid()); testTable.drop(new StoneSet(Arrays.asList(new Stone(5, RED))), @@ -35,18 +41,20 @@ public class TableTest { assertFalse(testTable.isValid()); } + /** */ @Test public void testEmptyIsValid() { assertTrue(testTable.isValid()); } + /** */ @Test @SuppressWarnings("unused") public void testPickUpStoneGroup() { Stone targetStone = new Stone(BLACK); testTable.drop( - new StoneSet(Arrays.asList(new Stone(RED), targetStone, new Stone(1, - BLACK))), new Position(0, 0)); + new StoneSet(Arrays.asList(new Stone(RED), targetStone, + new Stone(1, BLACK))), new Position(0, 0)); assertTrue(testTable.isValid()); testTable.pickUpStone(targetStone); assertFalse(testTable.isValid()); @@ -58,6 +66,7 @@ public class TableTest { assertEquals(1, counter); } + /** */ @Test public void testPickLonelyStone() { Stone targetStone = new Stone(BLACK); @@ -66,6 +75,7 @@ public class TableTest { assertEquals(0, testTable.getSize()); } + /** */ @Test public void testPickStoneFromEmptyTable() { Stone targetStone = new Stone(BLACK); @@ -73,6 +83,7 @@ public class TableTest { assertEquals(0, testTable.getSize()); } + /** */ @Test public void testPickNonexistentStone() { Stone targetStone = new Stone(BLACK); @@ -84,13 +95,14 @@ public class TableTest { assertSame(testTable.findStoneSet(droppedStone), set); } + /** */ @Test @SuppressWarnings("unused") public void testPickUpStoneRun() { Stone targetStone = new Stone(BLACK); testTable.drop( - new StoneSet(Arrays.asList(new Stone(1, RED), targetStone, new Stone(3, - RED))), new Position(0, 0)); + new StoneSet(Arrays.asList(new Stone(1, RED), targetStone, + new Stone(3, RED))), new Position(0, 0)); assertTrue(testTable.isValid()); testTable.pickUpStone(targetStone); assertFalse(testTable.isValid()); @@ -102,6 +114,7 @@ public class TableTest { assertEquals(2, counter); } + /** */ @Test public void testFindSet() { Stone targetStone = new Stone(BLACK); diff --git a/test/jrummikub/util/Event1Test.java b/test/jrummikub/util/Event1Test.java index c3f388e..6d61882 100644 --- a/test/jrummikub/util/Event1Test.java +++ b/test/jrummikub/util/Event1Test.java @@ -4,105 +4,112 @@ import static org.junit.Assert.*; import org.junit.Test; +/** + * Test class for {@link Event1} + */ public class Event1Test { - int fired, fired2; - - @Test - public void singleListener() { - fired = 0; - Event1<Integer> testEvent = new Event1<Integer>(); - testEvent.add(new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fired += n; - - } - }); - assertEquals(fired, 0); - testEvent.emit(10); - assertEquals(fired, 10); - testEvent.emit(20); - assertEquals(fired, 30); - } - - @Test - public void twoListeners() { - fired = 0; - fired2 = 0; - Event1<Integer> testEvent = new Event1<Integer>(); - testEvent.add(new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fired += n; - - } - }); - testEvent.add(new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fired2 -= n; - - } - }); - assertEquals(fired, 0); - assertEquals(fired2, 0); - testEvent.emit(5); - assertEquals(fired, 5); - assertEquals(fired2, -5); - - } - - @Test - public void removeListener() { - fired = 0; - Event1<Integer> testEvent = new Event1<Integer>(); - testEvent.add(new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fired += n; - - } - }); - IListener1<Integer> rem = new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fail(); - } - }; - testEvent.add(rem); - testEvent.remove(rem); - testEvent.emit(10); - assertEquals(fired, 10); - } - - @Test - public void removeListenerByConnection() { - fired = 0; - Event1<Integer> testEvent = new Event1<Integer>(); - testEvent.add(new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fired += n; - - } - }); - IListener1<Integer> rem = new IListener1<Integer>() { - - @Override - public void handle(Integer n) { - fail(); - } - }; - Connection connection = testEvent.add(rem); - connection.remove(); - testEvent.emit(10); - assertEquals(fired, 10); - } + int fired, fired2; + + /** */ + @Test + public void singleListener() { + fired = 0; + Event1<Integer> testEvent = new Event1<Integer>(); + testEvent.add(new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fired += n; + + } + }); + assertEquals(fired, 0); + testEvent.emit(10); + assertEquals(fired, 10); + testEvent.emit(20); + assertEquals(fired, 30); + } + + /** */ + @Test + public void twoListeners() { + fired = 0; + fired2 = 0; + Event1<Integer> testEvent = new Event1<Integer>(); + testEvent.add(new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fired += n; + + } + }); + testEvent.add(new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fired2 -= n; + + } + }); + assertEquals(fired, 0); + assertEquals(fired2, 0); + testEvent.emit(5); + assertEquals(fired, 5); + assertEquals(fired2, -5); + + } + + /** */ + @Test + public void removeListener() { + fired = 0; + Event1<Integer> testEvent = new Event1<Integer>(); + testEvent.add(new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fired += n; + + } + }); + IListener1<Integer> rem = new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fail(); + } + }; + testEvent.add(rem); + testEvent.remove(rem); + testEvent.emit(10); + assertEquals(fired, 10); + } + + /** */ + @Test + public void removeListenerByConnection() { + fired = 0; + Event1<Integer> testEvent = new Event1<Integer>(); + testEvent.add(new IListener1<Integer>() { + + @Override + public void handle(Integer n) { + fired += n; + + } + }); + IListener1<Integer> rem = new IListener1<Integer>() { + + @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 c258ddf..4298729 100644 --- a/test/jrummikub/util/Event2Test.java +++ b/test/jrummikub/util/Event2Test.java @@ -4,122 +4,129 @@ import static org.junit.Assert.*; import org.junit.Test; +/** + * Test class for {@link Event2} + */ public class Event2Test { - int fired, fired2, fired3, fired4; + 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>() { + /** */ + @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 handle(Integer n, Integer m) { - fired += n; - fired2 += m; - } - }); - assertEquals(fired, 0); - assertEquals(fired2, 0); - testEvent.emit(10, 5); - assertEquals(fired, 10); - assertEquals(fired2, 5); - testEvent.emit(20, 45); - assertEquals(fired, 30); - assertEquals(fired2, 50); - } + @Override + public void handle(Integer n, Integer m) { + fired += n; + fired2 += m; + } + }); + assertEquals(fired, 0); + assertEquals(fired2, 0); + testEvent.emit(10, 5); + assertEquals(fired, 10); + assertEquals(fired2, 5); + testEvent.emit(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>() { + /** */ + @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 handle(Integer n, Integer m) { - fired += n; - fired2 += m; - } - }); - testEvent.add(new IListener2<Integer, Integer>() { + @Override + public void handle(Integer n, Integer m) { + fired += n; + fired2 += m; + } + }); + testEvent.add(new IListener2<Integer, Integer>() { - @Override - public void handle(Integer n, Integer m) { - fired3 -= n; - fired4 -= m; - } - }); - assertEquals(fired, 0); - assertEquals(fired2, 0); - assertEquals(fired3, 0); - assertEquals(fired4, 0); - testEvent.emit(5, 10); - assertEquals(fired, 5); - assertEquals(fired2, 10); - assertEquals(fired3, -5); - assertEquals(fired4, -10); - } + @Override + public void handle(Integer n, Integer m) { + fired3 -= n; + fired4 -= m; + } + }); + assertEquals(fired, 0); + assertEquals(fired2, 0); + assertEquals(fired3, 0); + assertEquals(fired4, 0); + testEvent.emit(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>() { + /** */ + @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 handle(Integer n, Integer m) { - fired += n; - fired2 += m; - } - }); - IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() { + @Override + public void handle(Integer n, Integer m) { + fired += n; + fired2 += m; + } + }); + IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() { - @Override - public void handle(Integer n, Integer m) { - fail(); - } - }; - assertEquals(fired, 0); - assertEquals(fired2, 0); - testEvent.add(rem); - testEvent.remove(rem); - testEvent.emit(10, 20); - assertEquals(fired, 10); - assertEquals(fired2, 20); - } - - @Test - public void removeListenerByConnection() { - fired = 0; - fired2 = 0; - Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>(); - testEvent.add(new IListener2<Integer, Integer>() { + @Override + public void handle(Integer n, Integer m) { + fail(); + } + }; + assertEquals(fired, 0); + assertEquals(fired2, 0); + testEvent.add(rem); + testEvent.remove(rem); + testEvent.emit(10, 20); + assertEquals(fired, 10); + assertEquals(fired2, 20); + } - @Override - public void handle(Integer n, Integer m) { - fired += n; - fired2 += m; - } - }); - IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() { + /** */ + @Test + public void removeListenerByConnection() { + fired = 0; + fired2 = 0; + Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>(); + testEvent.add(new IListener2<Integer, Integer>() { - @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); - } + @Override + public void handle(Integer n, Integer m) { + fired += n; + fired2 += m; + } + }); + IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() { + + @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 f8c505c..de2e4e6 100644 --- a/test/jrummikub/util/EventTest.java +++ b/test/jrummikub/util/EventTest.java @@ -2,10 +2,13 @@ package jrummikub.util; import org.junit.Test; import static org.junit.Assert.*; - +/** + * Test class for {@link Event} + */ public class EventTest { boolean fired, fired2; + /** */ @Test public void singleListener() { fired = false; @@ -26,6 +29,7 @@ public class EventTest { assertTrue(fired); } + /** */ @Test public void twoListeners() { fired = false; @@ -55,6 +59,7 @@ public class EventTest { } + /** */ @Test public void removeListener() { fired = false; @@ -80,6 +85,7 @@ public class EventTest { assertTrue(fired); } + /** */ @Test public void removeListenerByConnection() { fired = false; |