forked from nus-cs2113-AY2425S1/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 #241 from telferang/branch-bug
Branch coding standard and Junit
- Loading branch information
Showing
10 changed files
with
106 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
78 changes: 78 additions & 0 deletions
78
src/test/java/seedu/budgetbuddy/validators/income/DeleteIncomeValidatorTest.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,78 @@ | ||
package seedu.budgetbuddy.validators.income; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import seedu.budgetbuddy.commands.Command; | ||
import seedu.budgetbuddy.commands.income.DeleteIncomeCommand; | ||
import seedu.budgetbuddy.commands.IncorrectCommand; | ||
import seedu.budgetbuddy.transaction.income.Income; | ||
import seedu.budgetbuddy.transaction.income.IncomeManager; | ||
|
||
import java.time.LocalDate; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class DeleteIncomeValidatorTest { | ||
|
||
@Test | ||
void processCommand_outOfRangeIndex_returnsIncorrectIncomeCommand() { | ||
String command = "delete income 10"; | ||
Command result = DeleteIncomeValidator.processCommand(command.trim()); | ||
|
||
assertTrue(result instanceof IncorrectCommand); | ||
assertEquals("Invalid Index", ((IncorrectCommand) result).getFeedbackToUser()); | ||
} | ||
|
||
@Test | ||
void processCommand_noIndexProvided_returnsIncorrectCommandIndexNotGiven() { | ||
String command = "delete income"; | ||
Command result = DeleteIncomeValidator.processCommand(command); | ||
|
||
assertTrue(result instanceof IncorrectCommand); | ||
assertEquals("Index not given", ((IncorrectCommand) result).getFeedbackToUser()); | ||
} | ||
|
||
@Test | ||
void processCommand_invalidIndex_returnsIncorrectCommandInvalidIndex() { | ||
String command = "delete income abc"; | ||
Command result = DeleteIncomeValidator.processCommand(command); | ||
|
||
assertTrue(result instanceof IncorrectCommand); | ||
assertEquals("Invalid Index", ((IncorrectCommand) result).getFeedbackToUser()); | ||
} | ||
|
||
@Test | ||
void processCommand_validIndex_returnsDeleteIncomeCommand() { | ||
IncomeManager.addIncome(new Income("Salary", 5000.00, LocalDate.of(2024, 11, 1))); | ||
IncomeManager.addIncome(new Income("Freelance", 1500.00, LocalDate.of(2024, 11, 5))); | ||
IncomeManager.addIncome(new Income("Bonus", 2000.00, LocalDate.of(2024, 11, 10))); | ||
|
||
String command = "delete income 3"; | ||
Command result = DeleteIncomeValidator.processCommand(command); | ||
|
||
assertTrue(result instanceof DeleteIncomeCommand); | ||
assertEquals(2, ((DeleteIncomeCommand) result).getIndex()); // Expecting index to be 2 due to 0-based indexing | ||
} | ||
|
||
@Test | ||
void processCommand_negativeIndex_returnsIncorrectCommandInvalidIndex() { | ||
String command = "delete income -1"; | ||
Command result = DeleteIncomeValidator.processCommand(command); | ||
|
||
assertTrue(result instanceof IncorrectCommand); | ||
assertEquals("Invalid Index", ((IncorrectCommand) result).getFeedbackToUser()); | ||
} | ||
|
||
@Test | ||
void processCommand_extraSpacesAfterIndex_returnsDeleteIncomeCommand() { | ||
IncomeManager.addIncome(new Income("Salary", 5000.00, LocalDate.of(2024, 11, 1))); | ||
IncomeManager.addIncome(new Income("Freelance", 1500.00, LocalDate.of(2024, 11, 5))); | ||
IncomeManager.addIncome(new Income("Bonus", 2000.00, LocalDate.of(2024, 11, 10))); | ||
|
||
String command = "delete income 3 "; | ||
Command result = DeleteIncomeValidator.processCommand(command.trim()); | ||
|
||
assertTrue(result instanceof DeleteIncomeCommand); | ||
assertEquals(2, ((DeleteIncomeCommand) result).getIndex()); | ||
} | ||
} |
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