diff --git a/src/main/java/mi/hdm/exceptions/InvalidCategoryException.java b/src/main/java/mi/hdm/exceptions/InvalidCategoryException.java new file mode 100644 index 0000000000000000000000000000000000000000..3eb3ea7f70e5dd6fdab80a29767a57316e340d42 --- /dev/null +++ b/src/main/java/mi/hdm/exceptions/InvalidCategoryException.java @@ -0,0 +1,7 @@ +package mi.hdm.exceptions; + +public class InvalidCategoryException extends RuntimeException{ + public InvalidCategoryException(String message) { + super(message); + } +} diff --git a/src/test/java/mi/hdm/recipes/CategoryTest.java b/src/test/java/mi/hdm/recipes/CategoryTest.java index 6e8cfad123e1dda76c97eab032c8c5070d2b78c9..4e68832d31229c5c81e9cb44d9317856ab3cc3d3 100644 --- a/src/test/java/mi/hdm/recipes/CategoryTest.java +++ b/src/test/java/mi/hdm/recipes/CategoryTest.java @@ -1,5 +1,6 @@ package mi.hdm.recipes; +import mi.hdm.exceptions.InvalidCategoryException; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -61,4 +62,24 @@ public class CategoryTest { //expect assertEquals(0, underTest.getAllCategories().size()); } + + @Test(expected = InvalidCategoryException.class) + public void canNotAddCategoryWithEmptyName() { + Category emptyName = new Category("", 0x1000); + } + + @Test(expected = InvalidCategoryException.class) + public void canNotAddCategoryWithNullName() { + Category emptyName = new Category(null, 0x1000); + } + + @Test(expected = InvalidCategoryException.class) + public void canNotAddCategoryWithNegativeCode() { + Category emptyName = new Category("foo", -100); + } + + @Test(expected = InvalidCategoryException.class) + public void canNotAddCategoryWithCodeTooHigh() { + Category emptyName = new Category("foo", Integer.MAX_VALUE); + } }