Skip to content

Commit

Permalink
Add tests for BookingCommandParser
Browse files Browse the repository at this point in the history
  • Loading branch information
moguries committed Apr 7, 2024
1 parent e0e72a7 commit a515015
Show file tree
Hide file tree
Showing 2 changed files with 433 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/main/java/housekeeping/hub/logic/commands/BookingCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,24 @@ private CommandResult housekeeperSearch(Model model) throws CommandException {
}
}

/**
* Checks that BookingCommand has no bookedDateAndTime initialised.
*
* @return True if there is no booked date and time, false otherwise
*/
public boolean hasNoBookedDateAndTime() {
return bookedDateAndTime == null;
}

/**
* Checks that BookingCommand has no Index initialised.
*
* @return True if there is no Index, false otherwise
*/
public boolean hasNoIndex() {
return index == null;
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -435,10 +453,24 @@ public boolean equals(Object other) {
}

BookingCommand otherBookingCommand = (BookingCommand) other;
return actionWord.equals(otherBookingCommand.actionWord)
&& index.equals(otherBookingCommand.index)
&& (bookingToDeleteIndex == otherBookingCommand.bookingToDeleteIndex)
&& bookedDateAndTime.equals(otherBookingCommand.bookedDateAndTime);

// for housekeeper search
if (this.hasNoIndex() && otherBookingCommand.hasNoIndex()
&& this.hasNoBookedDateAndTime() && otherBookingCommand.hasNoBookedDateAndTime()) {
return actionWord.equals(otherBookingCommand.actionWord)
&& (bookingToDeleteIndex == otherBookingCommand.bookingToDeleteIndex)
&& bookingSearchPredicate.equals(otherBookingCommand.bookingSearchPredicate);
// for housekeeper delete
} else if (this.hasNoBookedDateAndTime() && otherBookingCommand.hasNoBookedDateAndTime()) {
return actionWord.equals(otherBookingCommand.actionWord)
&& index.equals(otherBookingCommand.index)
&& (bookingToDeleteIndex == otherBookingCommand.bookingToDeleteIndex);
} else {
return actionWord.equals(otherBookingCommand.actionWord)
&& index.equals(otherBookingCommand.index)
&& (bookingToDeleteIndex == otherBookingCommand.bookingToDeleteIndex)
&& bookedDateAndTime.equals(otherBookingCommand.bookedDateAndTime);
}
}

@Override
Expand Down
Loading

0 comments on commit a515015

Please sign in to comment.