I am getting 1/4 branch coverage when I run this JUnit test. However, when I change the if
statement to "if (points == 1 || points == 2 || points == 3 || points == 4)" it passes the JUnit test. What am I doing wrong?
Main class:
public int getPoints() {
return points;
}
public Grade(int p) throws IllegalArgumentException {
if (p < 1 || p > 20)
throw new IllegalArgumentException();
points = p;
}
// Your additions/changes below this line
public Classification classify() {
if (points >= 1 && points <= 4) {
return Classification.First;
}
else {
throw new IllegalArgumentException("Not a Grade");
}
}
JUnit Test:
@Test
public void testFirst() {
Assert.assertEquals(Classification.First, new Grade(1).classify());
Assert.assertEquals(Classification.First, new Grade(2).classify());
Assert.assertEquals(Classification.First, new Grade(3).classify());
Assert.assertEquals(Classification.First, new Grade(4).classify());
}