diff --git a/pom.xml b/pom.xml index eacd70f0643febb1714d3f1a69a74c3cc9e8240d..061e2418fa079e4f115533ea6c5f232bb18dcbfb 100644 --- a/pom.xml +++ b/pom.xml @@ -8,8 +8,8 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <maven.compiler.source>11</maven.compiler.source> - <maven.compiler.target>11</maven.compiler.target> + <maven.compiler.source>17</maven.compiler.source> + <maven.compiler.target>17</maven.compiler.target> <javafx.base.version>14.0.1</javafx.base.version> </properties> @@ -32,9 +32,9 @@ </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.12</version> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>5.9.2</version> <scope>test</scope> </dependency> diff --git a/src/main/java/mi/hdm/recipes/IngredientManager.java b/src/main/java/mi/hdm/recipes/IngredientManager.java index af33221ff31c2de0d44419c2f1dc79c4739c710c..89260a36141195f848a35f2012e27ab2d3ab9951 100644 --- a/src/main/java/mi/hdm/recipes/IngredientManager.java +++ b/src/main/java/mi/hdm/recipes/IngredientManager.java @@ -13,6 +13,7 @@ public class IngredientManager { private static final IngredientManager instance = new IngredientManager(); private final List<Ingredient> allIngredients; + private IngredientManager() { allIngredients = new ArrayList<>(); } diff --git a/src/test/java/mi/hdm/AppTest.java b/src/test/java/mi/hdm/AppTest.java index f09b2e05f28daf550a58236d0c3c2355e55fbf60..06f6dfaec7b814a7780e96e23470d0e7ff4fb90e 100644 --- a/src/test/java/mi/hdm/AppTest.java +++ b/src/test/java/mi/hdm/AppTest.java @@ -1,7 +1,8 @@ package mi.hdm; -import org.junit.Assert; -import org.junit.Test; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * Unit test for simple App. @@ -12,7 +13,7 @@ public class AppTest { */ @Test public void testApp() { - Assert.assertTrue( true ); + Assertions.assertTrue(true); } } diff --git a/src/test/java/mi/hdm/recipes/CategoryTest.java b/src/test/java/mi/hdm/recipes/CategoryTest.java index 3edc2e9080432fbbf89bae106d30b6b99822a960..59df0cf7c84677b519452c7f02edd0d96c361ee0 100644 --- a/src/test/java/mi/hdm/recipes/CategoryTest.java +++ b/src/test/java/mi/hdm/recipes/CategoryTest.java @@ -1,11 +1,8 @@ package mi.hdm.recipes; import mi.hdm.exceptions.InvalidCategoryException; -import org.junit.Assert; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CategoryTest { CategoryManager underTest = CategoryManager.getInstance(); @@ -18,9 +15,9 @@ public class CategoryTest { Category c3 = new Category("ew", 0x13); Category c4 = new Category("ew", 0x100); - assertNotEquals(c1, c2); - assertEquals(c3, c4); - assertEquals(c2, c3); + Assertions.assertNotEquals(c1, c2); + Assertions.assertEquals(c3, c4); + Assertions.assertEquals(c2, c3); } @Test @@ -29,7 +26,7 @@ public class CategoryTest { underTest.addCategory("Mittag", 0x100000); underTest.addCategory("Mittag", 0x100040); - Assert.assertEquals(1, underTest.getAllCategories().size()); + Assertions.assertEquals(1, underTest.getAllCategories().size()); } @Test @@ -38,7 +35,7 @@ public class CategoryTest { underTest.addCategory("Morgen", 0x100040); underTest.addCategory("Mittag", 0x100040); - Assert.assertEquals(1, underTest.getAllCategories().size()); + Assertions.assertEquals(1, underTest.getAllCategories().size()); } @Test @@ -47,7 +44,7 @@ public class CategoryTest { underTest.addCategory("Morgen", 0x100000); underTest.addCategory("Abend", 0x100010); - Assert.assertEquals(2, underTest.getAllCategories().size()); + Assertions.assertEquals(2, underTest.getAllCategories().size()); } @Test @@ -60,26 +57,26 @@ public class CategoryTest { underTest.deleteCategory("Jan ist cool"); //expect - assertEquals(0, underTest.getAllCategories().size()); + Assertions.assertEquals(0, underTest.getAllCategories().size()); } - @Test(expected = InvalidCategoryException.class) + @Test public void canNotAddCategoryWithEmptyName() { - Category emptyName = new Category("", 0x1000); + Assertions.assertThrows(InvalidCategoryException.class, () -> new Category("", 0x1000)); } - @Test(expected = InvalidCategoryException.class) + @Test public void canNotAddCategoryWithNullName() { - Category nullName = new Category(null, 0x1000); + Assertions.assertThrows(InvalidCategoryException.class, () -> new Category(null, 0x1000)); } - @Test(expected = InvalidCategoryException.class) + @Test public void canNotAddCategoryWithNegativeCode() { - Category negativeCode = new Category("foo", -100); + Assertions.assertThrows(InvalidCategoryException.class, () -> new Category("Negative", -100)); } - @Test(expected = InvalidCategoryException.class) + @Test public void canNotAddCategoryWithCodeTooHigh() { - Category tooHighCode = new Category("foo", Integer.MAX_VALUE); + Assertions.assertThrows(InvalidCategoryException.class, () -> new Category("too high", Integer.MAX_VALUE)); } } diff --git a/src/test/java/mi/hdm/recipes/IngredientTest.java b/src/test/java/mi/hdm/recipes/IngredientTest.java index 5b9699cfbbe2a98289e44a8cdf4cc53fb903df34..82da1bdd5b30abe13578e6b95c0ae5346d030b25 100644 --- a/src/test/java/mi/hdm/recipes/IngredientTest.java +++ b/src/test/java/mi/hdm/recipes/IngredientTest.java @@ -1,29 +1,33 @@ package mi.hdm.recipes; import mi.hdm.exceptions.InvalidIngredientException; -import org.junit.Assert; -import org.junit.Test; - -import static org.junit.Assert.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class IngredientTest { IngredientManager underTest = IngredientManager.getInstance(); NutritionTable tt = ValidObjectsPool.getValidNutritionTableOne(); - @Test(expected = InvalidIngredientException.class) + @BeforeEach + public void setup() { + underTest.clearIngredients(); + } + + @Test public void shouldNotCreateIngredientWithNameNull() { - new Ingredient(Measurement.GRAM, null, tt); + Assertions.assertThrows(InvalidIngredientException.class, () -> new Ingredient(Measurement.GRAM, null, tt)); } - @Test(expected = InvalidIngredientException.class) + @Test public void shouldNotCreateIngredientWithNameEmpty() { - new Ingredient(Measurement.GRAM, "", tt); + Assertions.assertThrows(InvalidIngredientException.class, () -> new Ingredient(Measurement.GRAM, "", tt)); } - @Test(expected = InvalidIngredientException.class) + @Test public void shouldNotCreateIngredientWithNutritionTableNull() { - new Ingredient(Measurement.GRAM, "Name is not null", null); + Assertions.assertThrows(InvalidIngredientException.class, () -> new Ingredient(Measurement.GRAM, "foo", null)); } @Test @@ -32,9 +36,9 @@ public class IngredientTest { Ingredient i2 = new Ingredient(Measurement.PIECE, "Banana", tt); Ingredient i3 = new Ingredient(Measurement.GRAM, "Apple", tt); - assertEquals(i1, i2); - assertNotEquals(i1, i3); - assertNotEquals(i2, i3); + Assertions.assertEquals(i1, i2); + Assertions.assertNotEquals(i1, i3); + Assertions.assertNotEquals(i2, i3); } @Test @@ -42,13 +46,12 @@ public class IngredientTest { underTest.addIngredient(Measurement.GRAM, "Banana", tt); underTest.addIngredient(Measurement.PIECE, "Banana", tt); - Assert.assertEquals(1, underTest.getAllIngredients().size()); + Assertions.assertEquals(1, underTest.getAllIngredients().size()); } @Test public void shouldRemoveExistingIngredient() { //given - underTest.clearIngredients(); Ingredient i1 = ValidObjectsPool.getValidIngredientOne(); underTest.addIngredient(i1); @@ -56,13 +59,12 @@ public class IngredientTest { boolean shouldBeTrue = underTest.deleteIngredient(i1.getName()); //expect - assertTrue(shouldBeTrue); + Assertions.assertTrue(shouldBeTrue); } - @Test(expected = InvalidIngredientException.class) + @Test public void shouldThrowWhenRemovingWrongIngredient() { - underTest.clearIngredients(); Ingredient i1 = ValidObjectsPool.getValidIngredientOne(); - underTest.deleteIngredient(i1.getName()); + Assertions.assertThrows(InvalidIngredientException.class, () -> underTest.deleteIngredient(i1.getName())); } } diff --git a/src/test/java/mi/hdm/recipes/NutritionCalculatorTest.java b/src/test/java/mi/hdm/recipes/NutritionCalculatorTest.java index d54f4f9c86fad9f3d86647bcb6d8774f805b9520..cb5a28ad0761a88024551f0ece0625e127a664cd 100644 --- a/src/test/java/mi/hdm/recipes/NutritionCalculatorTest.java +++ b/src/test/java/mi/hdm/recipes/NutritionCalculatorTest.java @@ -1,21 +1,18 @@ package mi.hdm.recipes; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - public class NutritionCalculatorTest { List<Ingredient> ingredients = ValidObjectsPool.getValidIngredientList(); Map<RecipeComponent, Integer> recipeMap; - - @Before + @BeforeEach public void setUp() { recipeMap = new HashMap<>(); ingredients.forEach(ingredient -> recipeMap.put(ingredient, 100)); @@ -30,12 +27,12 @@ public class NutritionCalculatorTest { NutritionTable actual = NutritionCalculator.calculateNutritionTable(recipeMap); //expect - assertEquals(expected, actual); + Assertions.assertEquals(expected, actual); } @Test public void testCalculateNutritionTableFromRecipes() { //TODO - assertTrue(true); + Assertions.assertTrue(true); } } diff --git a/src/test/java/mi/hdm/recipes/NutritionTableTest.java b/src/test/java/mi/hdm/recipes/NutritionTableTest.java index 12c73740d9247fed410b3720af002e269420531a..38176e2c4048d7ec343ba09afd8cd81ba435ec35 100644 --- a/src/test/java/mi/hdm/recipes/NutritionTableTest.java +++ b/src/test/java/mi/hdm/recipes/NutritionTableTest.java @@ -1,19 +1,17 @@ package mi.hdm.recipes; import mi.hdm.exceptions.InvalidNutritionTableException; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - public class NutritionTableTest { - @Test(expected = InvalidNutritionTableException.class) + @Test public void shouldNotCreateInvalidNutritionTable() { - new NutritionTable(-1.0, 1.0, 1.0, 1.0, 1.0, 1.2); + Assertions.assertThrows(InvalidNutritionTableException.class, () -> new NutritionTable(-1.0, 1.0, 1.0, 1.0, 1.0, 1.2)); } @Test @@ -38,7 +36,7 @@ public class NutritionTableTest { expected.put(Nutrition.FIBERS, fibers); expected.put(Nutrition.SALT, salt); - assertEquals(expected, underTest.getTable()); + Assertions.assertEquals(expected, underTest.getTable()); } @Test @@ -47,8 +45,8 @@ public class NutritionTableTest { NutritionTable underTestTwo = ValidObjectsPool.getValidNutritionTableTwo(); NutritionTable underTestEqualToOne = new NutritionTable(100.0, 17.2, 9.4, 4.3, 2.4, 0.4); - assertNotEquals(underTestOne, underTestTwo); - assertEquals(underTestEqualToOne, underTestEqualToOne); + Assertions.assertNotEquals(underTestOne, underTestTwo); + Assertions.assertEquals(underTestEqualToOne, underTestEqualToOne); } } \ No newline at end of file