-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Box button not working after Star Pass (#78)
* Fix Box button not working after Star Pass When the skater changes positiosn from "Pivot" to "Jammer", the state is not correctly sync-ed between the PositionModel and the SkaterModel. At Jam end, the Jammer position's PenaltyBox status is cleared, but then not re-set based on the SkaterModel. This is now "fixed", but this PositionModel/SkaterModel nonsense is a mess, and in an ideal world I would just maintain the state on the SkaterModel and fire Position updates if the skater's status changes. I would be more comfortable making those changes once unit tests are in place though (#72). Closes #5 * add "unit" tests for DefaultPositionModel they aren't very unit-y, they depend rather heavily on the Team and Skater Models to work correctly, but I think this accomplishes good coverage of the Position interface. Added Mockito to avoid pulling in too much of the universe to do these tests. Near term plan (sometime in the few weeks) is to cook up a nice fixture to test the event system, add Tests for Skater and Team models, then start teasing apart the interweaving of the Team, Skater and Position models. * fix some issues with ant build with new tests
- Loading branch information
1 parent
e183594
commit 262b06f
Showing
6 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
169 changes: 169 additions & 0 deletions
169
tests/com/carolinarollergirls/scoreboard/DefaultPositionModelTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
package com.carolinarollergirls.scoreboard; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import com.carolinarollergirls.scoreboard.model.*; | ||
import com.carolinarollergirls.scoreboard.defaults.*; | ||
|
||
public class DefaultPositionModelTests { | ||
private final String firstId = "662caf51-17da-4ef2-8f01-a6d7e1c30d56"; | ||
private final String secondId = "91a6c3f5-8258-46c7-a845-62c21b6e37ca"; | ||
private final String thirdId = "5df0a35b-aaa6-4c30-93ef-07ba4f174cdc"; | ||
|
||
private ScoreBoardModel sbModelMock; | ||
private Ruleset ruleMock; | ||
private TeamModel teamModel; | ||
private SkaterModel first; | ||
private SkaterModel second; | ||
private SkaterModel third; | ||
|
||
@Before | ||
public void setup() { | ||
sbModelMock = Mockito.mock(DefaultScoreBoardModel.class); | ||
|
||
ruleMock = Mockito.mock(Ruleset.class); | ||
|
||
Mockito | ||
.when(sbModelMock.getScoreBoard()) | ||
.thenReturn(sbModelMock); | ||
|
||
Mockito | ||
.when(sbModelMock._getRuleset()) | ||
.thenReturn(ruleMock); | ||
|
||
teamModel = new DefaultTeamModel(sbModelMock, "A"); | ||
|
||
first = new DefaultSkaterModel(teamModel, firstId, "First","123", ""); | ||
second = new DefaultSkaterModel(teamModel, secondId, "Second","456", ""); | ||
third = new DefaultSkaterModel(teamModel, thirdId, "Third","789",""); | ||
|
||
teamModel.addSkaterModel(first); | ||
teamModel.addSkaterModel(second); | ||
teamModel.addSkaterModel(third); | ||
} | ||
|
||
@Test | ||
public void key_values_populated() { | ||
PositionModel blocker = teamModel.getPositionModel(Position.ID_BLOCKER1); | ||
|
||
assertSame(blocker.getId(),Position.ID_BLOCKER1); | ||
assertSame(blocker.getProviderName(), "Position"); | ||
assertSame(blocker.getProviderId(), Position.ID_BLOCKER1); | ||
assertSame(blocker.getProviderClass(), Position.class); | ||
assertSame(blocker.getTeam(), teamModel); | ||
} | ||
|
||
@Test | ||
public void make_skater_jammer_via_position() { | ||
PositionModel jammer = teamModel.getPositionModel(Position.ID_JAMMER); | ||
jammer.setSkaterModel(firstId); | ||
|
||
assertSame(jammer.getSkaterModel(), first); | ||
assertSame(first.getPosition(),Position.ID_JAMMER); | ||
} | ||
|
||
@Test | ||
public void make_skater_jammer_via_skater() { | ||
first.setPosition(Position.ID_JAMMER); | ||
PositionModel jammer = teamModel.getPositionModel(Position.ID_JAMMER); | ||
|
||
assertSame(jammer.getSkaterModel(), first); | ||
assertSame(first.getPosition(), Position.ID_JAMMER); | ||
} | ||
|
||
@Test | ||
public void position_knows_skater_penalty() { | ||
PositionModel jammer = teamModel.getPositionModel(Position.ID_JAMMER); | ||
jammer.setSkaterModel(firstId); | ||
first.setPenaltyBox(true); | ||
|
||
assertTrue(jammer.getPenaltyBox()); | ||
} | ||
|
||
@Test | ||
public void skater_knows_position_penalty() { | ||
PositionModel jammer = teamModel.getPositionModel(Position.ID_JAMMER); | ||
jammer.setSkaterModel(firstId); | ||
jammer.setPenaltyBox(true); | ||
|
||
assertTrue(first.isPenaltyBox()); | ||
} | ||
|
||
@Test | ||
public void doesnt_set_penalty_with_no_skater() { | ||
PositionModel jammer = teamModel.getPositionModel(Position.ID_JAMMER); | ||
jammer.setPenaltyBox(true); | ||
|
||
assertFalse(jammer.getPenaltyBox()); | ||
} | ||
|
||
@Test | ||
public void sp_works() { | ||
PositionModel jammer = teamModel.getPositionModel(Position.ID_JAMMER); | ||
PositionModel pivot = teamModel.getPositionModel(Position.ID_PIVOT); | ||
jammer.setSkaterModel(firstId); | ||
pivot.setSkaterModel(firstId); | ||
|
||
assertSame(pivot.getSkaterModel(), first); | ||
assertNull(jammer.getSkaterModel()); | ||
} | ||
|
||
@Test | ||
public void clears_with_empty_model_id() { | ||
PositionModel jammer = teamModel.getPositionModel(Position.ID_JAMMER); | ||
jammer.setSkaterModel(firstId); | ||
jammer.setSkaterModel(""); | ||
|
||
assertNull(jammer.getSkaterModel()); | ||
} | ||
|
||
@Test | ||
public void clears_with_null_model_id() { | ||
PositionModel jammer = teamModel.getPositionModel(Position.ID_JAMMER); | ||
jammer.setSkaterModel(firstId); | ||
jammer.setSkaterModel(null); | ||
|
||
assertNull(jammer.getSkaterModel()); | ||
} | ||
|
||
|
||
@Test(expected = SkaterNotFoundException.class) | ||
public void throws_with_bogus_skater_id() { | ||
PositionModel jammer = teamModel.getPositionModel(Position.ID_JAMMER); | ||
jammer.setSkaterModel("bogus"); | ||
} | ||
|
||
@Test | ||
public void position_knows_penalty_after_sp() { | ||
PositionModel jammer = teamModel.getPositionModel(Position.ID_JAMMER); | ||
PositionModel pivot = teamModel.getPositionModel(Position.ID_PIVOT); | ||
pivot.setSkaterModel(firstId); | ||
pivot.setPenaltyBox(true); | ||
first.setPosition(Position.ID_JAMMER); | ||
|
||
assertTrue(jammer.getPenaltyBox()); | ||
assertFalse(pivot.getPenaltyBox()); | ||
assertTrue(first.isPenaltyBox()); | ||
} | ||
|
||
@Test | ||
public void position_knows_penalty_after_sp_position() { | ||
PositionModel jammer = teamModel.getPositionModel(Position.ID_JAMMER); | ||
PositionModel pivot = teamModel.getPositionModel(Position.ID_PIVOT); | ||
pivot.setSkaterModel(firstId); | ||
pivot.setPenaltyBox(true); | ||
jammer.setSkaterModel(firstId); | ||
|
||
assertTrue(jammer.getPenaltyBox()); | ||
assertFalse(pivot.getPenaltyBox()); | ||
assertTrue(first.isPenaltyBox()); | ||
} | ||
|
||
|
||
|
||
|
||
} |