File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed
main/java/seedu/address/logic/commands
test/java/seedu/address/logic/commands Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 11package seedu .address .logic .commands ;
22
33import static java .util .Objects .requireNonNull ;
4- import static seedu .address .commons .util .AppUtil .checkArgument ;
54import static seedu .address .logic .parser .CliSyntax .PREFIX_FILE_ADDRESS ;
65import static seedu .address .logic .parser .CliSyntax .PREFIX_TAG_NAME ;
76
@@ -39,9 +38,6 @@ public class TagCommand extends Command {
3938 */
4039 public TagCommand (Tag tag ) {
4140 requireNonNull (tag );
42- // Check if file is present
43- checkArgument (filePresent (tag .getFileAddress ()),
44- String .format (MESSAGE_FILE_NOT_FOUND , tag .getFileAddress ().value ));
4541 toTag = tag ;
4642 }
4743
@@ -65,6 +61,12 @@ public CommandResult execute(Model model) throws CommandException {
6561 throw new CommandException (MESSAGE_DUPLICATE_TAG );
6662 }
6763
64+ // Check if file is present
65+ if (!filePresent (toTag .getFileAddress ())) {
66+ throw new CommandException (
67+ String .format (MESSAGE_FILE_NOT_FOUND , toTag .getFileAddress ().value ));
68+ }
69+
6870 model .addTag (toTag );
6971 return new CommandResult (String .format (MESSAGE_SUCCESS , toTag ));
7072 }
Original file line number Diff line number Diff line change @@ -38,7 +38,10 @@ public void execute_tagAcceptedByModel_tagSuccessful() throws Exception {
3838 @ Test
3939 public void execute_tagAddressFileNotFound_throwsCommandException () {
4040 Tag tagInvalidAddress = new TagBuilder ().withFileAddress ("./somewhereOverTheRainbow" ).build ();
41- assertThrows (IllegalArgumentException .class , () -> new TagCommand (tagInvalidAddress ));
41+ Tag validTag = new TagBuilder ().build ();
42+ TagCommand tagCommand = new TagCommand (tagInvalidAddress );
43+ ModelStub modelStub = new ModelStubWithTag (validTag );
44+ assertThrows (CommandException .class , () -> tagCommand .execute (modelStub ));
4245 }
4346
4447 @ Test
You can’t perform that action at this time.
0 commit comments