diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/ItemOverview.java b/src/main/java/no/ntnu/idatt1002/demo/data/ItemOverview.java index 03fcdb81d4af0554ef64ad5743f8bba63e8aa35a..6cd6914809100a8cb6a43677b49255198eb2c52d 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/ItemOverview.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/ItemOverview.java @@ -4,8 +4,8 @@ import java.util.ArrayList; /** * ItemOverview is a class for storing and getting - * information on items. Is also a - * superclass for Income- and Expense overview. TODO: Make income and expense overview + * information on items. It is meant for storing + * Income or Expense */ public class ItemOverview { ArrayList<Item> items; @@ -37,7 +37,7 @@ public class ItemOverview { * Add an Item object to items. * @param newItem The Item you want to add. */ - public void addItem(Income newItem){ + public void addItem(Item newItem){ if(items.contains(newItem)){ throw new IllegalArgumentException("This item is already registered"); } diff --git a/src/test/java/no/ntnu/idatt1002/demo/data/ItemOverviewTest.java b/src/test/java/no/ntnu/idatt1002/demo/data/ItemOverviewTest.java index ef9b58f72908bf6dfd4071d03266e511bbf6033e..d235a6b238a03b4f09b801314a2525b595a9eeaf 100644 --- a/src/test/java/no/ntnu/idatt1002/demo/data/ItemOverviewTest.java +++ b/src/test/java/no/ntnu/idatt1002/demo/data/ItemOverviewTest.java @@ -1,6 +1,5 @@ package no.ntnu.idatt1002.demo.data; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -8,10 +7,6 @@ import static org.junit.jupiter.api.Assertions.*; public class ItemOverviewTest { ItemOverview itemOverview; - @BeforeEach - public void makeItemOverview(){ - itemOverview = new ItemOverview(); - } @Test @DisplayName("addItem method throws exception when it should") void addItemThrows(){ @@ -22,18 +17,17 @@ public class ItemOverviewTest { @Test @DisplayName("addItem method does not throw exception when it should not") void addItemDoesNotThrow(){ - Income income1 = new Income("description", 59.9f, false, IncomeCategory.SALARY, "03.03.23"); - Income income2 = new Income("anotherDescription", 6.5f, true, IncomeCategory.SALARY, "02.03.23"); - assertDoesNotThrow(() -> {itemOverview.addItem(income1); itemOverview.addItem(income2);}); + Expense expense = new Expense("description", 59.9f, false, ExpenseCategory.CLOTHES, "03.03.23"); + Income income = new Income("anotherDescription", 6.5f, true, IncomeCategory.SALARY, "02.03.23"); + assertDoesNotThrow(() -> {itemOverview.addItem(expense); itemOverview.addItem(income);}); } @Test @DisplayName("getTotalSum method gives correct amount") - void getTotalIncomeCorrectAmount(){ + void getTotalSumCorrectAmount(){ itemOverview.addItem(new Income("description1", 59.9f, false, IncomeCategory.SALARY, "03.03.23")); itemOverview.addItem(new Income("description2", 62.4f, true, IncomeCategory.GIFT, "01.02.21")); itemOverview.addItem(new Income("description3", 9.81f, false, IncomeCategory.SALARY, "05.07.23")); - double totalIncome = 59.9f + 62.4f + 9.81f; assertEquals(Math.round(itemOverview.getTotalSum()), Math.round(totalIncome)); }