From f3d1ac0fb51b2a6eb9f30472d9d3914e39b32b99 Mon Sep 17 00:00:00 2001 From: Kelly Wong Date: Wed, 6 Nov 2024 00:39:12 +0800 Subject: [PATCH 1/3] Update StatusCommandParserTest --- .../logic/commands/StatusCommandTest.java | 28 ++++++++++++----- .../logic/parser/StatusCommandParserTest.java | 30 +++++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/test/java/seedu/hireme/logic/commands/StatusCommandTest.java b/src/test/java/seedu/hireme/logic/commands/StatusCommandTest.java index 53200e09e29..10e049587bd 100644 --- a/src/test/java/seedu/hireme/logic/commands/StatusCommandTest.java +++ b/src/test/java/seedu/hireme/logic/commands/StatusCommandTest.java @@ -116,25 +116,39 @@ 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 diff --git a/src/test/java/seedu/hireme/logic/parser/StatusCommandParserTest.java b/src/test/java/seedu/hireme/logic/parser/StatusCommandParserTest.java index bf1a8c5886d..6ce05a6c15b 100644 --- a/src/test/java/seedu/hireme/logic/parser/StatusCommandParserTest.java +++ b/src/test/java/seedu/hireme/logic/parser/StatusCommandParserTest.java @@ -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); + } } From 15e3d2a274b4c83b03315821c278a6932c587fa9 Mon Sep 17 00:00:00 2001 From: Kelly Wong Date: Wed, 6 Nov 2024 00:40:46 +0800 Subject: [PATCH 2/3] Fix checkstyle --- .../java/seedu/hireme/logic/commands/StatusCommandTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/hireme/logic/commands/StatusCommandTest.java b/src/test/java/seedu/hireme/logic/commands/StatusCommandTest.java index 10e049587bd..2cc829626e3 100644 --- a/src/test/java/seedu/hireme/logic/commands/StatusCommandTest.java +++ b/src/test/java/seedu/hireme/logic/commands/StatusCommandTest.java @@ -119,7 +119,8 @@ public void equals() { assertTrue(statusFirstCommand.equals(statusFirstCommand), "Same object reference should be equal"); // Test: Different objects with the same values should be equal - assertTrue(statusFirstCommand.equals(statusFirstCommandCopy), "Objects with the same index and status should be equal"); + 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), "Objects of different types should not be equal"); @@ -142,7 +143,8 @@ public void equals() { // 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"); + 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) From 58ef269ad4606ea35fc24287925bf646aeda86dc Mon Sep 17 00:00:00 2001 From: Kelly Wong Date: Wed, 6 Nov 2024 00:53:17 +0800 Subject: [PATCH 3/3] Improve code coverage of StatusCommandParser --- src/main/java/seedu/hireme/logic/commands/StatusCommand.java | 3 +-- .../java/seedu/hireme/logic/parser/StatusCommandParser.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/hireme/logic/commands/StatusCommand.java b/src/main/java/seedu/hireme/logic/commands/StatusCommand.java index 230029f20c9..45a7b303972 100644 --- a/src/main/java/seedu/hireme/logic/commands/StatusCommand.java +++ b/src/main/java/seedu/hireme/logic/commands/StatusCommand.java @@ -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. diff --git a/src/main/java/seedu/hireme/logic/parser/StatusCommandParser.java b/src/main/java/seedu/hireme/logic/parser/StatusCommandParser.java index 3eaf828b0c3..80d43770e56 100644 --- a/src/main/java/seedu/hireme/logic/parser/StatusCommandParser.java +++ b/src/main/java/seedu/hireme/logic/parser/StatusCommandParser.java @@ -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);