From 3b49b2053e9f9d26b73db0ffc8380a60706ee095 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Tue, 10 May 2011 03:54:48 +0200 Subject: Added all missing comments git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@213 72836036-5685-4462-b002-a69064685172 --- mock/jrummikub/model/MockGameState.java | 9 + mock/jrummikub/model/MockHand.java | 10 +- mock/jrummikub/model/MockPlayer.java | 13 +- mock/jrummikub/model/MockTable.java | 8 +- mock/jrummikub/util/MockEvent.java | 8 +- mock/jrummikub/util/MockEvent1.java | 14 +- mock/jrummikub/util/MockEvent2.java | 17 +- mock/jrummikub/view/MockHandPanel.java | 8 +- mock/jrummikub/view/MockPlayerPanel.java | 7 + mock/jrummikub/view/MockStoneCollectionPanel.java | 10 +- mock/jrummikub/view/MockTablePanel.java | 14 ++ mock/jrummikub/view/MockView.java | 13 +- src/jrummikub/control/ITurnTimer.java | 14 ++ src/jrummikub/control/RoundControl.java | 14 ++ src/jrummikub/control/TurnControl.java | 22 +++ src/jrummikub/control/TurnTimer.java | 12 +- src/jrummikub/model/GameState.java | 4 +- src/jrummikub/model/IGameState.java | 36 ++++ src/jrummikub/model/IHand.java | 3 + src/jrummikub/model/IPlayer.java | 18 ++ src/jrummikub/model/IStoneTray.java | 31 ++- src/jrummikub/model/ITable.java | 16 +- src/jrummikub/model/Player.java | 10 +- src/jrummikub/model/StoneColor.java | 9 +- src/jrummikub/model/StoneHeap.java | 13 +- src/jrummikub/model/StoneSet.java | 41 +++- src/jrummikub/view/IHandPanel.java | 12 ++ test/jrummikub/control/RoundControlTest.java | 17 +- test/jrummikub/control/TurnControlTest.java | 37 +++- test/jrummikub/model/GameStateTest.java | 6 +- test/jrummikub/model/HandTest.java | 12 +- test/jrummikub/model/StoneHeapTest.java | 20 +- test/jrummikub/model/StoneSetTest.java | 34 +++- test/jrummikub/model/StoneTrayTest.java | 18 +- test/jrummikub/model/TableTest.java | 29 ++- test/jrummikub/util/Event1Test.java | 205 ++++++++++---------- test/jrummikub/util/Event2Test.java | 219 +++++++++++----------- test/jrummikub/util/EventTest.java | 8 +- 38 files changed, 712 insertions(+), 279 deletions(-) diff --git a/mock/jrummikub/model/MockGameState.java b/mock/jrummikub/model/MockGameState.java index 377bd1d..53e332e 100644 --- a/mock/jrummikub/model/MockGameState.java +++ b/mock/jrummikub/model/MockGameState.java @@ -4,13 +4,22 @@ import java.awt.Color; import java.util.ArrayList; import java.util.List; +/** + * Mock class for {@link GameState} + */ public class MockGameState implements IGameState { + /** */ public MockTable table; + /** */ public ITable setTable; + /** */ public List players; + /** */ public int activePlayer; + /** */ public StoneHeap gameHeap; + /** */ public MockGameState() { table = new MockTable(); players = new ArrayList(); diff --git a/mock/jrummikub/model/MockHand.java b/mock/jrummikub/model/MockHand.java index f8388d0..dc348c0 100644 --- a/mock/jrummikub/model/MockHand.java +++ b/mock/jrummikub/model/MockHand.java @@ -7,13 +7,15 @@ import java.util.List; import java.util.Set; import jrummikub.util.Pair; - +/** + * Mock class for {@link Hand} + */ public class MockHand implements IHand { - + /** */ public List> stones = new ArrayList>(); - + /** */ public Set pickups = new HashSet(); - + /** */ public Iterable> iterable; @Override diff --git a/mock/jrummikub/model/MockPlayer.java b/mock/jrummikub/model/MockPlayer.java index 2f573ca..a9fbd80 100644 --- a/mock/jrummikub/model/MockPlayer.java +++ b/mock/jrummikub/model/MockPlayer.java @@ -2,14 +2,21 @@ package jrummikub.model; import java.awt.Color; +/** + * Mock class for {@link Player} + */ public class MockPlayer implements IPlayer { - + /** */ public MockHand hand; + /** */ public String name; + /** */ public Color color; - // private String name; - + /** + * @param name + * @param color + */ public MockPlayer(String name, Color color) { hand = new MockHand(); this.name = name; diff --git a/mock/jrummikub/model/MockTable.java b/mock/jrummikub/model/MockTable.java index f17e5df..0ff041e 100644 --- a/mock/jrummikub/model/MockTable.java +++ b/mock/jrummikub/model/MockTable.java @@ -7,11 +7,17 @@ import java.util.List; import java.util.Map; import jrummikub.util.Pair; - +/** + * Mock class for {@link Table} + */ public class MockTable implements ITable { + /** */ public Map findStoneSet = new HashMap(); + /** */ public boolean valid = false; + /** */ public MockTable clonedTable; + /** */ public List> sets = new ArrayList>(); @Override diff --git a/mock/jrummikub/util/MockEvent.java b/mock/jrummikub/util/MockEvent.java index 65aec9d..3d4c56a 100644 --- a/mock/jrummikub/util/MockEvent.java +++ b/mock/jrummikub/util/MockEvent.java @@ -1,8 +1,11 @@ package jrummikub.util; import java.util.HashSet; - +/** + * Mock class for Events + */ public class MockEvent implements IEvent { + /** */ public HashSet listeners = new HashSet(); @Override @@ -21,7 +24,8 @@ public class MockEvent implements IEvent { public void remove(IListener listener) { listeners.remove(listener); } - + + /** */ public void emit() { for (IListener listener : listeners) { listener.handle(); diff --git a/mock/jrummikub/util/MockEvent1.java b/mock/jrummikub/util/MockEvent1.java index 94b0257..7b44c88 100644 --- a/mock/jrummikub/util/MockEvent1.java +++ b/mock/jrummikub/util/MockEvent1.java @@ -2,14 +2,21 @@ package jrummikub.util; import java.util.HashSet; +/** + * Mock class for Event1s + * + * @param + * event type + */ public class MockEvent1 implements IEvent1 { + /** */ public HashSet> listeners = new HashSet>(); @Override public Connection add(final IListener1 listener) { listeners.add(listener); - return new Connection() { - + return new Connection() { + @Override public void remove() { MockEvent1.this.remove(listener); @@ -22,6 +29,9 @@ public class MockEvent1 implements IEvent1 { listeners.remove(listener); } + /** + * @param value + */ public void emit(T value) { for (IListener1 listener : listeners) { listener.handle(value); diff --git a/mock/jrummikub/util/MockEvent2.java b/mock/jrummikub/util/MockEvent2.java index 5aa7b59..38c9686 100644 --- a/mock/jrummikub/util/MockEvent2.java +++ b/mock/jrummikub/util/MockEvent2.java @@ -2,14 +2,23 @@ package jrummikub.util; import java.util.HashSet; +/** + * Mock class for Event2s + * + * @param + * first event type + * @param + * second event type + */ public class MockEvent2 implements IEvent2 { + /** */ public HashSet> listeners = new HashSet>(); @Override public Connection add(final IListener2 listener) { listeners.add(listener); - return new Connection() { - + return new Connection() { + @Override public void remove() { MockEvent2.this.remove(listener); @@ -22,6 +31,10 @@ public class MockEvent2 implements IEvent2 { listeners.remove(listener); } + /** + * @param value1 + * @param value2 + */ public void emit(T1 value1, T2 value2) { for (IListener2 listener : listeners) { listener.handle(value1, value2); diff --git a/mock/jrummikub/view/MockHandPanel.java b/mock/jrummikub/view/MockHandPanel.java index cb97ef7..299d50a 100644 --- a/mock/jrummikub/view/MockHandPanel.java +++ b/mock/jrummikub/view/MockHandPanel.java @@ -10,11 +10,17 @@ import jrummikub.util.Event2; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; import jrummikub.util.Pair; - +/** + * Mock class for HandPanel + */ public class MockHandPanel implements IHandPanel { + /** */ public Event2 stoneClickEvent = new Event2(); + /** */ public List> stones; + /** */ public Event2 rangeClickEvent = new Event2(); + /** */ public Event1 clickEvent = new Event1(); @Override diff --git a/mock/jrummikub/view/MockPlayerPanel.java b/mock/jrummikub/view/MockPlayerPanel.java index 8103c7e..f193fa1 100644 --- a/mock/jrummikub/view/MockPlayerPanel.java +++ b/mock/jrummikub/view/MockPlayerPanel.java @@ -3,10 +3,17 @@ package jrummikub.view; import jrummikub.util.IEvent; import jrummikub.util.MockEvent; +/** + * Mock class for PlayerPanel + */ public class MockPlayerPanel implements IPlayerPanel { + /** */ public MockEvent endTurnEvent = new MockEvent(); + /** */ public MockHandPanel handPanel = new MockHandPanel(); + /** */ public MockEvent sortByGroupsEvent = new MockEvent(); + /** */ public MockEvent sortByRunsEvent = new MockEvent(); @Override diff --git a/mock/jrummikub/view/MockStoneCollectionPanel.java b/mock/jrummikub/view/MockStoneCollectionPanel.java index 70016e5..66eccaa 100644 --- a/mock/jrummikub/view/MockStoneCollectionPanel.java +++ b/mock/jrummikub/view/MockStoneCollectionPanel.java @@ -4,10 +4,14 @@ import jrummikub.model.Stone; import jrummikub.util.Event2; import jrummikub.util.IEvent2; +/** + * Mock class for StoneCollectionPanel + */ public class MockStoneCollectionPanel implements IStoneCollectionPanel { - - public Event2 stoneClickEvent = new Event2(); - public Event2 setClickEvent = new Event2(); + /** */ + public Event2 stoneClickEvent = new Event2(); + /** */ + public Event2 setClickEvent = new Event2(); @Override public IEvent2 getStoneClickEvent() { diff --git a/mock/jrummikub/view/MockTablePanel.java b/mock/jrummikub/view/MockTablePanel.java index 792b2e7..ca3db6e 100644 --- a/mock/jrummikub/view/MockTablePanel.java +++ b/mock/jrummikub/view/MockTablePanel.java @@ -9,20 +9,34 @@ import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; import jrummikub.util.Pair; +/** + * Mock class for TablePanel + */ public class MockTablePanel implements ITablePanel { + /** */ public Event2 stoneClickEvent = new Event2(); + /** */ public Event2 setClickEvent = new Event2(); + /** */ public Event2 rangeClickEvent = new Event2(); + /** */ public Event1 clickEvent = new Event1(); + /** */ public Event1 leftConnectorClickEvent = new Event1(); + /** */ public Event1 rightConnectorClickEvent = new Event1(); + /** */ public MockStoneCollectionPanel stoneCollectionPanel = new MockStoneCollectionPanel(); + /** */ public String leftPlayerName; + /** */ public String topPlayerName; + /** */ public String rightPlayerName; + /** */ public Iterable> stoneSets; @Override diff --git a/mock/jrummikub/view/MockView.java b/mock/jrummikub/view/MockView.java index 44b6a78..f0337f3 100644 --- a/mock/jrummikub/view/MockView.java +++ b/mock/jrummikub/view/MockView.java @@ -5,19 +5,30 @@ import java.util.Collection; import jrummikub.model.Stone; import jrummikub.util.IEvent; import jrummikub.util.MockEvent; - +/** + * Mock class for View + */ public class MockView implements IView { + /** */ public MockPlayerPanel playerPanel = new MockPlayerPanel(); + /** */ public MockTablePanel tablePanel = new MockTablePanel(); + /** */ public Collection selectedStones; + /** */ public String currentPlayerName; + /** */ public boolean displayStartTurnPanel = false; + /** */ public boolean displayWinPanel = false; + /** */ public MockEvent startTurnEvent = new MockEvent(); + /** */ public MockEvent quitEvent = new MockEvent(); + /** */ public MockEvent newGameEvent = new MockEvent(); @Override diff --git a/src/jrummikub/control/ITurnTimer.java b/src/jrummikub/control/ITurnTimer.java index 54f00b5..175d95f 100644 --- a/src/jrummikub/control/ITurnTimer.java +++ b/src/jrummikub/control/ITurnTimer.java @@ -2,12 +2,26 @@ package jrummikub.control; import jrummikub.util.IEvent; +/** + * Interface for the {@link TurnTimer} + */ public interface ITurnTimer { + /** + * Starts the timer + */ public abstract void startTimer(); + /** + * Stops the timer. Stopping an already stopped timer is a no-op. + */ public abstract void stopTimer(); + /** + * Returns the event that is emitted if the timer timed out. + * + * @return time out event + */ public abstract IEvent getTimeRunOutEvent(); } \ No newline at end of file diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index 490873a..fc27f9b 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -18,6 +18,9 @@ import jrummikub.util.IListener; import jrummikub.util.Pair; import jrummikub.view.IView; +/** + * Controller that manages a single round of rummikub + */ public class RoundControl { private IGameState gameState; private IView view; @@ -25,6 +28,14 @@ public class RoundControl { private Event endRoundEvent = new Event(); private List connections = new ArrayList(); + /** + * Create a new RoundControl using the given gameState and view + * + * @param gameState + * initial game state + * @param view + * view used for user interaction + */ public RoundControl(IGameState gameState, IView view) { this.gameState = gameState; this.view = view; @@ -34,6 +45,9 @@ public class RoundControl { return endRoundEvent; } + /** + * Begin the round + */ public void startRound() { deal(); diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java index 32e6379..ace201e 100644 --- a/src/jrummikub/control/TurnControl.java +++ b/src/jrummikub/control/TurnControl.java @@ -21,6 +21,9 @@ import jrummikub.util.IListener2; import jrummikub.util.Pair; import jrummikub.view.IView; +/** + * Controller for a single turn made by a human player + */ public class TurnControl { private IHand hand; private ITable table; @@ -32,6 +35,17 @@ public class TurnControl { private Event endOfTurnEvent = new Event(); private List connections = new ArrayList(); + /** + * Create a new TurnControl using a given hand (of the active player), a + * given table and a given view for user interaction. + * + * @param hand + * active player's hand + * @param table + * current table + * @param view + * view for user interaction. + */ public TurnControl(IHand hand, ITable table, IView view) { this.hand = hand; this.table = table; @@ -47,6 +61,9 @@ public class TurnControl { this.timer = testTimer; } + /** + * Start the turn + */ public void startTurn() { IListener endOfTurnListener = new IListener() { @@ -408,6 +425,11 @@ public class TurnControl { view.setSelectedStones(new ArrayList()); } + /** + * Get the event that is emitted when the turn is over + * + * @return end of turn event + */ public IEvent getEndOfTurnEvent() { return endOfTurnEvent; } diff --git a/src/jrummikub/control/TurnTimer.java b/src/jrummikub/control/TurnTimer.java index 789bf1a..17bdf0f 100644 --- a/src/jrummikub/control/TurnTimer.java +++ b/src/jrummikub/control/TurnTimer.java @@ -9,12 +9,21 @@ import jrummikub.util.Event; import jrummikub.util.IEvent; import jrummikub.view.IView; +/** + * Count-down timer used to limit the turn time + */ public class TurnTimer implements ActionListener, ITurnTimer { private IView view; private int timeLeft = 60; private Timer timer; private Event timeRunOutEvent = new Event(); + /** + * Create a new timer using a given view to display the current time left + * + * @param view + * view to display + */ public TurnTimer(IView view) { this.view = view; timer = new Timer(1000, this); @@ -23,19 +32,16 @@ public class TurnTimer implements ActionListener, ITurnTimer { view.getPlayerPanel().setTimeLeft(timeLeft); } - @Override public void startTimer() { timer.start(); } - @Override public void stopTimer() { timer.stop(); } - @Override public void actionPerformed(ActionEvent arg0) { timeLeft--; diff --git a/src/jrummikub/model/GameState.java b/src/jrummikub/model/GameState.java index 6f1bad3..69c5570 100644 --- a/src/jrummikub/model/GameState.java +++ b/src/jrummikub/model/GameState.java @@ -11,6 +11,9 @@ public class GameState implements IGameState { private int activePlayer; private StoneHeap gameHeap; + /** + * Create a new GameState with an empty table and (currntly) 4 new players. + */ public GameState() { table = new Table(); players = new ArrayList(); @@ -37,7 +40,6 @@ public class GameState implements IGameState { return players.size(); } - /** Changes the activePlayer to the next {@link Player} in the list */ @Override public void nextPlayer() { activePlayer = (activePlayer + 1) % players.size(); diff --git a/src/jrummikub/model/IGameState.java b/src/jrummikub/model/IGameState.java index 8e64bc4..ebc31c5 100644 --- a/src/jrummikub/model/IGameState.java +++ b/src/jrummikub/model/IGameState.java @@ -1,20 +1,56 @@ package jrummikub.model; +/** + * Interface for {@link GameState} model + */ public interface IGameState { + /** + * Get the current {@link Table} + * + * @return The current Table + */ public ITable getTable(); + /** + * Sets the current {@link Table} + * + * @param table + * The new Table + */ public void setTable(ITable table); + /** + * Returns the number of players + * + * @return number of players + */ public int getPlayerCount(); /** Changes the activePlayer to the next {@link Player} in the list */ public void nextPlayer(); + /** + * Returns the currently active player + * + * @return currently active player + */ public IPlayer getActivePlayer(); + /** + * Returns the heap of stones to draw from + * + * @return heap of stones + */ public StoneHeap getGameHeap(); + /** + * Returns the player that would be the active player after i turns + * + * @param i + * number of turns + * @return player active after i turns + */ public IPlayer getNthNextPlayer(int i); } \ No newline at end of file diff --git a/src/jrummikub/model/IHand.java b/src/jrummikub/model/IHand.java index 8bc7e7f..f5234d1 100644 --- a/src/jrummikub/model/IHand.java +++ b/src/jrummikub/model/IHand.java @@ -1,5 +1,8 @@ package jrummikub.model; +/** + * Interface for the {@link Hand} model + */ public interface IHand extends IStoneTray { } diff --git a/src/jrummikub/model/IPlayer.java b/src/jrummikub/model/IPlayer.java index 17e37e7..3eca44b 100644 --- a/src/jrummikub/model/IPlayer.java +++ b/src/jrummikub/model/IPlayer.java @@ -2,12 +2,30 @@ package jrummikub.model; import java.awt.Color; +/** + * Interface for {@link Player} model + */ public interface IPlayer { + /** + * Get the current hand of the player + * + * @return the player's hand + */ public IHand getHand(); + /** + * Return the player's color + * + * @return the player's color + */ public Color getColor(); + /** + * Return the name of the player + * + * @return the player's name + */ public String getName(); } \ No newline at end of file diff --git a/src/jrummikub/model/IStoneTray.java b/src/jrummikub/model/IStoneTray.java index 11fcbbb..c1ed05d 100644 --- a/src/jrummikub/model/IStoneTray.java +++ b/src/jrummikub/model/IStoneTray.java @@ -2,6 +2,12 @@ package jrummikub.model; import jrummikub.util.Pair; +/** + * Interface for the {@link StoneTray} model + * + * @param + * Objects held by the IStoneTray + */ public interface IStoneTray extends Iterable>, Cloneable { @@ -9,7 +15,7 @@ public interface IStoneTray extends * Removes object from tray and returns it * * @param position - * position of the object that will be removed + * position of the object that will be removed * @return the picked up stone */ public E pickUp(Position position); @@ -18,9 +24,9 @@ public interface IStoneTray extends * Adds object to the tray * * @param object - * object to add to Hand + * object to add to Hand * @param position - * {@link Position} to put the object + * {@link Position} to put the object */ public void drop(E object, Position position); @@ -28,15 +34,32 @@ public interface IStoneTray extends * Returns the position of an object that is already on the tray * * @param object - * object whose position is requested + * object whose position is requested * @return position of the object or null when the object is not on the tray */ public Position getPosition(E object); + /** + * Tries to pick up (remove) a given object + * + * @param object + * object to pick up + * @return true when the object was successfully removed + */ public boolean pickUp(E object); + /** + * Create a clone of the StoneTray + * + * @return cloned StoneTray + */ public IStoneTray clone(); + /** + * Return the number of objects on the tray + * + * @return number of objects + */ public int getSize(); } \ No newline at end of file diff --git a/src/jrummikub/model/ITable.java b/src/jrummikub/model/ITable.java index 1c3fd9f..3b0032f 100644 --- a/src/jrummikub/model/ITable.java +++ b/src/jrummikub/model/ITable.java @@ -2,20 +2,32 @@ package jrummikub.model; import jrummikub.util.Pair; +/** + * Interface for the {@link Table} model + */ public interface ITable extends IStoneTray { /** * Removes {@link Stone} from the Table * * @param stone - * stone to pick up + * stone to pick up * @return the stone sets that are created by taking pickung the the stone */ public Pair pickUpStone(Stone stone); - /** Tests the Table for rule conflicts by checking all the {@link StoneSet} */ + /** + * Tests the Table for rule conflicts by checking all the {@link StoneSet} + * + * @return whether all sets on the table are valid + */ public boolean isValid(); + /** + * Finds the {@link StoneSet} containing the given {@link Stone} + * @param stone stone whose set we're searching + * @return the set containing the stone or null if no set was found + */ StoneSet findStoneSet(Stone stone); } \ No newline at end of file diff --git a/src/jrummikub/model/Player.java b/src/jrummikub/model/Player.java index 623915d..ddd10e4 100644 --- a/src/jrummikub/model/Player.java +++ b/src/jrummikub/model/Player.java @@ -9,8 +9,14 @@ public class Player implements IPlayer { private String name; private Color color; - // private String name; - + /** + * Create a new player with a given name and color + * + * @param name + * player name + * @param color + * player's color + */ public Player(String name, Color color) { hand = new Hand(); this.name = name; diff --git a/src/jrummikub/model/StoneColor.java b/src/jrummikub/model/StoneColor.java index 23f66a0..6b1807b 100644 --- a/src/jrummikub/model/StoneColor.java +++ b/src/jrummikub/model/StoneColor.java @@ -2,5 +2,12 @@ package jrummikub.model; /** Class specifying possible StoneColors */ public enum StoneColor { - BLACK, ORANGE, BLUE, RED + /** */ + BLACK, + /** */ + ORANGE, + /** */ + BLUE, + /** */ + RED } diff --git a/src/jrummikub/model/StoneHeap.java b/src/jrummikub/model/StoneHeap.java index ae84cef..d9d754f 100644 --- a/src/jrummikub/model/StoneHeap.java +++ b/src/jrummikub/model/StoneHeap.java @@ -43,7 +43,7 @@ public class StoneHeap { * Removes several {@link Stone}s from the heap and returns them * * @param number - * number of requested Stones + * number of requested Stones * @return list of drawn stones */ public List drawStones(int number) { @@ -54,10 +54,21 @@ public class StoneHeap { return drawnStones; } + /** + * Get the number of stones left + * + * @return number of stones on the heap + */ public int getSize() { return heap.size(); } + /** + * Put stones back on the heap + * + * @param stones + * collection of stones to put back + */ public void putBack(Collection stones) { heap.addAll(stones); } diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index 3723e75..83ce767 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -18,16 +18,34 @@ public class StoneSet implements Iterable, Sizeable { static final float HORIZONTAL_BORDER = 0.125f; private List stones; + /** + * Create a new single stone stone set + * + * @param stone + * single stone of the set + */ public StoneSet(Stone stone) { stones = Collections.singletonList(stone); } + /** + * Create a stone set from a list of stones + * + * @param stones + * list of stones to build a set of + */ public StoneSet(List stones) { this.stones = new ArrayList(stones); } + /** Validity type of the set */ public enum Type { - GROUP, RUN, INVALID + /** Set is a valid group */ + GROUP, + /** Set is a valid run */ + RUN, + /** Set is invalid */ + INVALID } /** @@ -40,8 +58,8 @@ public class StoneSet implements Iterable, Sizeable { } /** - * Test for rule conflict within the StoneSet and determine whether the set is - * a group or a run + * Test for rule conflict within the StoneSet and determine whether the set + * is a group or a run * * @return GROUP or RUN for valid sets, INVALID otherwise */ @@ -62,13 +80,15 @@ public class StoneSet implements Iterable, Sizeable { return GROUP; } // is run - if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2).getColor()) { + if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2) + .getColor()) { return isValidRun(nonJoker1) ? RUN : INVALID; } // is group else { - return isValidGroup(stones.get(nonJoker1).getValue()) ? GROUP : INVALID; + return isValidGroup(stones.get(nonJoker1).getValue()) ? GROUP + : INVALID; } } @@ -76,7 +96,7 @@ public class StoneSet implements Iterable, Sizeable { * Test for rule conflict within the StoneSet, assuming we have a run * * @param referencePosition - * position of stone used as reference (any non-joker stone) + * position of stone used as reference (any non-joker stone) */ private boolean isValidRun(int referencePosition) { StoneColor runColor = stones.get(referencePosition).getColor(); @@ -130,7 +150,7 @@ public class StoneSet implements Iterable, Sizeable { * Stone Sets * * @param position - * Splitting {@link Position} + * Splitting {@link Position} * @return A pair of StoneSets, one for each split part */ public Pair splitAt(int position) { @@ -140,7 +160,8 @@ public class StoneSet implements Iterable, Sizeable { return new Pair(this, null); } StoneSet firstSet = new StoneSet(stones.subList(0, position)); - StoneSet secondSet = new StoneSet(stones.subList(position, stones.size())); + StoneSet secondSet = new StoneSet(stones.subList(position, + stones.size())); return new Pair(firstSet, secondSet); } @@ -148,7 +169,7 @@ public class StoneSet implements Iterable, Sizeable { * Joins StoneSet to another StoneSet and returns the resulting new StoneSet * * @param other - * StoneSet to be joined to active StoneSet + * StoneSet to be joined to active StoneSet * @return the combined StoneSet */ public StoneSet join(StoneSet other) { @@ -171,7 +192,7 @@ public class StoneSet implements Iterable, Sizeable { * Returns the i-th stone of the set (starting with 0) * * @param i - * number of the stone to return + * number of the stone to return * @return the i-th stone */ public Stone get(int i) { diff --git a/src/jrummikub/view/IHandPanel.java b/src/jrummikub/view/IHandPanel.java index 3436062..3a76780 100644 --- a/src/jrummikub/view/IHandPanel.java +++ b/src/jrummikub/view/IHandPanel.java @@ -16,7 +16,19 @@ public interface IHandPanel extends IStonePanel, IClickable { */ public void setStones(Iterable> stones); + /** + * Set the number of stones that fit on the hand horizontally + * + * @param width + * number of stones + */ public void setHandWidth(int width); + /** + * Set the number of stones that fit on the hand vertically + * + * @param height + * number of stones + */ public void setHandHeight(int height); } 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()); } + /** */ @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()); } + /** */ @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 counters = new HashMap(); @@ -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 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 stones) { + private void assertSet(StoneSet.Type expectedType, List 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 testTray; - + /** */ @Before public void createTray() { testTray = new StoneTray(); } + /** */ @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 testThings = new ArrayList(); @@ -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 testEvent = new Event1(); - testEvent.add(new IListener1() { - - @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 testEvent = new Event1(); - testEvent.add(new IListener1() { - - @Override - public void handle(Integer n) { - fired += n; - - } - }); - testEvent.add(new IListener1() { - - @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 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(); - } - }; - testEvent.add(rem); - testEvent.remove(rem); - 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); - } + int fired, fired2; + + /** */ + @Test + public void singleListener() { + fired = 0; + Event1 testEvent = new Event1(); + testEvent.add(new IListener1() { + + @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 testEvent = new Event1(); + testEvent.add(new IListener1() { + + @Override + public void handle(Integer n) { + fired += n; + + } + }); + testEvent.add(new IListener1() { + + @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 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(); + } + }; + testEvent.add(rem); + testEvent.remove(rem); + 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 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 testEvent = new Event2(); - testEvent.add(new IListener2() { + /** */ + @Test + public void singleListener() { + fired = 0; + fired2 = 0; + Event2 testEvent = new Event2(); + testEvent.add(new IListener2() { - @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 testEvent = new Event2(); - testEvent.add(new IListener2() { + /** */ + @Test + public void twoListeners() { + fired = 0; + fired2 = 0; + fired3 = 0; + fired4 = 0; + Event2 testEvent = new Event2(); + testEvent.add(new IListener2() { - @Override - public void handle(Integer n, Integer m) { - fired += n; - fired2 += m; - } - }); - testEvent.add(new IListener2() { + @Override + public void handle(Integer n, Integer m) { + fired += n; + fired2 += m; + } + }); + testEvent.add(new IListener2() { - @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 testEvent = new Event2(); - testEvent.add(new IListener2() { + /** */ + @Test + public void removeListener() { + 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) { + fired += n; + fired2 += m; + } + }); + IListener2 rem = new IListener2() { - @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 testEvent = new Event2(); - testEvent.add(new IListener2() { + @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 rem = new IListener2() { + /** */ + @Test + public void removeListenerByConnection() { + fired = 0; + fired2 = 0; + Event2 testEvent = new Event2(); + testEvent.add(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); - } + @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 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; -- cgit v1.2.3