Skip to content

Commit

Permalink
add junit test for roll service
Browse files Browse the repository at this point in the history
  • Loading branch information
amenning committed Mar 14, 2018
1 parent 5653a1c commit 5c5dbec
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ repositories {

dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-all:1.3'
}
39 changes: 39 additions & 0 deletions src/test/java/com/pickominio/service/RollTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.pickominio.service;

import com.pickominio.model.ActiveDiceSet;
import com.pickominio.model.Dice;
import com.pickominio.model.DiceSet;
import org.junit.Before;
import org.junit.Test;

import java.util.stream.Stream;

import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.*;

public class RollTest {
private DiceSet diceSet;
private Roll roll;

@Before
public void setUp() throws Exception {
diceSet = ActiveDiceSet.buildNewSet();
roll = new Roll();
}

@Test
public void diceSet() {
roll.diceSet(diceSet);
int[] values = Stream.of(diceSet.toString().split(" "))
.mapToInt(value -> Integer.parseInt(value))
.toArray();
for (int diceValue : values) {
assertThat(
diceValue,
allOf(greaterThanOrEqualTo(Dice.MIN_DICE_VALUE), lessThanOrEqualTo(Dice.MAX_DICE_VALUE))
);
}
}
}

0 comments on commit 5c5dbec

Please sign in to comment.