Skip to content

Commit

Permalink
Merge pull request #173 from shaowi/find-command-test
Browse files Browse the repository at this point in the history
Add more find command test
  • Loading branch information
hingen authored Mar 22, 2023
2 parents 24148e0 + ff6d9b6 commit 9500f81
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
13 changes: 8 additions & 5 deletions src/test/java/seedu/address/logic/commands/FindCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
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.TypicalLectures.CS2040S_WEEK_1;
import static seedu.address.testutil.TypicalModules.CS2040S;
import static seedu.address.testutil.TypicalModules.ST2334;
import static seedu.address.testutil.TypicalModules.getTypicalTracker;

import java.util.Arrays;
Expand All @@ -24,16 +21,22 @@
import seedu.address.model.lecture.ReadOnlyLecture;
import seedu.address.model.module.CodeContainsKeywordsPredicate;
import seedu.address.model.module.LectureNameContainsKeywordsPredicate;
import seedu.address.model.module.Module;
import seedu.address.model.module.ModuleCode;
import seedu.address.model.module.ReadOnlyModule;
import seedu.address.model.module.VideoNameContainsKeywordsPredicate;
import seedu.address.testutil.LectureBuilder;
import seedu.address.testutil.ModuleBuilder;
import seedu.address.testutil.TypicalLectures;
import seedu.address.testutil.TypicalModules;

/**
* Contains integration tests (interaction with the Model) for {@code FindCommand}.
*/
public class FindCommandTest {
private static final Module CS2040S = TypicalModules.getCs2040s();
private static final Module ST2334 = TypicalModules.getSt2334();

private Model model = new ModelManager(getTypicalTracker(), new UserPrefs());
private Model expectedModel = new ModelManager(getTypicalTracker(), new UserPrefs());

Expand Down Expand Up @@ -78,7 +81,7 @@ public void execute_zeroKeywords_noLecturesFound() {
String expectedMessage = String.format(Messages.MESSAGE_LECTURES_LISTED_OVERVIEW, 0);
LectureNameContainsKeywordsPredicate predicate =
(LectureNameContainsKeywordsPredicate) preparePredicate(" ", Level.LECTURE);
ReadOnlyModule module = new ModuleBuilder(CS2040S).build();
ReadOnlyModule module = new ModuleBuilder().build();
ModuleCode moduleCode = module.getCode();
expectedModel.updateFilteredLectureList(predicate, module);
FindCommand command = new FindCommand(Collections.emptyList(), moduleCode);
Expand All @@ -93,7 +96,7 @@ public void execute_zeroKeywords_noVideosFound() {
VideoNameContainsKeywordsPredicate predicate =
(VideoNameContainsKeywordsPredicate) preparePredicate(" ", Level.VIDEO);
ReadOnlyModule module = new ModuleBuilder(CS2040S).build();
ReadOnlyLecture lecture = new LectureBuilder(CS2040S_WEEK_1).build();
ReadOnlyLecture lecture = new LectureBuilder(TypicalLectures.getCs2040sWeek1()).build();
expectedModel.updateFilteredVideoList(predicate, lecture);
FindCommand command = new FindCommand(Collections.emptyList(), module.getCode(), lecture.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class ListCommandTest {

private ListCommand listCommand;

private final Module existingModule = TypicalModules.CS2040S;
private final Module existingModule = TypicalModules.getCs2040s();
private final ModuleCode existingModuleCode = existingModule.getCode();
private final Lecture existingLecture = TypicalLectures.CS2040S_WEEK_1;
private final Lecture existingLecture = TypicalLectures.getCs2040sWeek1();
private final LectureName existingLectureName = existingLecture.getName();

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_LECTURE_NAME_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_MODULE_CODE_DESC;
import static seedu.address.logic.commands.CommandTestUtil.MODULE_CODE_DESC_2103;
import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY;
import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_WHITESPACE;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;

Expand All @@ -9,25 +14,40 @@
import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.FindCommand;
import seedu.address.model.lecture.LectureName;
import seedu.address.model.module.ModuleCode;

public class FindCommandParserTest {

private FindCommandParser parser = new FindCommandParser();

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

@Test
public void parse_validArgs_returnsFindCommand() {
// no leading and trailing whitespaces
FindCommand expectedFindCommand =
new FindCommand(Arrays.asList("Alice", "Bob"));
assertParseSuccess(parser, "Alice Bob", expectedFindCommand);
new FindCommand(Arrays.asList("CS2040S", "ST2334"));
assertParseSuccess(parser, "CS2040S ST2334", expectedFindCommand);

// multiple whitespaces between keywords
assertParseSuccess(parser, " \n Alice \n \t Bob \t", expectedFindCommand);
assertParseSuccess(parser, " \n CS2040S \n \t ST2334 \t", expectedFindCommand);
}

@Test
public void parse_invalidArgs_throwsParseException() {
String invalidFormat = String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindCommand.MESSAGE_USAGE);

// No empty keywords
assertParseFailure(parser, PREAMBLE_WHITESPACE, invalidFormat);

// Keyword present, missing module code and invalid lecture name format
assertParseFailure(parser, PREAMBLE_NON_EMPTY + INVALID_LECTURE_NAME_DESC, invalidFormat);

// Keyword present, invalid module code format
assertParseFailure(parser, PREAMBLE_NON_EMPTY + INVALID_MODULE_CODE_DESC, ModuleCode.MESSAGE_CONSTRAINTS);

// Keyword present, valid module code present but invalid lecture name format
assertParseFailure(parser,
PREAMBLE_NON_EMPTY + MODULE_CODE_DESC_2103 + INVALID_LECTURE_NAME_DESC,
LectureName.MESSAGE_CONSTRAINTS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void parse_validArgs_success() {
public void parse_invalidArgs_throwsParseException() {
String invalidFormat = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE);

// Invalid args
// Has args
assertParseFailure(parser, PREAMBLE_NON_EMPTY, invalidFormat);

// Missing module code and invalid lecture name format
Expand Down

0 comments on commit 9500f81

Please sign in to comment.