ItEr23S03ContornaItEr22S03: Checking that the category throws IllegalArgumentException when receiving a not valid percentage

This commit is contained in:
Óscar González Fernández 2009-08-23 13:37:36 +02:00
parent 9133b77940
commit 66528ab3e3
2 changed files with 7 additions and 2 deletions

View file

@ -15,7 +15,7 @@ public class LoadLevel {
SOME_LOAD {
@Override
public boolean contains(int percentage) {
return percentage < 100;
return percentage > 0 && percentage < 100;
}
},
FULL_LOAD {
@ -37,7 +37,7 @@ public class LoadLevel {
if (category.contains(percentage))
return category;
}
throw new RuntimeException("couldn't handle " + percentage);
throw new IllegalArgumentException("couldn't handle " + percentage);
}
}

View file

@ -60,4 +60,9 @@ public class LoadLevelTest {
thenTheCategoryIs(Category.OVERLOAD);
}
@Test(expected = IllegalArgumentException.class)
public void theCategoryThrowsExceptionIfCantHandleThePercentage() {
Category.categoryFor(-1);
}
}