forked from nus-cs2103-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from rrtheonlyone/home-command
Home Command Added
- Loading branch information
Showing
8 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/seedu/address/commons/events/ui/BackToHomeEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package seedu.address.commons.events.ui; | ||
|
||
import seedu.address.commons.events.BaseEvent; | ||
|
||
/** | ||
* Indicates a request to go back to the dashboard screen | ||
*/ | ||
public class BackToHomeEvent extends BaseEvent { | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/seedu/address/logic/commands/HomeCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.core.EventsCenter; | ||
import seedu.address.commons.events.ui.BackToHomeEvent; | ||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Logout the user from FoodZoom. | ||
*/ | ||
public class HomeCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "/home"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Back to Home Page! View your dashboard below."; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Returns back to home screen with dashboard. "; | ||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) { | ||
requireNonNull(model); | ||
EventsCenter.getInstance().post(new BackToHomeEvent()); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/test/java/seedu/address/logic/commands/HomeCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import static seedu.address.logic.commands.HomeCommand.MESSAGE_SUCCESS; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import seedu.address.commons.events.ui.BackToHomeEvent; | ||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.ui.testutil.EventsCollectorRule; | ||
|
||
public class HomeCommandTest { | ||
@Rule | ||
public final EventsCollectorRule eventsCollectorRule = new EventsCollectorRule(); | ||
|
||
private Model model = new ModelManager(); | ||
private CommandHistory commandHistory = new CommandHistory(); | ||
|
||
@Test | ||
public void execute_home_success() { | ||
CommandResult result = new HomeCommand().execute(model, commandHistory); | ||
assertEquals(MESSAGE_SUCCESS, result.feedbackToUser); | ||
assertTrue(eventsCollectorRule.eventsCollector.getMostRecent() instanceof BackToHomeEvent); | ||
assertTrue(eventsCollectorRule.eventsCollector.getSize() == 1); | ||
} | ||
} |