Skip to content

Commit 3d0660e

Browse files
authored
Merge pull request nus-cs2103-AY2021S1#94 from luo-git/Branch-OpenCommand
Resolve a bug in the tag command
2 parents 1eeba2f + 4648cb2 commit 3d0660e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/main/java/seedu/address/logic/commands/TagCommand.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package seedu.address.logic.commands;
22

33
import static java.util.Objects.requireNonNull;
4-
import static seedu.address.commons.util.AppUtil.checkArgument;
54
import static seedu.address.logic.parser.CliSyntax.PREFIX_FILE_ADDRESS;
65
import 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
}

src/test/java/seedu/address/logic/commands/TagCommandTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)