From c9bb6ab96d867f83ac480144c25d54100e7687b0 Mon Sep 17 00:00:00 2001
From: Lukas Karsch <lk224@hdm-stuttgart.de>
Date: Thu, 20 Apr 2023 11:02:06 +0200
Subject: [PATCH] added InvalidCategoryException.java; added tests to
 categories: they should not be created with a name that is "", null and only
 be created with a color code where 0 <= code <= 0xFFFFFF

---
 .../exceptions/InvalidCategoryException.java  |  7 +++++++
 .../java/mi/hdm/recipes/CategoryTest.java     | 21 +++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 src/main/java/mi/hdm/exceptions/InvalidCategoryException.java

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 0000000..3eb3ea7
--- /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 6e8cfad..4e68832 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);
+    }
 }
-- 
GitLab