Skip to content

Commit

Permalink
Merge pull request #206 from woke02/branch-update-status-command-test…
Browse files Browse the repository at this point in the history
…-cases

Update StatusCommandParserTestCase
  • Loading branch information
Raghava-Chittidi authored Nov 6, 2024
2 parents f19c6b0 + 58ef269 commit b53c692
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/main/java/seedu/hireme/logic/commands/StatusCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public class StatusCommand extends Command {
+ " or " + COMMAND_WORD_PENDING + " or " + COMMAND_WORD_REJECT
+ ": Changes the status of the internship application identified by "
+ "the index number used in the displayed list.\n"
+ "Parameters: INDEX (" + MESSAGE_INDEX_CONSTRAINT + ")\n"
+ "Example: " + COMMAND_WORD_ACCEPT + " 5" + " (if total number of applications is <= 5)";
+ "Parameters: INDEX (" + MESSAGE_INDEX_CONSTRAINT + ")\n";

/**
* Message to display upon successful status update.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public StatusCommand parse(String args) throws ParseException {
// Ensure the status is one of the allowed values (PENDING, ACCEPTED, REJECTED)
if (status == null || !(status == Status.PENDING || status == Status.ACCEPTED
|| status == Status.REJECTED)) {
throw new ParseException(Status.MESSAGE_CONSTRAINTS);
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_USAGE));
}

return new StatusCommand(index, status);
Expand Down
30 changes: 23 additions & 7 deletions src/test/java/seedu/hireme/logic/commands/StatusCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,41 @@ public void equals() {
StatusCommand statusFirstCommandCopy = new StatusCommand(INDEX_FIRST_INTERNSHIP_APPLICATION, Status.ACCEPTED);

// Test: Same object reference should be equal
assertTrue(statusFirstCommand.equals(statusFirstCommand));
assertTrue(statusFirstCommand.equals(statusFirstCommand), "Same object reference should be equal");

// Test: Different objects with the same values should be equal
assertTrue(statusFirstCommand.equals(statusFirstCommandCopy));
assertTrue(statusFirstCommand.equals(statusFirstCommandCopy),
"Objects with the same index and status should be equal");

// Test: Different types should not be equal
assertFalse(statusFirstCommand.equals(1));
assertFalse(statusFirstCommand.equals(1), "Objects of different types should not be equal");

// Test: Null should not be equal
assertFalse(statusFirstCommand.equals(null));
assertFalse(statusFirstCommand.equals(null), "Comparison with null should return false");

// Test: Objects with different indices should not be equal
StatusCommand statusSecondCommand = new StatusCommand(INDEX_SECOND_INTERNSHIP_APPLICATION, Status.ACCEPTED);
assertFalse(statusFirstCommand.equals(statusSecondCommand));
StatusCommand statusSecondCommand =
new StatusCommand(INDEX_SECOND_INTERNSHIP_APPLICATION, Status.ACCEPTED);
assertFalse(statusFirstCommand.equals(statusSecondCommand),
"Objects with different indices should not be equal");

// Test: Objects with the same index but different statuses should not be equal
StatusCommand statusDifferentStatusCommand =
new StatusCommand(INDEX_FIRST_INTERNSHIP_APPLICATION, Status.PENDING);
assertFalse(statusFirstCommand.equals(statusDifferentStatusCommand));
assertFalse(statusFirstCommand.equals(statusDifferentStatusCommand),
"Objects with the same index but different statuses should not be equal");

// Test: Objects with different indices and different statuses should not be equal
StatusCommand completelyDifferentCommand =
new StatusCommand(INDEX_SECOND_INTERNSHIP_APPLICATION, Status.REJECTED);
assertFalse(statusFirstCommand.equals(completelyDifferentCommand),
"Objects with different indices and statuses should not be equal");

// Test: Ensure reflexive, symmetric, and transitive properties
assertTrue(statusFirstCommand.equals(statusFirstCommandCopy)
&& statusFirstCommandCopy.equals(statusFirstCommand),
"Equality should be symmetric");
assertTrue(statusFirstCommand.equals(statusFirstCommandCopy), "Equality should be reflexive");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,34 @@ public void parse_extraWhitespaceValidArgs_returnsStatusCommand() {
assertParseSuccess(parser, " 1 ",
new StatusCommand(INDEX_FIRST_INTERNSHIP_APPLICATION, Status.ACCEPTED));
}

@Test
public void parse_nullStatus_throwsParseException() {
// Create the parser with null status
StatusCommandParser parser = new StatusCommandParser(null);

// Ensure the parser throws ParseException with the correct message
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_USAGE);
assertParseFailure(parser, "1", expectedMessage);
}

@Test
public void parse_invalidStatus_throwsParseException() {
// Create a parser with a valid status but simulate an invalid scenario
StatusCommandParser parser = new StatusCommandParser(null);

// Ensure the parser throws ParseException with the correct message
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_USAGE);
assertParseFailure(parser, "1", expectedMessage);
}

@Test
public void parse_nonNumericIndex_throwsParseException() {
// Create the parser with a valid status 'PENDING'
StatusCommandParser parser = new StatusCommandParser(Status.PENDING);

// Ensure the parser throws ParseException for non-numeric index
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_USAGE);
assertParseFailure(parser, "abc", expectedMessage);
}
}

0 comments on commit b53c692

Please sign in to comment.