Skip to content

Commit

Permalink
Update JUnit Test And Developer Guide For Edit Command
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronxujiachen committed Nov 13, 2023
1 parent 483da5c commit 19381dc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
39 changes: 39 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,45 @@ and modifications.
The following sequence diagram shows how the view transaction operation works:
<img src="images/ViewSequenceDiagram.png" width="600" />

### `edit` Transaction Feature

#### I. Architecture-Level Design
This section details the components involved in the `edit` transaction feature:
1. **Parser**: Interprets user input and creates an `EditCommand` object with the appropriate parameters.
2. **EditCommand**: Inherits from the `Command` class, encapsulating the "edit" action along with the index and the new transaction details.
3. **Nuscents**: The main class that invokes the `execute()` method of `EditCommand`.
4. **TransactionList**: Manages a collection of transactions and facilitates the replacement of a specific transaction.
5. **Transaction**: The superclass for different types of transactions such as `Expense` and `Allowance`.
6. **UI**: Manages interactions with the user and displays messages regarding the editing process.

#### II. Component-Level Design
Here's how each component plays a role in the `edit` transaction feature:
1. **Parser**: Extracts the index and transaction details from the input and uses other parsing methods to create a `Transaction` object.
2. **EditCommand**: Contains the logic to replace an existing transaction in the `TransactionList`.
3. **Nuscents**: Calls the `execute()` method of `EditCommand` and handles exceptions that may arise.
4. **TransactionList**: Provides the `editTransaction(index, transaction)` method to update transactions at a specific index.
5. **Transaction**: Abstract representation of a financial record that can be edited.
6. **UI**: Outputs the result of the edit operation and any error messages.

#### III. Alternatives Considered
An alternative design considered was to have `EditCommand` interact directly with `Transaction` objects to modify their fields. However, this approach was discarded in favor of having a clear separation where `TransactionList` manages all transactions, maintaining encapsulation and single responsibility principles.

#### IV. Usage Scenario Example
**Step 1**: User starts the application, and `TransactionList` is initialized with existing transactions.

**Step 2**: The user inputs `edit 2 expense /amt 100 /date 01-01-2023 /desc Movie night`. The `Parser` reads the input, separating the index from the rest of the transaction details.

**Step 3**: `Parser` calls `parseExpense` to create an `Expense` object and then constructs an `EditCommand` with the index and the new `Expense`.

**Step 4**: `Nuscents` receives and invokes the `EditCommand`'s `execute()` method.

**Step 5**: Inside `execute()`, `EditCommand` uses `TransactionList`'s `editTransaction(index, transaction)` to replace the existing transaction.

**Step 6**: `TransactionList` updates the transaction at the given index. If the index is invalid, an exception is thrown.

**Step 7**: Upon successful update, `UI` displays a confirmation message. If an error occurs, an error message is shown instead.


### `helpCommand` Feature

#### I. Architecture-Level Design
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/nuscents/ui/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class Messages {
public static final String MESSAGE_INVALID_INDEX = "OOPS!!! This is an invalid transaction index.";
public static final String MESSAGE_INVALID_INDEX_ARGUMENTS = "OOPS!!! The input should consist only of digits.";
public static final String MESSAGE_EMPTY_LIST = "You have not made any transactions!";
public static final String MESSAGE_EMPTY_KEYWORD = "OOPS!!! The keyword of a find command cannot be empty.";
public static final String MESSAGE_EMPTY_BUDGET = "OOPS!!! The budget amount cannot be empty.";
public static final String MESSAGE_INVALID_BUDGET = "OOPS!!! The budget amount requires a +ve valid float value";
public static final String MESSAGE_INVALID_BUDGET_FLOAT_DP = "OOPS!!! The budget amount cannot exceed 2 d.p.";
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/seedu/nuscents/parser/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,17 @@ public void parseFilterCategory_invalidCategory_exceptionThrown() throws Nuscent
assertEquals(Messages.MESSAGE_UNKNOWN_FILTER_CATEGORY, exception.getMessage());
}

@Test
public void parseEdit_emptyArguments_exceptionThrown() {
String input = "edit 2";
Exception exception = assertThrows(NuscentsException.class, () -> {
Parser.parseEdit(input);
});
assertEquals(Messages.MESSAGE_EMPTY_EDIT, exception.getMessage());
}



@Test
public void parseCommand_helpCommandWithCorrectInput_returnsHelpCommand() throws Exception {
Command result = Parser.parseCommand("help", null);
Expand Down

0 comments on commit 19381dc

Please sign in to comment.