55import static seedu .address .logic .parser .CommandParserTestUtil .assertParseSuccess ;
66
77import java .util .ArrayList ;
8+ import java .util .HashSet ;
9+ import java .util .Set ;
810
911import org .junit .jupiter .api .Test ;
1012
1113import seedu .address .logic .commands .FindCommand ;
14+ import seedu .address .model .person .NameContainsKeywordsPredicate ;
1215import seedu .address .model .person .PersonHasTagsAndNamePredicate ;
16+ import seedu .address .model .person .PersonHasTagsPredicate ;
1317import seedu .address .model .tag .Tag ;
1418
1519public class FindCommandParserTest {
@@ -18,7 +22,24 @@ public class FindCommandParserTest {
1822
1923 @ Test
2024 public void parse_emptyArg_throwsParseException () {
21- assertParseFailure (parser , " " , String .format (MESSAGE_INVALID_COMMAND_FORMAT , FindCommand .MESSAGE_USAGE ));
25+ // no arguments
26+ assertParseFailure (parser , " " ,
27+ String .format (MESSAGE_INVALID_COMMAND_FORMAT , FindCommand .MESSAGE_USAGE ));
28+ // name prefix but no name argument
29+ assertParseFailure (parser , " n/" ,
30+ String .format (MESSAGE_INVALID_COMMAND_FORMAT , FindCommand .MESSAGE_USAGE ));
31+ // tag prefix but no tag argument
32+ assertParseFailure (parser , "t/" ,
33+ String .format (MESSAGE_INVALID_COMMAND_FORMAT , FindCommand .MESSAGE_USAGE ));
34+ // name and tag prefix but no name argument
35+ assertParseFailure (parser , " n/ t/tag" ,
36+ String .format (MESSAGE_INVALID_COMMAND_FORMAT , FindCommand .MESSAGE_USAGE ));
37+ // name and tag prefix but no tag argument
38+ assertParseFailure (parser , " n/name t/" ,
39+ String .format (MESSAGE_INVALID_COMMAND_FORMAT , FindCommand .MESSAGE_USAGE ));
40+ // name and tag prefix but no arguments
41+ assertParseFailure (parser , " n/ t/" ,
42+ String .format (MESSAGE_INVALID_COMMAND_FORMAT , FindCommand .MESSAGE_USAGE ));
2243 }
2344
2445 @ Test
@@ -36,29 +57,65 @@ public void parse_validArgs_returnsFindCommand() {
3657 assertParseSuccess (parser , " \n n/Alice \n t/tag\t " , expectedFindCommand );
3758 }
3859
39- //TODO: Fix this test case
40- // @Test
41- // public void parse_multipleNames_returnsFindCommand() {
42- // // no leading and trailing whitespaces
43- // ArrayList<String> nameList = new ArrayList<>();
44- // nameList.add("Alice");
45- // nameList.add("Bob");
46- // nameList.add("Candy");
47- // ArrayList<Tag> tagList = new ArrayList<>();
48- // tagList.add(new Tag("tag"));
49- // FindCommand expectedFindCommand =
50- // new FindCommand(new PersonHasTagsAndNamePredicate(nameList, tagList));
51- // assertParseSuccess(parser, " n/Alice n/Bob n/Candy t/tag", expectedFindCommand);
52- // }
60+ @ Test
61+ public void parse_multipleNamesAndMultipleTags_returnsFindCommand () {
62+ // no leading and trailing whitespaces
63+ Set <String > nameSet = new HashSet <>();
64+ nameSet .add ("Alice" );
65+ nameSet .add ("Bob" );
66+ nameSet .add ("Candy" );
67+ ArrayList <String > nameList = new ArrayList <>(nameSet );
68+ Set <Tag > tagSet = new HashSet <>();
69+ tagSet .add (new Tag ("tag" ));
70+ tagSet .add (new Tag ("person" ));
71+ ArrayList <Tag > tagList = new ArrayList <>(tagSet );
72+ FindCommand expectedFindCommand =
73+ new FindCommand (new PersonHasTagsAndNamePredicate (nameList , tagList ));
74+ assertParseSuccess (parser , " n/Alice n/Bob n/Candy t/tag t/person" , expectedFindCommand );
75+ }
5376
5477 @ Test
5578 public void parse_singleNameAndNoTag_returnsFindCommand () {
5679 // no leading and trailing whitespaces
5780 ArrayList <String > nameList = new ArrayList <>();
5881 nameList .add ("Alice" );
59- ArrayList <Tag > tagList = new ArrayList <>();
6082 FindCommand expectedFindCommand =
61- new FindCommand (new PersonHasTagsAndNamePredicate (nameList , tagList ));
83+ new FindCommand (new NameContainsKeywordsPredicate (nameList ));
6284 assertParseSuccess (parser , " n/Alice " , expectedFindCommand );
6385 }
86+
87+ @ Test
88+ public void parse_multipleNamesAndNoTag_returnsFindCommand () {
89+ // no leading and trailing whitespaces
90+ Set <String > nameSet = new HashSet <>();
91+ nameSet .add ("Alice" );
92+ nameSet .add ("Bob" );
93+ nameSet .add ("Candy" );
94+ ArrayList <String > nameList = new ArrayList <>(nameSet );
95+ FindCommand expectedFindCommand =
96+ new FindCommand (new NameContainsKeywordsPredicate (nameList ));
97+ assertParseSuccess (parser , " n/Alice n/Bob n/Candy" , expectedFindCommand );
98+ }
99+
100+ @ Test
101+ public void parse_noNameAndSingleTag_returnsFindCommand () {
102+ // no leading and trailing whitespaces
103+ ArrayList <Tag > tagList = new ArrayList <>();
104+ tagList .add (new Tag ("tag" ));
105+ FindCommand expectedFindCommand =
106+ new FindCommand (new PersonHasTagsPredicate (tagList ));
107+ assertParseSuccess (parser , " t/tag " , expectedFindCommand );
108+ }
109+
110+ @ Test
111+ public void parse_noNameAndMultipleTags_returnsFindCommand () {
112+ // no leading and trailing whitespaces
113+ Set <Tag > tagSet = new HashSet <>();
114+ tagSet .add (new Tag ("tag" ));
115+ tagSet .add (new Tag ("person" ));
116+ ArrayList <Tag > tagList = new ArrayList <>(tagSet );
117+ FindCommand expectedFindCommand =
118+ new FindCommand (new PersonHasTagsPredicate (tagList ));
119+ assertParseSuccess (parser , " t/tag t/person " , expectedFindCommand );
120+ }
64121}
0 commit comments