Skip to content

Commit

Permalink
added tests (not nullability of params) for Round and Move
Browse files Browse the repository at this point in the history
  • Loading branch information
samidalouche committed Feb 14, 2010
1 parent c2cde61 commit 08bf651
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
Expand Up @@ -4,7 +4,7 @@

import org.apache.commons.lang.Validate;

public class Round {
public final class Round {
private static final class Outcome {
Move winner;
Move loser;
Expand Down
@@ -1,6 +1,7 @@
package com.dalouche.experiments.rockpaperscissors;

import static com.dalouche.experiments.rockpaperscissors.Paper.paper;
import static com.dalouche.experiments.rockpaperscissors.Rock.rock;
import static com.dalouche.experiments.rockpaperscissors.Scissors.scissors;
import static org.mockito.Mockito.mock;

Expand All @@ -18,6 +19,16 @@ public void onSetUp() {
player2 = mock(Player.class);
}

@Test(expected=IllegalArgumentException.class)
public void shouldNotCreateWithoutSymbol() {
new Move(anyPlayer(), null);
}

@Test(expected=IllegalArgumentException.class)
public void shouldNotCreateWithoutPlayer() {
new Move(null, anySymbol());
}

@Test
public void move1ShouldDefeatMove2() {
Move move1 = playerOnePlaysScissors();
Expand All @@ -33,4 +44,11 @@ private Move player2PlaysPaper() {
private Move playerOnePlaysScissors() {
return new Move(player1, scissors());
}
private Player anyPlayer() {
return player1;
}

private Symbol anySymbol() {
return rock();
}
}
Expand Up @@ -5,10 +5,7 @@
import static com.dalouche.experiments.commons.TestUtils.shouldNotEqualNull;
import static com.dalouche.experiments.commons.TestUtils.shouldNotEqualObjectOfDifferentType;
import static com.dalouche.experiments.rockpaperscissors.Nobody.nobody;
import static com.dalouche.experiments.rockpaperscissors.Paper.paper;
import static com.dalouche.experiments.rockpaperscissors.Rock.rock;

import org.junit.Assert;
import org.junit.Test;

public class NobodyTest {
Expand Down
Expand Up @@ -7,11 +7,8 @@
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;

import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

public final class RoundTest {

Expand All @@ -24,10 +21,22 @@ public void onSetUp() {
player2 = mock(Player.class);
}

@Test(expected=IllegalArgumentException.class)
public void shouldNotCreateMoveWithoutMove1() {
new Round(null, anyMove());
}

@Test(expected=IllegalArgumentException.class)
public void shouldNotCreateMoveWithoutMove2() {
new Round(anyMove(), null);
}



@Test
public void player1ShouldBeWinner() {
Move move1 = playerOnePlaysScissors();
Move move2 = player2PlaysPaper();
Move move2 = playerTwoPlaysPaper();
assertThat(move1.against(move2).getRoundWinner(), is(player1));
assertThat(move1.against(move2).getRoundLoser(), is(player2));
}
Expand All @@ -39,11 +48,15 @@ public void nobodyShouldWin() {
assertThat(move1.against(move2).getRoundWinner(), is((Player)nobody()));
}

private Move player2PlaysPaper() {
private Move playerTwoPlaysPaper() {
return new Move(player2, paper());
}

private Move playerOnePlaysScissors() {
return new Move(player1, scissors());
}

private Move anyMove() {
return playerOnePlaysScissors();
}
}

0 comments on commit 08bf651

Please sign in to comment.