Code: Alles auswählen
@Test(expected = IllegalArgumentException.class)
public void testAddThrow_AfterStrike() {
//
// setup:
StandardFrame sut1 = new StandardFrame();
//
// exercise:
sut1.addThrowScore(10);
sut1.addThrowScore(0);
// verify: see annotation expected
// tear-down: not needed.
}
Code: Alles auswählen
@Override
public void addThrowScore(int score) {
// check whether the input is invalid
if (score < 0 || score > 10)
throw new IllegalArgumentException("The score[" + score
+ "] is out of bounds(0,10).");
if (!hasFirstThrow()) {
setFirstThrowScore(score);
return;
}
if (!hasSecondThrow()) {
// check whether the input is invalid for this second throw
if (getFirstThrowScore() != 10 && getFirstThrowScore() + score > 10)
throw new IllegalArgumentException("The score[" + score
+ "] is in addition with the current score["
+ getFirstThrowScore() + "] out of bounds(0,10).");
setSecondThrowScore(score);
return;
}
// invalid state
throw new IllegalStateException(
"This frame has already been used for three throws.");
}
Kann mir jemand sagen wo mein Denkfehler liegt?