diff --git a/src/main/java/seedu/address/logic/commands/AddFeedCommand.java b/src/main/java/seedu/address/logic/commands/AddFeedCommand.java new file mode 100644 index 00000000000..c8ae1074c99 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/AddFeedCommand.java @@ -0,0 +1,57 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; + +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.feed.Feed; + +/** + * Adds a feed to the feed list. + */ +public class AddFeedCommand extends Command { + + public static final String COMMAND_WORD = "addfeed"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a feed to the feed list." + + "Parameters: " + + PREFIX_NAME + "NAME " + + PREFIX_ADDRESS + "ADDRESS " + + "Example: " + COMMAND_WORD + " " + + PREFIX_NAME + "Ladyironchef " + + PREFIX_ADDRESS + "https://www.ladyironchef.com/feed/"; + + public static final String MESSAGE_SUCCESS = "New feed added: %1$s"; + public static final String MESSAGE_DUPLICATE_FEED = "This feed already exists in the feed list."; + + private final Feed toAdd; + + /** + * Creates an AddFeedCommand to add the specified {@code Feed} + */ + public AddFeedCommand(Feed feed) { + requireNonNull(feed); + toAdd = feed; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + + if (model.hasFeed(toAdd)) { + throw new CommandException(MESSAGE_DUPLICATE_FEED); + } + + model.addFeed(toAdd); + return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof AddFeedCommand // instanceof handles nulls + && toAdd.equals(((AddFeedCommand) other).toAdd)); + } +} diff --git a/src/main/java/seedu/address/logic/commands/DeleteFeedCommand.java b/src/main/java/seedu/address/logic/commands/DeleteFeedCommand.java new file mode 100644 index 00000000000..2a6a4793c7f --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/DeleteFeedCommand.java @@ -0,0 +1,57 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; + +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.feed.Feed; + +/** + * Deletes a feed identified using its name from the feed list. + */ +public class DeleteFeedCommand extends Command { + + public static final String COMMAND_WORD = "deletefeed"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Deletes the feed identified using its name from the feed list.\n" + + "Parameters: " + PREFIX_NAME + " NAME" + + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + " Seth Lui"; + + public static final String MESSAGE_DELETE_FEED_SUCCESS = "Deleted feed: %1$s"; + public static final String MESSAGE_MISSING_FEED = "Feed does not exist in feed list."; + + private final String name; + + public DeleteFeedCommand(String name) { + this.name = name; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + + Feed feedToDelete = null; + for (Feed f : model.getFeedList().getFeedList()) { + if (f.getName().equals(name)) { + feedToDelete = f; + break; + } + } + + if (feedToDelete == null) { + throw new CommandException(MESSAGE_MISSING_FEED); + } + + model.deleteFeed(feedToDelete); + return new CommandResult(String.format(MESSAGE_DELETE_FEED_SUCCESS, feedToDelete)); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof DeleteFeedCommand // instanceof handles nulls + && name.equals(((DeleteFeedCommand) other).name)); // state check + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddFeedCommandParser.java b/src/main/java/seedu/address/logic/parser/AddFeedCommandParser.java new file mode 100644 index 00000000000..bcdf1e3ea5f --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/AddFeedCommandParser.java @@ -0,0 +1,48 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; + +import java.util.stream.Stream; + +import seedu.address.logic.commands.AddFeedCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.feed.Feed; + +/** + * Parses input arguments and creates a new AddFeedCommand object + */ +public class AddFeedCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the AddFeedCommand + * and returns an AddFeedCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public AddFeedCommand parse(String args) throws ParseException { + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_ADDRESS); + + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS) + || !argMultimap.getPreamble().isEmpty()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddFeedCommand.MESSAGE_USAGE)); + } + + String name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()).fullName; + String address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()).value; + + Feed feed = new Feed(name, address); + + return new AddFeedCommand(feed); + } + + /** + * Returns true if none of the prefixes contains empty {@code Optional} values in the given + * {@code ArgumentMultimap}. + */ + private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { + return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); + } + +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 59def15db17..4b2455079ba 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -7,10 +7,12 @@ import java.util.regex.Pattern; import seedu.address.logic.commands.AddCommand; +import seedu.address.logic.commands.AddFeedCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.CloseCommand; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.commands.DeleteFeedCommand; import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.ExitCommand; import seedu.address.logic.commands.FindCommand; @@ -81,6 +83,12 @@ public Command parseCommand(String userInput) throws ParseException { case ReviewCommand.COMMAND_WORD: return new ReviewCommandParser().parse(arguments); + case AddFeedCommand.COMMAND_WORD: + return new AddFeedCommandParser().parse(arguments); + + case DeleteFeedCommand.COMMAND_WORD: + return new DeleteFeedCommandParser().parse(arguments); + default: throw new ParseException(MESSAGE_UNKNOWN_COMMAND); } diff --git a/src/main/java/seedu/address/logic/parser/DeleteFeedCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteFeedCommandParser.java new file mode 100644 index 00000000000..fd52c49e673 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/DeleteFeedCommandParser.java @@ -0,0 +1,43 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; + +import java.util.stream.Stream; + +import seedu.address.logic.commands.DeleteFeedCommand; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new DeleteFeedCommand object + */ +public class DeleteFeedCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the DeleteFeedCommand + * and returns an DeleteFeedCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public DeleteFeedCommand parse(String args) throws ParseException { + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_NAME); + + if (!arePrefixesPresent(argMultimap, PREFIX_NAME) + || !argMultimap.getPreamble().isEmpty()) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteFeedCommand.MESSAGE_USAGE)); + } + + String name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()).fullName; + + return new DeleteFeedCommand(name); + } + + /** + * Returns true if none of the prefixes contains empty {@code Optional} values in the given + * {@code ArgumentMultimap}. + */ + private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { + return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); + } + +} diff --git a/src/main/java/seedu/address/ui/FeedPostListPanel.java b/src/main/java/seedu/address/ui/FeedPostListPanel.java index d8341c4c84c..5225489b049 100644 --- a/src/main/java/seedu/address/ui/FeedPostListPanel.java +++ b/src/main/java/seedu/address/ui/FeedPostListPanel.java @@ -1,9 +1,13 @@ package seedu.address.ui; +import java.util.List; +import java.util.Objects; import java.util.logging.Logger; +import java.util.stream.Collectors; import javafx.application.Platform; import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.ListCell; @@ -31,8 +35,43 @@ public FeedPostListPanel(ReadOnlyFeedList feedList) { feedPostListView.setItems(feedPostList); feedPostListView.setCellFactory(listView -> new FeedPostListViewCell()); + fetchPosts(feedPostList, feedList.getFeedList()); + + ObservableList observableFeedList = feedList.getFeedList(); + ListChangeListener listener = change -> updatePosts(feedPostList, change); + observableFeedList.addListener(listener); + } + + /** + * Detects the changes made in a `ListChangeListener.Change` object and updates the post list accordingly. + * If feeds are added, trigger a thread to fetch its posts. If feeds are removed, remove all its posts from the + * feed list. + * @param feedPostList Observable list of feed posts + * @param change Object representing a change in the feed list + */ + private void updatePosts(ObservableList feedPostList, ListChangeListener.Change change) { + change.next(); + List added = change.getAddedSubList().stream().filter(Objects::nonNull).collect(Collectors.toList()); + List removed = change.getRemoved().stream().filter(Objects::nonNull).collect(Collectors.toList()); + + if (added.size() > 0) { + fetchPosts(feedPostList, added); + } + if (removed.size() > 0) { + for (Feed f : removed) { + feedPostList.removeIf(feedPost -> feedPost.getSource().equals(f.getName())); + } + } + } + + /** + * Fires off a thread that fetches posts from a list of feeds and adds them to the post list. + * @param feedPostList Observable list of feed posts. + * @param feedList List of input feeds. + */ + private void fetchPosts(ObservableList feedPostList, List feedList) { Runnable feedPostFetch = () -> { - for (Feed feed : feedList.getFeedList()) { + for (Feed feed : feedList) { ObservableList feedPosts = feed.fetchPosts(); Platform.runLater(() -> { feedPostList.addAll(feedPosts); diff --git a/src/test/java/seedu/address/logic/commands/AddFeedCommandTest.java b/src/test/java/seedu/address/logic/commands/AddFeedCommandTest.java new file mode 100644 index 00000000000..ed68d029f5c --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/AddFeedCommandTest.java @@ -0,0 +1,46 @@ +package seedu.address.logic.commands; + +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalEateries.getTypicalAddressBook; +import static seedu.address.testutil.TypicalFeeds.getTypicalFeedList; + +import org.junit.jupiter.api.BeforeEach; +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.feed.Feed; +import seedu.address.testutil.FeedBuilder; + +/** + * Contains integration tests (interaction with the Model) for {@code AddFeedCommand}. + */ +public class AddFeedCommandTest { + + private Model model; + + @BeforeEach + public void setUp() { + model = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs()); + } + + @Test + public void execute_newFeed_success() { + Feed validFeed = new FeedBuilder().build(); + + Model expectedModel = new ModelManager(model.getAddressBook(), model.getFeedList(), new UserPrefs()); + expectedModel.addFeed(validFeed); + + assertCommandSuccess(new AddFeedCommand(validFeed), model, + String.format(AddFeedCommand.MESSAGE_SUCCESS, validFeed), expectedModel); + } + + @Test + public void execute_duplicateFeed_throwsCommandException() { + Feed feedInFeedList = model.getFeedList().getFeedList().get(0); + + assertCommandFailure(new AddFeedCommand(feedInFeedList), model, AddFeedCommand.MESSAGE_DUPLICATE_FEED); + } +} diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 074f67000e9..0044b9c8140 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -43,6 +43,13 @@ public class CommandTestUtil { public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + " " + VALID_TAG_HUSBAND; public static final String CATEGORY_DESC = " " + PREFIX_CATEGORY + " " + VALID_CATEGORY; + public static final String VALID_NAME_EATBOOK = "Eatbook"; + public static final String VALID_NAME_SETHLUI = "Seth Lui"; + public static final String VALID_ADDRESS_EATBOOK = "https://eatbook.sg/feed"; + public static final String VALID_ADDRESS_SETHLUI = "https://sethlui.com/feed"; + public static final String NAME_DESC_EATBOOK = " " + PREFIX_NAME + " " + VALID_NAME_EATBOOK; + public static final String ADDRESS_DESC_EATBOOK = " " + PREFIX_ADDRESS + " " + VALID_ADDRESS_EATBOOK; + public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + " James&"; // '&' not allowed in names public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + " hubby*"; // '*' not allowed in tags @@ -70,7 +77,7 @@ public class CommandTestUtil { * - the {@code actualModel} matches {@code expectedModel} */ public static void assertCommandSuccess(Command command, Model actualModel, CommandResult expectedCommandResult, - Model expectedModel) { + Model expectedModel) { try { CommandResult result = command.execute(actualModel); assertEquals(expectedCommandResult, result); @@ -85,7 +92,7 @@ public static void assertCommandSuccess(Command command, Model actualModel, Comm * that takes a string {@code expectedMessage}. */ public static void assertCommandSuccess(Command command, Model actualModel, String expectedMessage, - Model expectedModel) { + Model expectedModel) { CommandResult expectedCommandResult = new CommandResult(expectedMessage); assertCommandSuccess(command, actualModel, expectedCommandResult, expectedModel); } diff --git a/src/test/java/seedu/address/logic/commands/DeleteFeedCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteFeedCommandTest.java new file mode 100644 index 00000000000..5d82d33bbcb --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/DeleteFeedCommandTest.java @@ -0,0 +1,42 @@ +package seedu.address.logic.commands; + +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalEateries.getTypicalAddressBook; +import static seedu.address.testutil.TypicalFeeds.getTypicalFeedList; + +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.feed.Feed; + +/** + * Contains integration tests (interaction with the Model) for {@code DeleteFeedCommand}. + */ +public class DeleteFeedCommandTest { + + private Model model = new ModelManager(getTypicalAddressBook(), getTypicalFeedList(), new UserPrefs()); + + @Test + public void execute_validName_success() { + Feed feedToDelete = model.getFeedList().getFeedList().get(0); + DeleteFeedCommand deleteCommand = new DeleteFeedCommand(feedToDelete.getName()); + + String expectedMessage = String.format(DeleteFeedCommand.MESSAGE_DELETE_FEED_SUCCESS, feedToDelete); + + ModelManager expectedModel = new ModelManager(model.getAddressBook(), model.getFeedList(), new UserPrefs()); + expectedModel.deleteFeed(feedToDelete); + + assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_invalidName_throwsCommandException() { + String invalidName = "Invalid Name"; + DeleteFeedCommand deleteCommand = new DeleteFeedCommand(invalidName); + + assertCommandFailure(deleteCommand, model, DeleteFeedCommand.MESSAGE_MISSING_FEED); + } +} diff --git a/src/test/java/seedu/address/logic/parser/AddFeedCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddFeedCommandParserTest.java new file mode 100644 index 00000000000..9c300860fcb --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/AddFeedCommandParserTest.java @@ -0,0 +1,39 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_EATBOOK; +import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_EATBOOK; +import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_EATBOOK; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_EATBOOK; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.AddFeedCommand; +import seedu.address.model.feed.Feed; +import seedu.address.testutil.FeedBuilder; + +public class AddFeedCommandParserTest { + private AddFeedCommandParser parser = new AddFeedCommandParser(); + + @Test + public void parse_allFieldsPresent_success() { + Feed expectedFeed = new FeedBuilder().withName(VALID_NAME_EATBOOK).withAddress(VALID_ADDRESS_EATBOOK).build(); + assertParseSuccess(parser, NAME_DESC_EATBOOK + ADDRESS_DESC_EATBOOK, new AddFeedCommand(expectedFeed)); + } + + @Test + public void parse_compulsoryFieldMissing_failure() { + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddFeedCommand.MESSAGE_USAGE); + + // missing name prefix + assertParseFailure(parser, VALID_NAME_EATBOOK + ADDRESS_DESC_EATBOOK, expectedMessage); + + // missing address prefix + assertParseFailure(parser, NAME_DESC_EATBOOK + VALID_ADDRESS_EATBOOK, expectedMessage); + + // all prefixes missing + assertParseFailure(parser, VALID_NAME_EATBOOK + VALID_ADDRESS_EATBOOK, expectedMessage); + } +} diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 27372431371..7bf398b036c 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -4,6 +4,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; +import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_EATBOOK; +import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_EATBOOK; +import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_EATBOOK; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_EATBOOK; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_EATERY; @@ -14,9 +18,11 @@ import org.junit.jupiter.api.Test; import seedu.address.logic.commands.AddCommand; +import seedu.address.logic.commands.AddFeedCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.CloseCommand; import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.commands.DeleteFeedCommand; import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.EditCommand.EditEateryDescriptor; import seedu.address.logic.commands.ExitCommand; @@ -26,9 +32,11 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.eatery.Eatery; import seedu.address.model.eatery.NameContainsKeywordsPredicate; +import seedu.address.model.feed.Feed; import seedu.address.testutil.EateryBuilder; import seedu.address.testutil.EateryUtil; import seedu.address.testutil.EditEateryDescriptorBuilder; +import seedu.address.testutil.FeedBuilder; public class AddressBookParserTest { @@ -96,6 +104,24 @@ public void parseCommand_list() throws Exception { assertTrue(parser.parseCommand(ListCommand.COMMAND_WORD + " 3") instanceof ListCommand); } + @Test + public void parseCommand_addfeed() throws Exception { + Feed feed = new FeedBuilder().withName(VALID_NAME_EATBOOK).withAddress(VALID_ADDRESS_EATBOOK).build(); + String input = AddFeedCommand.COMMAND_WORD + NAME_DESC_EATBOOK + ADDRESS_DESC_EATBOOK; + + AddFeedCommand expectedCommand = new AddFeedCommand(feed); + AddFeedCommand command = (AddFeedCommand) parser.parseCommand(input); + + assertEquals(expectedCommand, command); + } + + @Test + public void parseCommand_deletefeed() throws Exception { + DeleteFeedCommand command = (DeleteFeedCommand) parser.parseCommand( + DeleteFeedCommand.COMMAND_WORD + NAME_DESC_EATBOOK); + assertEquals(new DeleteFeedCommand(VALID_NAME_EATBOOK), command); + } + @Test public void parseCommand_unrecognisedInput_throwsParseException() { assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), () diff --git a/src/test/java/seedu/address/logic/parser/DeleteFeedCommandParserTest.java b/src/test/java/seedu/address/logic/parser/DeleteFeedCommandParserTest.java new file mode 100644 index 00000000000..eae43a91210 --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/DeleteFeedCommandParserTest.java @@ -0,0 +1,34 @@ +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_EATBOOK; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_EATBOOK; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.DeleteFeedCommand; + +/** + * As we are only doing white-box testing, our test cases do not cover path variations + * outside of the DeleteFeedCommand code. For example, inputs "1" and "1 abc" take the + * same path through the DeleteFeedCommand, and therefore we test only one of them. + * The path variation for those two cases occur inside the ParserUtil, and + * therefore should be covered by the ParserUtilTest. + */ +public class DeleteFeedCommandParserTest { + + private DeleteFeedCommandParser parser = new DeleteFeedCommandParser(); + + @Test + public void parse_validArgs_returnsDeleteFeedCommand() { + assertParseSuccess(parser, NAME_DESC_EATBOOK, new DeleteFeedCommand(VALID_NAME_EATBOOK)); + } + + @Test + public void parse_invalidArgs_throwsParseException() { + assertParseFailure(parser, VALID_NAME_EATBOOK, + String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteFeedCommand.MESSAGE_USAGE)); + } +} diff --git a/src/test/java/seedu/address/testutil/TypicalFeeds.java b/src/test/java/seedu/address/testutil/TypicalFeeds.java index 9d653765b72..f37b028a4b3 100644 --- a/src/test/java/seedu/address/testutil/TypicalFeeds.java +++ b/src/test/java/seedu/address/testutil/TypicalFeeds.java @@ -1,5 +1,10 @@ package seedu.address.testutil; +import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_EATBOOK; +import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_SETHLUI; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_EATBOOK; +import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_SETHLUI; + import seedu.address.model.FeedList; import seedu.address.model.feed.Feed; @@ -7,10 +12,15 @@ * A utility class containing a list of {@code Feed} objects to be used in tests. */ public class TypicalFeeds { + public static final Feed EATBOOK = new FeedBuilder() + .withName(VALID_NAME_EATBOOK).withAddress(VALID_ADDRESS_EATBOOK).build(); + public static final Feed SETHLUI = new FeedBuilder() + .withName(VALID_NAME_SETHLUI).withAddress(VALID_ADDRESS_SETHLUI).build(); + public static FeedList getTypicalFeedList() { FeedList feedList = new FeedList(); - feedList.addFeed(new Feed("Seth Lui", "https://sethlui.com/feed")); - feedList.addFeed(new Feed("Eatbook", "https://eatbook.sg/feed")); + feedList.addFeed(EATBOOK); + feedList.addFeed(SETHLUI); return feedList; } }