I'm trying to test if an exception is being thrown (when one is expected)
I get this error (when I shouldn't):
java.lang.AssertionError: Expected exception: exception.OutOfRangeException
The method being tested:
public void setScore ( int score ) throws exception.OutOfRangeException
{
if ( ( score < 0 ) || ( score > 100 ) ) {
throw new exception.OutOfRangeException( "Score invalid: " + score );
}
else {
this.score = score
}
}
The test method:
@Test(expected=exception.OutOfRangeException.class)
public void testScoreOutOfRangeException() {
try {
record.setScore (-1);
}
catch ( OutOfRangeException e ) {
// do nothing because we expected it
}
}
What I am doing wrong?