Skip to content
Snippets Groups Projects
Commit 3be96283 authored by Harry Linrui XU's avatar Harry Linrui XU
Browse files

Made hasUnusedCategories more general + Tested new budget methods

parent 9ba86dbb
No related branches found
No related tags found
3 merge requests!43Merging frontend-testing into master,!38"Made progressbar dynamic in accordance to spending. Added balance field....,!37Made the sub progress bars respond to changes in expense
Pipeline #215848 passed
...@@ -172,10 +172,19 @@ public class GeneralBudget { ...@@ -172,10 +172,19 @@ public class GeneralBudget {
return budgetItems.stream().anyMatch(budgetItem -> budgetItem.getBudgetCategory().equals(category)); return budgetItems.stream().anyMatch(budgetItem -> budgetItem.getBudgetCategory().equals(category));
} }
/**
* This method checks if there are unused categories in the budget.
* @return True, if the list contains unused categories. Else returns false.
*/
private boolean hasUnusedCategories() { private boolean hasUnusedCategories() {
return budgetItems.size() != 4; return budgetItems.size() != ExpenseCategory.values().length;
} }
/**
* Method that adds the remaining, unused categories to the budget list.
* Useful, as unused categories can be automatically added without user input.
*/
public void addUnusedCategories() { public void addUnusedCategories() {
if (hasUnusedCategories()) { if (hasUnusedCategories()) {
Arrays.stream(ExpenseCategory.values()). Arrays.stream(ExpenseCategory.values()).
......
package no.ntnu.idatt1002.demo.data.Budget; package no.ntnu.idatt1002.demo.data.Budget;
import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory; import no.ntnu.idatt1002.demo.data.Economics.ExpenseCategory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -105,6 +107,30 @@ class GeneralBudgetTest { ...@@ -105,6 +107,30 @@ class GeneralBudgetTest {
assertTrue(list.isEmpty()); assertTrue(list.isEmpty());
} }
@Nested
class UnusedCategories {
GeneralBudget budget;
List<BudgetItem> list;
@BeforeEach
void setUp() {
list = new ArrayList<>();
budget = new GeneralBudget(12, list, 1200);
budget.addToBudget(10, "Books", ExpenseCategory.BOOKS);
}
@Test
@DisplayName("Test addUnusedCategories adds unused categories")
void hasUnusedCategories_with_full_budget() {
assertEquals(1, budget.getBudgetItems().size());
budget.addUnusedCategories();
assertEquals(4, budget.getBudgetItems().size());
}
}
/* @Test /* @Test
@DisplayName("Gets the number of days left in the month. 17 has to be changed to the actual number of days left in the month.") @DisplayName("Gets the number of days left in the month. 17 has to be changed to the actual number of days left in the month.")
void get_days_left_of_the_month(){ void get_days_left_of_the_month(){
......
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