Skip to content

Commit

Permalink
Merge pull request #243 from licongshen12/parser-tests
Browse files Browse the repository at this point in the history
Update tests for appointment commands
  • Loading branch information
trgao authored Nov 9, 2023
2 parents 9a48623 + 74f0f3d commit b8ff430
Show file tree
Hide file tree
Showing 18 changed files with 333 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ public CommandResult execute(Model model) {
model.setAddressBook(new AddressBook());
return new CommandResult(MESSAGE_SUCCESS, false, false, false, true);
}

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
return other instanceof ClearCommand;
}
}
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/logic/commands/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ public CommandResult execute(Model model) {
return new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true, false);
}

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
return other instanceof ExitCommand;
}
}
8 changes: 8 additions & 0 deletions src/main/java/seedu/address/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ public class HelpCommand extends Command {
public CommandResult execute(Model model) {
return new CommandResult(SHOWING_HELP_MESSAGE, true, false, false);
}

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
return other instanceof HelpCommand;
}
}
8 changes: 8 additions & 0 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ public CommandResult execute(Model model) {
model.updateFilteredAppointmentList(PREDICATE_SHOW_ALL_APPOINTMENTS);
return new CommandResult(MESSAGE_SUCCESS);
}

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
return other instanceof ListCommand;
}
}
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/logic/commands/ModeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ public CommandResult execute(Model model) {
return new CommandResult(MESSAGE_TOGGLED, false, false, true);
}

@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
return other instanceof ModeCommand;
}
}
19 changes: 19 additions & 0 deletions src/test/java/seedu/address/logic/commands/ClearCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

Expand Down Expand Up @@ -29,4 +31,21 @@ public void execute_nonEmptyAddressBook_success() {
assertCommandSuccess(new ClearCommand(), model, ClearCommand.MESSAGE_SUCCESS, expectedModel);
}

@Test
public void equals() {
ClearCommand firstClearCommand = new ClearCommand();
ClearCommand secondClearCommand = new ClearCommand();

// same object -> returns true
assertTrue(firstClearCommand.equals(firstClearCommand));

// same type -> returns true
assertTrue(firstClearCommand.equals(secondClearCommand));

// different types -> returns false
assertFalse(firstClearCommand.equals(1));

// null -> returns false
assertFalse(firstClearCommand.equals(null));
}
}
20 changes: 20 additions & 0 deletions src/test/java/seedu/address/logic/commands/ExitCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.ExitCommand.MESSAGE_EXIT_ACKNOWLEDGEMENT;

Expand All @@ -17,4 +19,22 @@ public void execute_exit_success() {
CommandResult expectedCommandResult = new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true, false);
assertCommandSuccess(new ExitCommand(), model, expectedCommandResult, expectedModel);
}

@Test
public void equals() {
ExitCommand firstExitCommand = new ExitCommand();
ExitCommand secondExitCommand = new ExitCommand();

// same object -> returns true
assertTrue(firstExitCommand.equals(firstExitCommand));

// same type -> returns true
assertTrue(firstExitCommand.equals(secondExitCommand));

// different types -> returns false
assertFalse(firstExitCommand.equals(1));

// null -> returns false
assertFalse(firstExitCommand.equals(null));
}
}
20 changes: 20 additions & 0 deletions src/test/java/seedu/address/logic/commands/HelpCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.HelpCommand.SHOWING_HELP_MESSAGE;

Expand All @@ -17,4 +19,22 @@ public void execute_help_success() {
CommandResult expectedCommandResult = new CommandResult(SHOWING_HELP_MESSAGE, true, false, false);
assertCommandSuccess(new HelpCommand(), model, expectedCommandResult, expectedModel);
}

@Test
public void equals() {
HelpCommand firstHelpCommand = new HelpCommand();
HelpCommand secondHelpCommand = new HelpCommand();

// same object -> returns true
assertTrue(firstHelpCommand.equals(firstHelpCommand));

// same type -> returns true
assertTrue(firstHelpCommand.equals(secondHelpCommand));

// different types -> returns false
assertFalse(firstHelpCommand.equals(1));

// null -> returns false
assertFalse(firstHelpCommand.equals(null));
}
}
20 changes: 20 additions & 0 deletions src/test/java/seedu/address/logic/commands/ListCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showAppointmentAtIndex;
import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex;
Expand Down Expand Up @@ -43,4 +45,22 @@ public void execute_listIsFiltered_showsEverything() {
showAppointmentAtIndex(model, INDEX_FIRST_APPOINTMENT);
assertCommandSuccess(new ListCommand(), model, ListCommand.MESSAGE_SUCCESS, expectedModel);
}

@Test
public void equals() {
ListCommand firstListCommand = new ListCommand();
ListCommand secondListCommand = new ListCommand();

// same object -> returns true
assertTrue(firstListCommand.equals(firstListCommand));

// same type -> returns true
assertTrue(firstListCommand.equals(secondListCommand));

// different types -> returns false
assertFalse(firstListCommand.equals(1));

// null -> returns false
assertFalse(firstListCommand.equals(null));
}
}
20 changes: 20 additions & 0 deletions src/test/java/seedu/address/logic/commands/ModeCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.ModeCommand.MESSAGE_TOGGLED;

Expand All @@ -17,4 +19,22 @@ public void execute_toggleMode_success() {
CommandResult expectedCommandResult = new CommandResult(MESSAGE_TOGGLED, false, false, true);
assertCommandSuccess(new ModeCommand(), model, expectedCommandResult, expectedModel);
}

@Test
public void equals() {
ModeCommand firstModeCommand = new ModeCommand();
ModeCommand secondModeCommand = new ModeCommand();

// same object -> returns true
assertTrue(firstModeCommand.equals(firstModeCommand));

// same type -> returns true
assertTrue(firstModeCommand.equals(secondModeCommand));

// different types -> returns false
assertFalse(firstModeCommand.equals(1));

// null -> returns false
assertFalse(firstModeCommand.equals(null));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands.appointmentcommands;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showAppointmentAtIndex;
import static seedu.address.testutil.TypicalAppointments.getTypicalAddressBook;
Expand Down Expand Up @@ -33,4 +35,22 @@ public void execute_listIsFiltered_showsEverything() {
showAppointmentAtIndex(model, INDEX_FIRST_APPOINTMENT);
assertCommandSuccess(new AppointmentsCommand(), model, AppointmentsCommand.MESSAGE_SUCCESS, expectedModel);
}

@Test
public void equals() {
AppointmentsCommand firstAppointmentsCommand = new AppointmentsCommand();
AppointmentsCommand secondAppointmentsCommand = new AppointmentsCommand();

// same object -> returns true
assertTrue(firstAppointmentsCommand.equals(firstAppointmentsCommand));

// same type -> returns true
assertTrue(firstAppointmentsCommand.equals(secondAppointmentsCommand));

// different types -> returns false
assertFalse(firstAppointmentsCommand.equals(1));

// null -> returns false
assertFalse(firstAppointmentsCommand.equals(null));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands.appointmentcommands;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showAppointmentAtIndex;
import static seedu.address.testutil.TypicalAppointments.TODAYAPPOINTMENT;
Expand All @@ -23,4 +25,22 @@ public void execute_listIsFiltered_showsAppointmentsOnTodayOnly() {
showAppointmentAtIndex(expectedModel, Index.fromZeroBased(4));
assertCommandSuccess(new TodayCommand(), model, TodayCommand.MESSAGE_SUCCESS, expectedModel);
}

@Test
public void equals() {
TodayCommand firstTodayCommand = new TodayCommand();
TodayCommand secondTodayCommand = new TodayCommand();

// same object -> returns true
assertTrue(firstTodayCommand.equals(firstTodayCommand));

// same type -> returns true
assertTrue(firstTodayCommand.equals(secondTodayCommand));

// different types -> returns false
assertFalse(firstTodayCommand.equals(1));

// null -> returns false
assertFalse(firstTodayCommand.equals(null));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands.appointmentcommands;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showAppointmentAtIndex;
import static seedu.address.testutil.TypicalAppointments.UPCOMINGAPPOINTMENT;
Expand All @@ -23,4 +25,22 @@ public void execute_listIsFiltered_showsAppointmentsOnTodayOnly() {
showAppointmentAtIndex(expectedModel, Index.fromZeroBased(4));
assertCommandSuccess(new UpcomingCommand(), model, UpcomingCommand.MESSAGE_SUCCESS, expectedModel);
}

@Test
public void equals() {
UpcomingCommand firstUpcomingCommand = new UpcomingCommand();
UpcomingCommand secondUpcomingCommand = new UpcomingCommand();

// same object -> returns true
assertTrue(firstUpcomingCommand.equals(firstUpcomingCommand));

// same type -> returns true
assertTrue(firstUpcomingCommand.equals(secondUpcomingCommand));

// different types -> returns false
assertFalse(firstUpcomingCommand.equals(1));

// null -> returns false
assertFalse(firstUpcomingCommand.equals(null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.parser.exceptions.ParseException;

public class ClearCommandParserTest {
private ClearCommandParser parser = new ClearCommandParser();

@Test
public void parse_emptyArgs_returnsClearCommand() throws ParseException {
// No arguments should return a ClearCommand
ClearCommand expectedClearCommand = new ClearCommand();
assertParseSuccess(parser, "", expectedClearCommand);
}

@Test
public void parse_nonEmptyArgs_throwsParseException() {
assertParseFailure(parser, "some random string",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ClearCommand.MESSAGE_USAGE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.parser.exceptions.ParseException;

public class ExitCommandParserTest {
private ExitCommandParser parser = new ExitCommandParser();

@Test
public void parse_emptyArgs_returnsExitCommand() throws ParseException {
// No arguments should return an ExitCommand
ExitCommand expectedExitCommand = new ExitCommand();
assertParseSuccess(parser, "", expectedExitCommand);
}

@Test
public void parse_nonEmptyArgs_throwsParseException() {
assertParseFailure(parser, "some random string",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ExitCommand.MESSAGE_USAGE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.parser.exceptions.ParseException;

public class HelpCommandParserTest {
private HelpCommandParser parser = new HelpCommandParser();

@Test
public void parse_emptyArgs_returnsHelpCommand() throws ParseException {
// No arguments should return a HelpCommand
HelpCommand expectedHelpCommand = new HelpCommand();
assertParseSuccess(parser, "", expectedHelpCommand);
}

@Test
public void parse_nonEmptyArgs_throwsParseException() {
assertParseFailure(parser, "some random string",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE));
}
}
Loading

0 comments on commit b8ff430

Please sign in to comment.