Skip to content
Snippets Groups Projects
Commit bd0ba3e9 authored by Andreas's avatar Andreas
Browse files

Made ItemOverview abstract, and made subclasses

parent 6deb6a3f
No related branches found
No related tags found
1 merge request!5Created register for storing information on Income and Expense
Pipeline #204631 passed
package no.ntnu.idatt1002.demo.data;
import java.util.ArrayList;
public class ExpenseOverview {
private ArrayList<Expense> expenses;
public ExpenseOverview(){
this.expenses = new ArrayList<>();
}
}
package no.ntnu.idatt1002.demo.data;
import java.util.ArrayList;
public class IncomeOverview extends ItemOverview {
private ArrayList<Income> income;
public IncomeOverview(){
this.income = new ArrayList<>();
}
}
......@@ -7,7 +7,7 @@ import java.util.ArrayList;
* information on items. It is meant for storing EITHER
* Income or Expense
*/
public class ItemOverview {
public abstract class ItemOverview {
ArrayList<Item> items;
/**
......
......@@ -6,35 +6,35 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class ItemOverviewTest {
ItemOverview itemOverview;
public class IncomeOverviewTest {
IncomeOverview incomeOverview;
@BeforeEach
public void createItemOverView(){
itemOverview = new ItemOverview();
incomeOverview = new IncomeOverview();
}
@Test
@DisplayName("addItem method throws exception when it should")
void addItemThrows(){
Income income = new Income("description", 59.9f, false, IncomeCategory.SALARY, "03.03.23");
assertThrows(IllegalArgumentException.class, () -> {itemOverview.addItem(income); itemOverview.addItem(income);});
assertThrows(IllegalArgumentException.class, () -> {incomeOverview.addItem(income); incomeOverview.addItem(income);});
}
@Test
@DisplayName("addItem method does not throw exception when it should not")
void addItemDoesNotThrow(){
Expense expense = new Expense("description", 59.9f, false, ExpenseCategory.CLOTHES, "03.03.23");
Income expense = new Income("description", 59.9f, false, IncomeCategory.GIFT, "03.03.23");
Income income = new Income("anotherDescription", 6.5f, true, IncomeCategory.SALARY, "02.03.23");
assertDoesNotThrow(() -> {itemOverview.addItem(expense); itemOverview.addItem(income);});
assertDoesNotThrow(() -> {incomeOverview.addItem(expense); incomeOverview.addItem(income);});
}
@Test
@DisplayName("getTotalSum method gives correct amount")
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"));
incomeOverview.addItem(new Income("description1", 59.9f, false, IncomeCategory.SALARY, "03.03.23"));
incomeOverview.addItem(new Income("description2", 62.4f, true, IncomeCategory.GIFT, "01.02.21"));
incomeOverview.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));
assertEquals(Math.round(incomeOverview.getTotalSum()), Math.round(totalIncome));
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment