forked from nus-cs2103-AY2223S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #247 from shirsho-12/master
Add PPP
- Loading branch information
Showing
14 changed files
with
1,387 additions
and
454 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/test/java/fasttrack/logic/commands/SetBudgetCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package fasttrack.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import fasttrack.model.Budget; | ||
import fasttrack.model.Model; | ||
import fasttrack.model.ModelManager; | ||
import fasttrack.model.UserPrefs; | ||
import fasttrack.testutil.TypicalCategories; | ||
|
||
public class SetBudgetCommandTest { | ||
private Budget budget = new Budget(1000); | ||
private Budget differentBudget = new Budget(2000); | ||
private Model model = new ModelManager(TypicalCategories.getTypicalExpenseTracker(), | ||
new UserPrefs()); | ||
|
||
@Test | ||
public void equals() { | ||
SetBudgetCommand setBudgetCommand = new SetBudgetCommand(budget); | ||
SetBudgetCommand setBudgetCommandCopy = new SetBudgetCommand(budget); | ||
SetBudgetCommand setBudgetCommandDifferentBudget = new SetBudgetCommand(differentBudget); | ||
|
||
// same object -> returns true | ||
assertTrue(setBudgetCommand.equals(setBudgetCommand)); | ||
|
||
// same values -> returns true | ||
assertTrue(setBudgetCommand.equals(setBudgetCommandCopy)); | ||
|
||
// null -> returns false | ||
assertFalse(setBudgetCommand.equals(null)); | ||
|
||
// different budget -> returns false | ||
assertFalse(setBudgetCommand.equals(setBudgetCommandDifferentBudget)); | ||
} | ||
|
||
@Test | ||
public void testHashCode() { | ||
SetBudgetCommand setBudgetCommand = new SetBudgetCommand(budget); | ||
SetBudgetCommand setBudgetCommandCopy = new SetBudgetCommand(budget); | ||
SetBudgetCommand setBudgetCommandDifferentBudget = new SetBudgetCommand(differentBudget); | ||
|
||
// same object -> returns same hashcode | ||
assertEquals(setBudgetCommand.hashCode(), setBudgetCommand.hashCode()); | ||
|
||
// same values -> returns same hashcode | ||
assertEquals(setBudgetCommand.hashCode(), setBudgetCommandCopy.hashCode()); | ||
|
||
// different budget -> returns different hashcode | ||
assertNotEquals(setBudgetCommand.hashCode(), setBudgetCommandDifferentBudget.hashCode()); | ||
} | ||
|
||
@Test | ||
public void testToString() { | ||
SetBudgetCommand setBudgetCommand = new SetBudgetCommand(budget); | ||
assertEquals("SetBudgetCommand{budget=1000.0}", setBudgetCommand.toString()); | ||
} | ||
|
||
@Test | ||
public void execute_validBudget_success() { | ||
SetBudgetCommand setBudgetCommand = new SetBudgetCommand(budget); | ||
String expectedMessage = SetBudgetCommand.MESSAGE_SUCCESS + budget.toString(); | ||
Model expectedModel = new ModelManager(model.getExpenseTracker(), new UserPrefs()); | ||
CommandResult message = setBudgetCommand.execute(expectedModel); | ||
assertEquals(expectedMessage, message.getFeedbackToUser()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package fasttrack.ui; | ||
|
||
import static fasttrack.testutil.TypicalCategories.FOOD; | ||
import static fasttrack.ui.JavaFxTestHelper.initJavaFxHelper; | ||
import static fasttrack.ui.JavaFxTestHelper.setUpHeadlessMode; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentest4j.AssertionFailedError; | ||
|
||
import fasttrack.model.category.Category; | ||
import javafx.application.Platform; | ||
import javafx.scene.control.Label; | ||
|
||
|
||
public class CategoryCardTest { | ||
|
||
private Category category; | ||
private int displayedIndex; | ||
private int associatedExpenseCount; | ||
|
||
@BeforeEach | ||
public void setUp() throws InterruptedException { | ||
if (System.getProperty("os.name").toLowerCase().contains("linux")) { | ||
return; | ||
} | ||
category = FOOD; | ||
displayedIndex = 1; | ||
associatedExpenseCount = 3; | ||
} | ||
|
||
@BeforeAll | ||
static void initJfx() throws InterruptedException { | ||
if (System.getProperty("os.name").toLowerCase().contains("linux")) { | ||
return; | ||
} | ||
setUpHeadlessMode(); | ||
initJavaFxHelper(); | ||
} | ||
|
||
@Test | ||
public void testCategoryCard_validData_success() { | ||
if (System.getProperty("os.name").toLowerCase().contains("linux")) { | ||
return; | ||
} | ||
CategoryCard categoryCard = new CategoryCard(category, displayedIndex, associatedExpenseCount); | ||
CompletableFuture<Void> future = new CompletableFuture<>(); | ||
Platform.runLater(() -> { | ||
try { | ||
// Test that the category name label is set correctly | ||
Label categoryNameLabel = (Label) categoryCard.getRoot().lookup("#categoryName"); | ||
assertEquals("Food", categoryNameLabel.getText()); | ||
|
||
// Test that the index label is set correctly | ||
Label indexLabel = (Label) categoryCard.getRoot().lookup("#id"); | ||
assertEquals("1. ", indexLabel.getText()); | ||
|
||
// Test that the expense count label is set correctly | ||
Label expenseCountLabel = (Label) categoryCard.getRoot().lookup("#expenseCount"); | ||
assertEquals("3", expenseCountLabel.getText()); | ||
future.complete(null); | ||
} catch (AssertionFailedError e) { | ||
future.completeExceptionally(e); | ||
} | ||
}); | ||
try { | ||
future.get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
fail("Assertion error thrown in Platform.runLater thread: " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testEquals_validCategoryCard_success() { | ||
if (System.getProperty("os.name").toLowerCase().contains("linux")) { | ||
return; | ||
} | ||
CategoryCard categoryCard1 = new CategoryCard(category, displayedIndex, associatedExpenseCount); | ||
CategoryCard categoryCard2 = new CategoryCard(category, displayedIndex + 1, associatedExpenseCount - 1); | ||
CategoryCard categoryCard3 = new CategoryCard(category, displayedIndex + 1, associatedExpenseCount - 1); | ||
CompletableFuture<Void> future = new CompletableFuture<>(); | ||
Platform.runLater(() -> { | ||
try { | ||
assertEquals(categoryCard1, categoryCard1); | ||
assertNotEquals(categoryCard1, categoryCard2); | ||
assertEquals(categoryCard2, categoryCard3); | ||
future.complete(null); | ||
} catch (AssertionFailedError e) { | ||
future.completeExceptionally(e); | ||
} | ||
}); | ||
try { | ||
future.get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
fail("Assertion error thrown in Platform.runLater thread: " + e.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package fasttrack.ui; | ||
|
||
import static fasttrack.testutil.TypicalCategories.FOOD; | ||
import static fasttrack.testutil.TypicalCategories.TECH; | ||
import static fasttrack.testutil.TypicalExpenses.APPLE; | ||
import static fasttrack.testutil.TypicalExpenses.CHERRY; | ||
import static fasttrack.ui.JavaFxTestHelper.initJavaFxHelper; | ||
import static fasttrack.ui.JavaFxTestHelper.setUpHeadlessMode; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentest4j.AssertionFailedError; | ||
|
||
import fasttrack.model.category.Category; | ||
import fasttrack.model.expense.Expense; | ||
import javafx.application.Platform; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import javafx.scene.control.ListView; | ||
|
||
|
||
public class CategoryListPanelTest { | ||
|
||
private CategoryListPanel categoryListPanel; | ||
private ObservableList<Category> categories; | ||
private ObservableList<Expense> expenses; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
if (System.getProperty("os.name").toLowerCase().contains("linux")) { | ||
return; | ||
} | ||
categories = FXCollections.observableArrayList(FOOD, TECH); | ||
expenses = FXCollections.observableArrayList(APPLE, CHERRY); | ||
} | ||
|
||
@BeforeAll | ||
static void initJfx() throws InterruptedException { | ||
if (System.getProperty("os.name").toLowerCase().contains("linux")) { | ||
return; | ||
} | ||
setUpHeadlessMode(); | ||
initJavaFxHelper(); | ||
} | ||
|
||
|
||
@Test | ||
public void categoryListView_validCategories_countEqual() { | ||
if (System.getProperty("os.name").toLowerCase().contains("linux")) { | ||
return; | ||
} | ||
CompletableFuture<Void> future = new CompletableFuture<>(); | ||
categoryListPanel = new CategoryListPanel(categories, expenses); | ||
Platform.runLater(() -> { | ||
try { | ||
// Test that the number of categories is correct | ||
ListView<?> categoryListView = (ListView<?>) categoryListPanel.getRoot().lookup("#categoryListView"); | ||
assertEquals(categories.size(), categoryListView.getItems().size()); | ||
future.complete(null); | ||
} catch (AssertionFailedError e) { | ||
future.completeExceptionally(e); | ||
} | ||
}); | ||
try { | ||
future.get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
fail("Assertion error thrown in Platform.runLater thread: " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void categoryListView_emptyList_countZero() { | ||
if (System.getProperty("os.name").toLowerCase().contains("linux")) { | ||
return; | ||
} | ||
categories = FXCollections.observableArrayList(); | ||
expenses = FXCollections.observableArrayList(); | ||
CompletableFuture<Void> future = new CompletableFuture<>(); | ||
categoryListPanel = new CategoryListPanel(categories, expenses); | ||
Platform.runLater(() -> { | ||
try { | ||
ListView<?> categoryListView = (ListView<?>) categoryListPanel.getRoot().lookup("#categoryListView"); | ||
assertEquals(0, categoryListView.getItems().size()); | ||
future.complete(null); | ||
} catch (AssertionFailedError e) { | ||
future.completeExceptionally(e); | ||
} | ||
}); | ||
try { | ||
future.get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
fail("Assertion error thrown in Platform.runLater thread: " + e.getMessage()); | ||
} | ||
} | ||
} |
Oops, something went wrong.