Skip to content

Commit

Permalink
Add FindScheduleCommandParserTest
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjinius committed Apr 3, 2024
1 parent 6c2e562 commit f351924
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Parses input arguments and creates a new FindScheduleCommand object
*/
public class FindScheduleCommandParser {
public class FindScheduleCommandParser implements Parser<FindScheduleCommand> {
/**
* Parses the given {@code String} of arguments in the context of the FindScheduleCommand
* and returns a FindCScheduleCommand object for execution.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"schedules" : [{
"schedules" : [ {
"title" : "Meeting",
"description" : "Meeting with supervisor",
"startDateTime" : "2024-03-10 16:00",
Expand All @@ -24,5 +24,5 @@
"description" : "Discuss project progress",
"startDateTime" : "2024-03-14 10:00",
"endDateTime" : "2024-03-14 11:00"
}]
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class FindCommandParserTest {

private FindCommandParser parser = new FindCommandParser();
private final FindCommandParser parser = new FindCommandParser();

@Test
public void parse_emptyArg_throwsParseException() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package scm.address.logic.parser;

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

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;

import org.junit.jupiter.api.Test;

import scm.address.logic.commands.FindScheduleCommand;
import scm.address.model.schedule.AfterDateTimePredicate;
import scm.address.model.schedule.BeforeDateTimePredicate;
import scm.address.model.schedule.DescriptionContainsKeywordsPredicate;
import scm.address.model.schedule.DuringDateTimePredicate;
import scm.address.model.schedule.TitleContainsKeywordsPredicate;



public class FindScheduleCommandParserTest {
private final FindScheduleCommandParser parser = new FindScheduleCommandParser();

@Test
public void parse_emptyArg_throwsParseException() {
assertParseFailure(parser, " ",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindScheduleCommand.MESSAGE_USAGE));
}

@Test
public void parse_validArgs_returnsFindScheduleCommand() {
// no leading and trailing whitespaces
FindScheduleCommand expectedFindScheduleCommand =
new FindScheduleCommand(new TitleContainsKeywordsPredicate(Arrays.asList("meeting", "lesson")),
new DescriptionContainsKeywordsPredicate(Collections.emptyList()),
new BeforeDateTimePredicate(Optional.of(LocalDateTime.of(2024, 5, 7, 0, 0))),
new AfterDateTimePredicate(Optional.of(LocalDateTime.of(2024, 4, 30, 12, 0))),
new DuringDateTimePredicate(Optional.empty()));
assertParseSuccess(parser, " title/meeting lesson before/2024-05-07 00:00 after/2024-04-30 12:00",
expectedFindScheduleCommand);

// multiple whitespaces between keywords
assertParseSuccess(parser,
" \n title/meeting \t lesson \n before/2024-05-07 \n 00:00 \t after/2024-04-30 \t 12:00",
expectedFindScheduleCommand);
}
}

0 comments on commit f351924

Please sign in to comment.