Skip to content

Commit

Permalink
added FindNoteCommand testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinran-J committed Oct 27, 2022
1 parent 3d66010 commit 8a56ae9
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class CommandTestUtil {
public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";

public static final String INVALID_NON_MATCHING_NOTE_TITLE = "abcdefghijklmnop";

public static final EditCommand.EditPersonDescriptor DESC_AMY;
public static final EditCommand.EditPersonDescriptor DESC_BOB;
public static final EditNoteCommand.EditNoteDescriptor DESC_MEETING;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.commons.core.Messages.MESSAGE_NOTES_LISTED_OVERVIEW;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_NON_MATCHING_NOTE_TITLE;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalNotes.CHARITY;
import static seedu.address.testutil.TypicalNotes.DONATE;
import static seedu.address.testutil.TypicalNotes.ELECTION;
import static seedu.address.testutil.TypicalNotes.KEYWORD_MATCHING_EVENT;
import static seedu.address.testutil.TypicalNotes.getTypicalAddressBook;

import java.util.Arrays;
import java.util.Collections;

import org.junit.jupiter.api.Test;

import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.note.TitleContainsKeywordsPredicate;

/**
* Contains integration tests (interaction with the Model) for {@code FindNoteCommand}.
*/
public class FindNoteCommandTest {
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());

@Test
public void equals() {
TitleContainsKeywordsPredicate firstPredicate =
new TitleContainsKeywordsPredicate(Collections.singletonList("first"));

TitleContainsKeywordsPredicate secondPredicate =
new TitleContainsKeywordsPredicate(Collections.singletonList("second"));

FindNoteCommand findFirstNoteCommand = new FindNoteCommand(firstPredicate);
FindNoteCommand findSecondNoteCommand = new FindNoteCommand(secondPredicate);

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

// same values -> returns true
FindNoteCommand findFirstNoteCommandCopy = new FindNoteCommand(firstPredicate);
assertTrue(findFirstNoteCommand.equals(findFirstNoteCommandCopy));

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

// null -> returns false
assertFalse(findFirstNoteCommand.equals(null));

// different person -> returns false
assertFalse(findFirstNoteCommand.equals(findSecondNoteCommand));
}

@Test
public void execute_zeroKeywords_noNoteFound() {
String expectedMessage = String.format(MESSAGE_NOTES_LISTED_OVERVIEW, 0);
TitleContainsKeywordsPredicate predicate = preparePredicate(INVALID_NON_MATCHING_NOTE_TITLE);
FindNoteCommand command = new FindNoteCommand(predicate);
expectedModel.updateFilteredNoteList(predicate);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Collections.emptyList(), model.getFilteredNoteList());
}

@Test
public void execute_multipleKeywords_multipleNoteFound() {
String expectedMessage = String.format(MESSAGE_NOTES_LISTED_OVERVIEW, 3);
TitleContainsKeywordsPredicate predicate = preparePredicate(KEYWORD_MATCHING_EVENT);
FindNoteCommand command = new FindNoteCommand(predicate);
expectedModel.updateFilteredNoteList(predicate);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Arrays.asList(CHARITY, DONATE, ELECTION), model.getFilteredNoteList());
}


/**
* Parses {@code userInput} into a {@code TitleContainsKeywordsPredicate}.
*/
private TitleContainsKeywordsPredicate preparePredicate(String userInput) {
return new TitleContainsKeywordsPredicate(Arrays.asList(userInput.split("\\s+")));
}
}
6 changes: 3 additions & 3 deletions src/test/java/seedu/address/testutil/TypicalNotes.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public class TypicalNotes {
public static final Note CHARITY = new NoteBuilder().withTitle("Charity Event")
.withContent("Charity event").withTags("c").build();

public static final Note DONATE = new NoteBuilder().withTitle("Donate")
public static final Note DONATE = new NoteBuilder().withTitle("Donate Event")
.withContent("Donate food").withTags("d").build();

public static final Note ELECTION = new NoteBuilder().withTitle("Election")
public static final Note ELECTION = new NoteBuilder().withTitle("Election Event")
.withContent("Elect new club president").withTags("e").build();

// Manually added
public static final Note FOOTBALL = new NoteBuilder().withTitle("Football Event")
public static final Note FOOTBALL = new NoteBuilder().withTitle("Football")
.withContent("Football practice").build();

// Manually added - Note's details found in {@code CommandTestUtil}
Expand Down

0 comments on commit 8a56ae9

Please sign in to comment.