From 749e8e0024c191dc95564741407964c2b0458310 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sat, 29 Oct 2016 23:51:17 +0800 Subject: [PATCH 01/24] Update add, clear and delete gui tests --- src/test/java/guitests/AddCommandTest.java | 30 +++++++++++-------- src/test/java/guitests/ClearCommandTest.java | 20 ++++++++----- src/test/java/guitests/DeleteCommandTest.java | 4 +-- ...okGuiTest.java => TaskManagerGuiTest.java} | 2 +- 4 files changed, 32 insertions(+), 24 deletions(-) rename src/test/java/guitests/{AddressBookGuiTest.java => TaskManagerGuiTest.java} (98%) diff --git a/src/test/java/guitests/AddCommandTest.java b/src/test/java/guitests/AddCommandTest.java index 84c28a602c79..5cd6dcaaea6f 100644 --- a/src/test/java/guitests/AddCommandTest.java +++ b/src/test/java/guitests/AddCommandTest.java @@ -4,34 +4,37 @@ import org.junit.Test; import seedu.address.logic.commands.AddCommand; import seedu.address.commons.core.Messages; +import seedu.address.logic.commands.ClearCommand; import seedu.address.testutil.TestEntry; import seedu.address.testutil.TestUtil; import static org.junit.Assert.assertTrue; -public class AddCommandTest extends AddressBookGuiTest { +public class AddCommandTest extends TaskManagerGuiTest { + //@@author A0116603R @Test public void add() { - //add one task - TestEntry[] currentList = td.getTypicalPersons(); - TestEntry testEntry = td.homework; - assertAddSuccess(testEntry, currentList); - currentList = TestUtil.addPersonsToList(currentList, testEntry); + TestEntry[] currentList = td.getSampleEntriesAsArray(); // sample entries already present + TestEntry testEntry = null; - //add another task - testEntry = td.movie; - assertAddSuccess(testEntry, currentList); - currentList = TestUtil.addPersonsToList(currentList, testEntry); + //add new entries + for (TestEntry entry : td.getNonSampleEntries()) { + testEntry = entry; + assertAddSuccess(testEntry, currentList); + currentList = TestUtil.addPersonsToList(currentList, testEntry); + } + + assertTrue(currentList.length > 0); //add duplicate task - commandBox.runCommand(td.homework.getAddCommand()); + commandBox.runCommand(currentList[0].getAddCommand()); assertResultMessage(AddCommand.MESSAGE_DUPLICATE_ENTRY); assertTrue(taskList.isListMatching(currentList)); //add to empty list - commandBox.runCommand("clear"); - assertAddSuccess(td.apple); + commandBox.runCommand(ClearCommand.COMMAND_WORD); + assertAddSuccess(currentList[0]); //invalid command commandBox.runCommand("adds Johnny"); @@ -39,6 +42,7 @@ public void add() { } + //@@author private void assertAddSuccess(TestEntry testEntry, TestEntry... currentList) { commandBox.runCommand(testEntry.getAddCommand()); diff --git a/src/test/java/guitests/ClearCommandTest.java b/src/test/java/guitests/ClearCommandTest.java index 6ed01e032a79..c5830cfb3a00 100644 --- a/src/test/java/guitests/ClearCommandTest.java +++ b/src/test/java/guitests/ClearCommandTest.java @@ -1,22 +1,26 @@ package guitests; import org.junit.Test; +import seedu.address.logic.commands.ClearCommand; +import seedu.address.logic.commands.DeleteCommand; +import seedu.address.testutil.TestEntry; +import seedu.address.testutil.TypicalTestTasks; import static org.junit.Assert.assertTrue; -public class ClearCommandTest extends AddressBookGuiTest { +public class ClearCommandTest extends TaskManagerGuiTest { @Test public void clear() { - //verify a non-empty list can be cleared - assertTrue(taskList.isListMatching(td.getTypicalPersons())); + assertTrue(taskList.isListMatching(td.getSampleEntriesAsArray())); assertClearCommandSuccess(); //verify other commands can work after a clear command - commandBox.runCommand(td.homework.getAddCommand()); - assertTrue(taskList.isListMatching(td.homework)); - commandBox.runCommand("delete 1"); + TestEntry testEntry = td.getTestEntry(TypicalTestTasks.BuyTasks.TASK_1); + commandBox.runCommand(testEntry.getAddCommand()); + assertTrue(taskList.isListMatching(testEntry)); + commandBox.runCommand(DeleteCommand.COMMAND_WORD + " 1"); assertListSize(0); //verify clear command works when the list is empty @@ -24,8 +28,8 @@ public void clear() { } private void assertClearCommandSuccess() { - commandBox.runCommand("clear"); + commandBox.runCommand(ClearCommand.COMMAND_WORD); assertListSize(0); - assertResultMessage("Todo list has been cleared!"); + assertResultMessage(ClearCommand.MESSAGE_SUCCESS); } } diff --git a/src/test/java/guitests/DeleteCommandTest.java b/src/test/java/guitests/DeleteCommandTest.java index 33e22fb40cc0..1d7d379b8133 100644 --- a/src/test/java/guitests/DeleteCommandTest.java +++ b/src/test/java/guitests/DeleteCommandTest.java @@ -8,13 +8,13 @@ import static org.junit.Assert.assertTrue; import static seedu.address.logic.commands.DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS; -public class DeleteCommandTest extends AddressBookGuiTest { +public class DeleteCommandTest extends TaskManagerGuiTest { @Test public void delete() { //delete the first in the list - TestEntry[] currentList = td.getTypicalPersons(); + TestEntry[] currentList = td.getSampleEntriesAsArray(); int targetIndex = 1; assertDeleteSuccess(targetIndex, currentList); diff --git a/src/test/java/guitests/AddressBookGuiTest.java b/src/test/java/guitests/TaskManagerGuiTest.java similarity index 98% rename from src/test/java/guitests/AddressBookGuiTest.java rename to src/test/java/guitests/TaskManagerGuiTest.java index 7f8a075057c0..6ac3d13409d1 100644 --- a/src/test/java/guitests/AddressBookGuiTest.java +++ b/src/test/java/guitests/TaskManagerGuiTest.java @@ -23,7 +23,7 @@ /** * A GUI Test class for TaskManager. */ -public abstract class AddressBookGuiTest { +public abstract class TaskManagerGuiTest { /* The TestName Rule makes the current test name available inside test methods */ @Rule From 747d85b77614bf2ebd807a9deeee1951eadd678d Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sat, 29 Oct 2016 23:53:10 +0800 Subject: [PATCH 02/24] Remove unused code + update help window test for gui --- src/test/java/guitests/HelpWindowTest.java | 15 +++++++++++---- .../guitests/guihandles/HelpWindowHandle.java | 3 ++- .../java/guitests/guihandles/TaskListHandle.java | 16 ++++++---------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/test/java/guitests/HelpWindowTest.java b/src/test/java/guitests/HelpWindowTest.java index 61ee557344bf..786d96584abb 100644 --- a/src/test/java/guitests/HelpWindowTest.java +++ b/src/test/java/guitests/HelpWindowTest.java @@ -5,18 +5,25 @@ import static org.junit.Assert.assertTrue; -public class HelpWindowTest extends AddressBookGuiTest { +public class HelpWindowTest extends TaskManagerGuiTest { + //@@author A0116603R @Test - public void openHelpWindow() { - + public void openAndCloseHelpWindow() { HelpWindowHandle helpWindowHandle = commandBox.runHelpCommand(); assertHelpWindowOpen(helpWindowHandle); helpWindowHandle.pressEscape(); + assertHelpWindowClosed(); + } + + private void assertHelpWindowClosed() { + assertTrue(taskList.isVisible()); } + // @@author private void assertHelpWindowOpen(HelpWindowHandle helpWindowHandle) { - assertTrue(helpWindowHandle.isWindowOpen()); + assertTrue(helpWindowHandle.isVisible()); } + } diff --git a/src/test/java/guitests/guihandles/HelpWindowHandle.java b/src/test/java/guitests/guihandles/HelpWindowHandle.java index 8d312df6df9c..0918640868c6 100644 --- a/src/test/java/guitests/guihandles/HelpWindowHandle.java +++ b/src/test/java/guitests/guihandles/HelpWindowHandle.java @@ -4,6 +4,7 @@ import javafx.stage.Stage; import static seedu.address.ui.util.GuiUtil.OPAQUE; +import static seedu.address.ui.util.GuiUtil.TRANSPARENT; /** * Provides a handle to the help window of the app. @@ -18,7 +19,7 @@ public HelpWindowHandle(GuiRobot guiRobot, Stage primaryStage) { guiRobot.sleep(300); } - public boolean isWindowOpen() { + public boolean isVisible() { return getNode(HELP_WINDOW_ROOT_FIELD_ID).getOpacity() == OPAQUE; } diff --git a/src/test/java/guitests/guihandles/TaskListHandle.java b/src/test/java/guitests/guihandles/TaskListHandle.java index f63e1fd2671f..243b727ccc2a 100644 --- a/src/test/java/guitests/guihandles/TaskListHandle.java +++ b/src/test/java/guitests/guihandles/TaskListHandle.java @@ -16,6 +16,7 @@ import java.util.Set; import static org.junit.Assert.assertTrue; +import static seedu.address.ui.util.GuiUtil.OPAQUE; /** * Provides a handle for the panel containing the task list. @@ -31,11 +32,6 @@ public TaskListHandle(GuiRobot guiRobot, Stage primaryStage) { super(guiRobot, primaryStage, TestApp.APP_TITLE); } - public List getSelectedPersons() { - ListView personList = getListView(); - return personList.getSelectionModel().getSelectedItems(); - } - public ListView getListView() { return (ListView) getNode(TASK_LIST_ID); } @@ -47,13 +43,12 @@ public ListView getListView() { public boolean isListMatching(Entry... persons) { return this.isListMatching(0, persons); } - + /** - * Clicks on the ListView. + * Returns true if the task list is currently visible */ - public void clickOnListView() { - Point2D point= TestUtil.getScreenMidPoint(getListView()); - guiRobot.clickOn(point.getX(), point.getY()); + public boolean isVisible() { + return getNode(TASK_LIST_ID).getOpacity() == OPAQUE; } /** @@ -85,6 +80,7 @@ public boolean containsInOrder(int startPosition, Entry... entries) { public boolean isListMatching(int startPosition, Entry... persons) throws IllegalArgumentException { if (persons.length + startPosition != getListView().getItems().size()) { throw new IllegalArgumentException("List size mismatched\n" + + "Got " + (persons.length) + " persons" + "Expected " + (getListView().getItems().size() - 1) + " persons"); } assertTrue(this.containsInOrder(startPosition, persons)); From 35efd0887a4ba19e2ea3df2fd25c8d7dcbdc9839 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sat, 29 Oct 2016 23:54:04 +0800 Subject: [PATCH 03/24] Update command box test + refactor typical test tasks --- src/test/java/guitests/CommandBoxTest.java | 9 +- .../address/testutil/TypicalTestTasks.java | 123 +++++++++++++----- 2 files changed, 99 insertions(+), 33 deletions(-) diff --git a/src/test/java/guitests/CommandBoxTest.java b/src/test/java/guitests/CommandBoxTest.java index 71c8d3f0fe48..3db3f2a3242a 100644 --- a/src/test/java/guitests/CommandBoxTest.java +++ b/src/test/java/guitests/CommandBoxTest.java @@ -1,15 +1,18 @@ package guitests; import org.junit.Test; +import seedu.address.testutil.TestEntry; +import seedu.address.testutil.TypicalTestTasks; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public class CommandBoxTest extends AddressBookGuiTest { +public class CommandBoxTest extends TaskManagerGuiTest { @Test public void commandBox_commandSucceeds_textCleared() { - commandBox.runCommand(td.banana.getAddCommand()); + TestEntry testEntry = td.getTestEntry(TypicalTestTasks.BuyTasks.TASK_1); + commandBox.runCommand(testEntry.getAddCommand()); assertEquals(commandBox.getCommandInput(), ""); } @@ -21,7 +24,7 @@ public void commandBox_commandFails_textStays(){ @Test public void commandBox_commandFails_redBorder() { - commandBox.runCommand("invalid command produces red glow"); + commandBox.runCommand("invalid command produces error styling"); assertTrue(commandBox.hasErrorClass()); } diff --git a/src/test/java/seedu/address/testutil/TypicalTestTasks.java b/src/test/java/seedu/address/testutil/TypicalTestTasks.java index 9f043a1f32b3..b4df88181a8f 100644 --- a/src/test/java/seedu/address/testutil/TypicalTestTasks.java +++ b/src/test/java/seedu/address/testutil/TypicalTestTasks.java @@ -4,50 +4,113 @@ import seedu.address.model.TaskManager; import seedu.address.model.task.*; +import java.util.List; +import java.util.Set; + +//@@author A0116603R +/** + * A class encapsulating typical tasks for test purposes. + */ public class TypicalTestTasks { - public static TestEntry apple, banana, cat, doge, eggplant, study, jogging, homework, movie; + public static class BuyTasks implements TestTasks { + public static final String TASK_1 = "Buy apples"; + static final String TASK_2 = "Buy bananas"; + static final String TASK_3 = "Buy cookies"; + static final String TASK_4 = "Buy some time"; - public TypicalTestTasks() { - try { - apple = new EntryBuilder().withTitle("Buy apples").withTags("groceries").build(); - banana = new EntryBuilder().withTitle("Buy bananas").withTags("groceries", "for scale").build(); - cat = new EntryBuilder().withTitle("Adopt a cat").build(); - doge = new EntryBuilder().withTitle("Get blankets for doge").build(); - eggplant = new EntryBuilder().withTitle("Buy eggplants").build(); - study = new EntryBuilder().withTitle("Study for tests").build(); - jogging = new EntryBuilder().withTitle("Go jogging this Thursday").build(); - - homework = new EntryBuilder().withTitle("Do assignment 314").build(); - movie = new EntryBuilder().withTitle("Watch Deadpool").build(); - } catch (IllegalValueException e) { - e.printStackTrace(); - assert false : "not possible"; + public static final String VERB = "Buy"; + + @Override + public List getSampleEntries() { + return getAllEntries(TASK_1, TASK_2); + } + + @Override + public List getNonSampleEntries() { + return getAllEntries(TASK_3, TASK_4); } } - public static void loadAddressBookWithSampleData(TaskManager taskManager) { + private static class StudyTasks implements TestTasks { + static final String TASK_1 = "Study for finals"; + static final String TASK_2 = "Do assignment 1"; + static final String TASK_3 = "Read up on unit testing"; + static final String TASK_4 = "Code for project"; - try { - taskManager.addTask(new Task(apple)); - taskManager.addTask(new Task(banana)); - taskManager.addTask(new Task(cat)); - taskManager.addTask(new Task(doge)); - taskManager.addTask(new Task(eggplant)); - taskManager.addTask(new Task(study)); - taskManager.addTask(new Task(jogging)); - } catch (UniqueTaskList.DuplicateTaskException e) { - assert false : "not possible"; + @Override + public List getSampleEntries() { + return getAllEntries(TASK_1, TASK_2); + } + + @Override + public List getNonSampleEntries() { + return getAllEntries(TASK_3, TASK_4); } } - public TestEntry[] getTypicalPersons() { - return new TestEntry[]{apple, banana, cat, doge, eggplant, study, jogging}; + public static class WatchTasks implements TestTasks { + static final String TASK_1 = "Watch movie"; + static final String TASK_2 = "Watch Black Mirror"; + + public static final String VERB = "Watch"; + + @Override + public List getSampleEntries() { + return getAllEntries(TASK_1); + } + + @Override + public List getNonSampleEntries() { + return getAllEntries(TASK_2); + } } - public TaskManager getTypicalAddressBook(){ + public static void loadAddressBookWithSampleData(TaskManager taskManager) { + for (Entry entry : getSampleEntries()) { + try { + taskManager.addTask(new Task(entry)); + } catch (UniqueTaskList.DuplicateTaskException e) { + assert false : "not possible"; + } + } + } + + private static List getSampleEntries() { + List allTestEntries = new BuyTasks().getSampleEntries(); + allTestEntries.addAll(new StudyTasks().getSampleEntries()); + allTestEntries.addAll(new WatchTasks().getSampleEntries()); + return allTestEntries; + } + + public TestEntry[] getSampleEntriesAsArray() { + List allTestEntries = getSampleEntries(); + TestEntry[] result = new TestEntry[allTestEntries.size()]; + return allTestEntries.toArray(result); + } + + public List getNonSampleEntries() { + List nonSampleEntries = new BuyTasks().getNonSampleEntries(); + nonSampleEntries.addAll(new StudyTasks().getNonSampleEntries()); + nonSampleEntries.addAll(new WatchTasks().getNonSampleEntries()); + return nonSampleEntries; + } + + public TaskManager getTypicalTaskManager(){ TaskManager tm = new TaskManager(); loadAddressBookWithSampleData(tm); return tm; } + + public TestEntry getTestEntry(String title) { + TestEntry entry = null; + try { + entry = new EntryBuilder().withTitle(title).build(); + } catch (IllegalValueException e) { + assert false : "not possible"; + } + return entry; + } + + } From f669d81834bb3771abc961854ade4697ef3a0341 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sat, 29 Oct 2016 23:54:15 +0800 Subject: [PATCH 04/24] Add test tasks interface --- .../seedu/address/testutil/TestTasks.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/test/java/seedu/address/testutil/TestTasks.java diff --git a/src/test/java/seedu/address/testutil/TestTasks.java b/src/test/java/seedu/address/testutil/TestTasks.java new file mode 100644 index 000000000000..feac3c6bfad9 --- /dev/null +++ b/src/test/java/seedu/address/testutil/TestTasks.java @@ -0,0 +1,35 @@ +package seedu.address.testutil; + +import seedu.address.commons.exceptions.IllegalValueException; + +import java.util.ArrayList; +import java.util.List; + +//@@author A0116603R +/** + * An interface representing a category of typical test tasks. + */ +public interface TestTasks { + default List getAllEntries(String... tasks) { + List entries = new ArrayList<>(); + for (String task : tasks) { + try { + entries.add(new EntryBuilder().withTitle(task).build()); + } catch (IllegalValueException e) { + assert false : "not possible"; + } + } + return entries; + } + + /** + * Returns the entries used as sample data for this category of tasks + */ + List getSampleEntries(); + + /** + * Returns the entries used as new data that can be arbitrarily added to + * a test task manager instance + */ + List getNonSampleEntries(); +} From 3fb6cc07dc53e7ba3a49b369e1dd98267ba97192 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sat, 29 Oct 2016 23:54:29 +0800 Subject: [PATCH 05/24] Update some non gui tests --- .../address/storage/StorageManagerTest.java | 2 +- .../storage/XmlAddressBookStorageTest.java | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/test/java/seedu/address/storage/StorageManagerTest.java b/src/test/java/seedu/address/storage/StorageManagerTest.java index f7176bfe9f6b..931d0e0bb574 100644 --- a/src/test/java/seedu/address/storage/StorageManagerTest.java +++ b/src/test/java/seedu/address/storage/StorageManagerTest.java @@ -55,7 +55,7 @@ public void prefsReadSave() throws Exception { @Test public void addressBookReadSave() throws Exception { - TaskManager original = new TypicalTestTasks().getTypicalAddressBook(); + TaskManager original = new TypicalTestTasks().getTypicalTaskManager(); storageManager.saveTaskManager(original); ReadOnlyTaskManager retrieved = storageManager.readTaskManager().get(); assertEquals(original, new TaskManager(retrieved)); diff --git a/src/test/java/seedu/address/storage/XmlAddressBookStorageTest.java b/src/test/java/seedu/address/storage/XmlAddressBookStorageTest.java index 628ac44c425a..88502fd6b5da 100644 --- a/src/test/java/seedu/address/storage/XmlAddressBookStorageTest.java +++ b/src/test/java/seedu/address/storage/XmlAddressBookStorageTest.java @@ -10,12 +10,17 @@ import seedu.address.model.TaskManager; import seedu.address.model.ReadOnlyTaskManager; import seedu.address.model.task.Task; +import seedu.address.testutil.TestEntry; import seedu.address.testutil.TypicalTestTasks; import java.io.IOException; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class XmlAddressBookStorageTest { private static String TEST_DATA_FOLDER = FileUtil.getPath("./src/test/data/XmlAddressBookStorageTest/"); @@ -62,7 +67,7 @@ public void read_notXmlFormat_exceptionThrown() throws Exception { public void readAndSaveAddressBook_allInOrder_success() throws Exception { String filePath = testFolder.getRoot().getPath() + "TempAddressBook.xml"; TypicalTestTasks td = new TypicalTestTasks(); - TaskManager original = td.getTypicalAddressBook(); + TaskManager original = td.getTypicalTaskManager(); XmlTaskManagerStorage xmlTaskManagerStorage = new XmlTaskManagerStorage(filePath); //Save in new file and read back @@ -71,14 +76,21 @@ public void readAndSaveAddressBook_allInOrder_success() throws Exception { assertEquals(original, new TaskManager(readBack)); //Modify data, overwrite exiting file, and read back - original.addTask(new Task(TypicalTestTasks.homework)); - original.removeEntry(new Task(TypicalTestTasks.apple)); + List typicalEntries = td.getNonSampleEntries(); + assertTrue(typicalEntries.size() >= 3); + Iterator testEntries = typicalEntries.iterator(); + + if (testEntries.hasNext()) { + original.addTask(new Task(testEntries.next())); + } xmlTaskManagerStorage.saveTaskManager(original, filePath); readBack = xmlTaskManagerStorage.readTaskManager(filePath).get(); assertEquals(original, new TaskManager(readBack)); //Save and read without specifying file path - original.addTask(new Task(TypicalTestTasks.movie)); + if (testEntries.hasNext()) { + original.addTask(new Task(testEntries.next())); + } xmlTaskManagerStorage.saveTaskManager(original); //file path not specified readBack = xmlTaskManagerStorage.readTaskManager().get(); //file path not specified assertEquals(original, new TaskManager(readBack)); From c69618e153ddbccf52892f2be110310597400360 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sat, 29 Oct 2016 23:54:38 +0800 Subject: [PATCH 06/24] Remove useless methods --- .../java/seedu/address/testutil/TestUtil.java | 92 ------------------- 1 file changed, 92 deletions(-) diff --git a/src/test/java/seedu/address/testutil/TestUtil.java b/src/test/java/seedu/address/testutil/TestUtil.java index a26a5d506803..6469ec233154 100644 --- a/src/test/java/seedu/address/testutil/TestUtil.java +++ b/src/test/java/seedu/address/testutil/TestUtil.java @@ -178,53 +178,6 @@ public static void captureScreenShot(String fileName) { } } - public static String descOnFail(Object... comparedObjects) { - return "Comparison failed \n" - + Arrays.asList(comparedObjects).stream() - .map(Object::toString) - .collect(Collectors.joining("\n")); - } - - public static void setFinalStatic(Field field, Object newValue) throws NoSuchFieldException, IllegalAccessException{ - field.setAccessible(true); - // remove final modifier from field - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - // ~Modifier.FINAL is used to remove the final modifier from field so that its value is no longer - // final and can be changed - modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); - field.set(null, newValue); - } - - public static void initRuntime() throws TimeoutException { - FxToolkit.registerPrimaryStage(); - FxToolkit.hideStage(); - } - - public static void tearDownRuntime() throws Exception { - FxToolkit.cleanupStages(); - } - - /** - * Gets private method of a class - * Invoke the method using method.invoke(objectInstance, params...) - * - * Caveat: only find method declared in the current Class, not inherited from supertypes - */ - public static Method getPrivateMethod(Class objectClass, String methodName) throws NoSuchMethodException { - Method method = objectClass.getDeclaredMethod(methodName); - method.setAccessible(true); - return method; - } - - public static void renameFile(File file, String newFileName) { - try { - Files.copy(file, new File(newFileName)); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - /** * Gets mid point of a node relative to the screen. * @param node @@ -236,42 +189,10 @@ public static Point2D getScreenMidPoint(Node node) { return new Point2D(x,y); } - /** - * Gets mid point of a node relative to its scene. - * @param node - * @return - */ - public static Point2D getSceneMidPoint(Node node) { - double x = getScenePos(node).getMinX() + node.getLayoutBounds().getWidth() / 2; - double y = getScenePos(node).getMinY() + node.getLayoutBounds().getHeight() / 2; - return new Point2D(x,y); - } - - /** - * Gets the bound of the node relative to the parent scene. - * @param node - * @return - */ - public static Bounds getScenePos(Node node) { - return node.localToScene(node.getBoundsInLocal()); - } - public static Bounds getScreenPos(Node node) { return node.localToScreen(node.getBoundsInLocal()); } - public static double getSceneMaxX(Scene scene) { - return scene.getX() + scene.getWidth(); - } - - public static double getSceneMaxY(Scene scene) { - return scene.getX() + scene.getHeight(); - } - - public static Object getLastElement(List list) { - return list.get(list.size() - 1); - } - /** * Removes a subset from the list of persons. * @param persons The list of persons @@ -284,7 +205,6 @@ public static TestEntry[] removePersonsFromList(final TestEntry[] persons, TestE return listOfPersons.toArray(new TestEntry[listOfPersons.size()]); } - /** * Returns a copy of the list with the task at specified index removed. * @param list original list to copy from @@ -294,18 +214,6 @@ public static TestEntry[] removePersonFromList(final TestEntry[] list, int targe return removePersonsFromList(list, list[targetIndexInOneIndexedFormat-1]); } - /** - * Replaces persons[i] with a task. - * @param persons The array of persons. - * @param person The replacement task - * @param index The index of the task to be replaced. - * @return - */ - public static TestEntry[] replacePersonFromList(TestEntry[] persons, TestEntry person, int index) { - persons[index] = person; - return persons; - } - /** * Appends persons to the array of persons. * @param persons A array of persons. From efd166162ae40ee8baf655d14001b2f85fbb76cd Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 00:00:19 +0800 Subject: [PATCH 07/24] Minor name change --- src/test/java/guitests/TaskManagerGuiTest.java | 2 +- src/test/java/guitests/guihandles/MainGuiHandle.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/guitests/TaskManagerGuiTest.java b/src/test/java/guitests/TaskManagerGuiTest.java index 6ac3d13409d1..a4dc6f7bc2a3 100644 --- a/src/test/java/guitests/TaskManagerGuiTest.java +++ b/src/test/java/guitests/TaskManagerGuiTest.java @@ -57,7 +57,7 @@ public static void setupSpec() { public void setup() throws Exception { FxToolkit.setupStage((stage) -> { mainGui = new MainGuiHandle(new GuiRobot(), stage); - taskList = mainGui.getPersonListPanel(); + taskList = mainGui.getTaskListPanel(); resultDisplay = mainGui.getResultDisplay(); commandBox = mainGui.getCommandBox(); this.stage = stage; diff --git a/src/test/java/guitests/guihandles/MainGuiHandle.java b/src/test/java/guitests/guihandles/MainGuiHandle.java index 15f6681983af..1b4dbb422913 100644 --- a/src/test/java/guitests/guihandles/MainGuiHandle.java +++ b/src/test/java/guitests/guihandles/MainGuiHandle.java @@ -13,7 +13,7 @@ public MainGuiHandle(GuiRobot guiRobot, Stage primaryStage) { super(guiRobot, primaryStage, TestApp.APP_TITLE); } - public TaskListHandle getPersonListPanel() { + public TaskListHandle getTaskListPanel() { return new TaskListHandle(guiRobot, primaryStage); } From 532f1bc7b6f9c0bab46cd47c46f26cd01878113f Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 00:04:45 +0800 Subject: [PATCH 08/24] Update list command test --- src/test/java/guitests/AddCommandTest.java | 2 +- src/test/java/guitests/ListCommandTest.java | 37 ++++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/test/java/guitests/AddCommandTest.java b/src/test/java/guitests/AddCommandTest.java index 5cd6dcaaea6f..5ed33f489d74 100644 --- a/src/test/java/guitests/AddCommandTest.java +++ b/src/test/java/guitests/AddCommandTest.java @@ -12,7 +12,7 @@ public class AddCommandTest extends TaskManagerGuiTest { - //@@author A0116603R + //@@author A0116603R-reused @Test public void add() { TestEntry[] currentList = td.getSampleEntriesAsArray(); // sample entries already present diff --git a/src/test/java/guitests/ListCommandTest.java b/src/test/java/guitests/ListCommandTest.java index 9ad2eee39885..9b9d82c169be 100644 --- a/src/test/java/guitests/ListCommandTest.java +++ b/src/test/java/guitests/ListCommandTest.java @@ -2,27 +2,40 @@ import org.junit.Test; import seedu.address.commons.core.Messages; +import seedu.address.logic.commands.ClearCommand; +import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.commands.ListCommand; import seedu.address.testutil.TestEntry; +import seedu.address.testutil.TestTasks; +import seedu.address.testutil.TypicalTestTasks; + +import java.util.List; import static org.junit.Assert.assertTrue; -public class ListCommandTest extends AddressBookGuiTest { +public class ListCommandTest extends TaskManagerGuiTest { + //@@author A0116603R-reused @Test public void list_nonEmptyList() { - //TODO: Write better, less fragile tests - assertListResult("list nodoge"); //no results - assertListResult("list Buy", td.apple, td.banana, td.eggplant); //multiple results + // search miss + assertListResult(ListCommand.COMMAND_WORD + " 404 doge not found"); + + // search hits for BuyTasks + TestTasks generator = new TypicalTestTasks.BuyTasks(); + assertListResult(ListCommand.COMMAND_WORD + " " + TypicalTestTasks.BuyTasks.VERB, generator.getSampleEntries()); - //find after deleting one result - commandBox.runCommand("delete 1"); - assertListResult("list doge",td.doge); + // search after deleting one result + commandBox.runCommand(DeleteCommand.COMMAND_WORD + " 1"); + generator = new TypicalTestTasks.WatchTasks(); + assertListResult(ListCommand.COMMAND_WORD + " " + TypicalTestTasks.WatchTasks.VERB, generator.getSampleEntries()); } @Test public void list_emptyList(){ - commandBox.runCommand("clear"); - assertListResult("list doge"); //no results + // clear the list and assert search miss + commandBox.runCommand(ClearCommand.COMMAND_WORD); + assertListResult(ListCommand.COMMAND_WORD + " " + TypicalTestTasks.BuyTasks.VERB); } @Test @@ -37,4 +50,10 @@ private void assertListResult(String command, TestEntry... expectedHits ) { assertResultMessage(expectedHits.length + " entries listed!"); assertTrue(taskList.isListMatching(expectedHits)); } + + private void assertListResult(String command, List expectedHits) { + TestEntry[] array = new TestEntry[expectedHits.size()]; + expectedHits.toArray(array); + assertListResult(command, array); + } } From 41684878b4b4ffd868eae32b7b920dd5017c8cae Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 00:09:43 +0800 Subject: [PATCH 09/24] Convert static method to instance method --- src/test/java/seedu/address/testutil/TypicalTestTasks.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/address/testutil/TypicalTestTasks.java b/src/test/java/seedu/address/testutil/TypicalTestTasks.java index b4df88181a8f..60c56c1b1e98 100644 --- a/src/test/java/seedu/address/testutil/TypicalTestTasks.java +++ b/src/test/java/seedu/address/testutil/TypicalTestTasks.java @@ -66,7 +66,7 @@ public List getNonSampleEntries() { } } - public static void loadAddressBookWithSampleData(TaskManager taskManager) { + public void loadAddressBookWithSampleData(TaskManager taskManager) { for (Entry entry : getSampleEntries()) { try { taskManager.addTask(new Task(entry)); @@ -76,7 +76,7 @@ public static void loadAddressBookWithSampleData(TaskManager taskManager) { } } - private static List getSampleEntries() { + private List getSampleEntries() { List allTestEntries = new BuyTasks().getSampleEntries(); allTestEntries.addAll(new StudyTasks().getSampleEntries()); allTestEntries.addAll(new WatchTasks().getSampleEntries()); From 4efd2326af61dcfdab0f41c635d4ac0d4e897c46 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 00:17:03 +0800 Subject: [PATCH 10/24] Fix for static -> instance method change --- src/test/java/guitests/TaskManagerGuiTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/guitests/TaskManagerGuiTest.java b/src/test/java/guitests/TaskManagerGuiTest.java index a4dc6f7bc2a3..23fccbf77f37 100644 --- a/src/test/java/guitests/TaskManagerGuiTest.java +++ b/src/test/java/guitests/TaskManagerGuiTest.java @@ -75,7 +75,8 @@ public void setup() throws Exception { */ protected TaskManager getInitialData() { TaskManager ab = TestUtil.generateEmptyAddressBook(); - TypicalTestTasks.loadAddressBookWithSampleData(ab); + TypicalTestTasks typicalTestTasks = new TypicalTestTasks(); + typicalTestTasks.loadAddressBookWithSampleData(ab); return ab; } From dc012d461bf549126474b1af48388290079268a4 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 01:10:07 +0800 Subject: [PATCH 11/24] Add tests for gui util --- .../java/seedu/address/ui/util/GuiUtil.java | 8 ++-- src/test/java/guitests/GuiUtilTest.java | 45 +++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 src/test/java/guitests/GuiUtilTest.java diff --git a/src/main/java/seedu/address/ui/util/GuiUtil.java b/src/main/java/seedu/address/ui/util/GuiUtil.java index 4cf20dc15afb..eacea0a1c774 100644 --- a/src/main/java/seedu/address/ui/util/GuiUtil.java +++ b/src/main/java/seedu/address/ui/util/GuiUtil.java @@ -1,5 +1,6 @@ package seedu.address.ui.util; +import com.google.common.annotations.VisibleForTesting; import javafx.beans.value.ChangeListener; import seedu.address.commons.core.EventsCenter; import seedu.address.commons.events.ui.MarkTaskEvent; @@ -22,9 +23,10 @@ public class GuiUtil { public static final String EVENT_DESCRIPTION_STYLE_CLASS = "event"; - private static String PAST_STYLE_CLASS = "past"; - private static String ACTIVE_STYLE_CLASS = "present"; - private static String OVERDUE_STYLE_CLASS = "overdue"; + @VisibleForTesting + public static String PAST_STYLE_CLASS = "past"; + public static String ACTIVE_STYLE_CLASS = "present"; + public static String OVERDUE_STYLE_CLASS = "overdue"; public static ChangeListener getCheckBoxEventListener(int idx) { return (ov, old_val, new_val) -> EventsCenter.getInstance().post(new MarkTaskEvent(idx, new_val)); diff --git a/src/test/java/guitests/GuiUtilTest.java b/src/test/java/guitests/GuiUtilTest.java new file mode 100644 index 000000000000..3555934a02b5 --- /dev/null +++ b/src/test/java/guitests/GuiUtilTest.java @@ -0,0 +1,45 @@ +package guitests; + +import org.junit.Test; + +import java.time.LocalDateTime; +import java.time.LocalTime; + +import static org.junit.Assert.assertEquals; +import static seedu.address.ui.util.GuiUtil.*; + +public class GuiUtilTest { + + private LocalDateTime now = LocalDateTime.now(); + private LocalDateTime midnight = LocalDateTime.of(now.toLocalDate().plusDays(1), LocalTime.MIDNIGHT); + + @Test + public void taskStyling() { + assertEquals("Unmarked floating tasks have no styling", "", getTaskStyling(false)); + assertEquals("Marked floating tasks have ." + PAST_STYLE_CLASS + " style class", PAST_STYLE_CLASS, getTaskStyling(true)); + } + + @Test + public void deadlineStyling_marked_havePastStyleRegardlessOfDeadline() { + String styleClass = getDeadlineStyling(true, now.minusWeeks(1)); + assertEquals(PAST_STYLE_CLASS, styleClass); + + styleClass = getDeadlineStyling(true, now.plusWeeks(1)); + assertEquals(PAST_STYLE_CLASS, styleClass); + } + + @Test + public void deadlineStyling_unmarked() { + assertEquals(OVERDUE_STYLE_CLASS, getDeadlineStyling(false, now.minusWeeks(1))); + assertEquals(ACTIVE_STYLE_CLASS, getDeadlineStyling(false, midnight.minusMinutes(1))); + assertEquals("", getDeadlineStyling(false, now.plusWeeks(1))); + } + + @Test + public void eventStyling_past() { + assertEquals(PAST_STYLE_CLASS, getEventStyling(now.minusDays(5), now.minusDays(4))); + assertEquals(ACTIVE_STYLE_CLASS, getEventStyling(now.minusSeconds(1), now.plusHours(1))); + assertEquals("", getEventStyling(now.plusDays(1), now.plusDays(2))); + } + +} From 9f6fca7ad19a8c944a4aee8084410f685d9a8a7a Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 01:10:24 +0800 Subject: [PATCH 12/24] =?UTF-8?q?Faster=20gui=20tests...=20=F0=9F=98=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/guitests/guihandles/GuiHandle.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/guitests/guihandles/GuiHandle.java b/src/test/java/guitests/guihandles/GuiHandle.java index 9ce8d1faea97..1ce09a345602 100644 --- a/src/test/java/guitests/guihandles/GuiHandle.java +++ b/src/test/java/guitests/guihandles/GuiHandle.java @@ -62,11 +62,11 @@ protected void setTextField(String textFieldId, String newText) { } public void pressEnter() { - guiRobot.type(KeyCode.ENTER).sleep(500); + guiRobot.type(KeyCode.ENTER).sleep(200); } public void pressEscape() { - guiRobot.type(KeyCode.ESCAPE).sleep(500); + guiRobot.type(KeyCode.ESCAPE).sleep(200); } protected String getTextFromLabel(String fieldId, Node parentNode) { From 7807f40a1c6a78ef10dfa9dff81908b1fe85180f Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 02:01:45 +0800 Subject: [PATCH 13/24] Remove event --- .../events/ui/JumpToListRequestEvent.java | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/main/java/seedu/address/commons/events/ui/JumpToListRequestEvent.java diff --git a/src/main/java/seedu/address/commons/events/ui/JumpToListRequestEvent.java b/src/main/java/seedu/address/commons/events/ui/JumpToListRequestEvent.java deleted file mode 100644 index 0580d27aecf5..000000000000 --- a/src/main/java/seedu/address/commons/events/ui/JumpToListRequestEvent.java +++ /dev/null @@ -1,21 +0,0 @@ -package seedu.address.commons.events.ui; - -import seedu.address.commons.events.BaseEvent; - -/** - * Indicates a request to jump to the list of persons - */ -public class JumpToListRequestEvent extends BaseEvent { - - public final int targetIndex; - - public JumpToListRequestEvent(int targetIndex) { - this.targetIndex = targetIndex; - } - - @Override - public String toString() { - return this.getClass().getSimpleName(); - } - -} From 99ac7f1d7b54c9b631e37e8cbaf853799ae9e07d Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 02:02:29 +0800 Subject: [PATCH 14/24] Refactoring --- .../java/seedu/address/model/task/Entry.java | 2 +- src/test/java/guitests/AddCommandTest.java | 2 +- .../seedu/address/logic/LogicManagerTest.java | 5 ---- .../java/seedu/address/testutil/TestUtil.java | 30 ------------------- 4 files changed, 2 insertions(+), 37 deletions(-) diff --git a/src/main/java/seedu/address/model/task/Entry.java b/src/main/java/seedu/address/model/task/Entry.java index 44232eeedc16..447166b044e3 100644 --- a/src/main/java/seedu/address/model/task/Entry.java +++ b/src/main/java/seedu/address/model/task/Entry.java @@ -151,7 +151,7 @@ public final String markString() { public abstract String getDateDisplay(LocalDateTime dateTime); /** - * Formats the Entry as text, showing all contact details. + * Formats the Entry as text, showing all task details. */ //@@author A0116603R public String getAsText() { diff --git a/src/test/java/guitests/AddCommandTest.java b/src/test/java/guitests/AddCommandTest.java index 5ed33f489d74..0f5f7e252a00 100644 --- a/src/test/java/guitests/AddCommandTest.java +++ b/src/test/java/guitests/AddCommandTest.java @@ -47,7 +47,7 @@ private void assertAddSuccess(TestEntry testEntry, TestEntry... currentList) { commandBox.runCommand(testEntry.getAddCommand()); //confirm the new card contains the right data - TaskCardHandle addedCard = taskList.navigateToPerson(testEntry.getTitle().fullTitle); + TaskCardHandle addedCard = taskList.navigateToEntry(testEntry.getTitle().fullTitle); assertMatching(testEntry, addedCard); //confirm the list now contains all previous persons plus the new task diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index dc5b346ce98e..619d36f135d3 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -8,7 +8,6 @@ import org.junit.rules.TemporaryFolder; import seedu.address.commons.core.EventsCenter; import seedu.address.logic.commands.*; -import seedu.address.commons.events.ui.JumpToListRequestEvent; import seedu.address.commons.events.ui.ShowHelpListEvent; import seedu.address.commons.events.model.TaskManagerChangedEvent; import seedu.address.model.TaskManager; @@ -57,10 +56,6 @@ private void handleShowHelpRequestEvent(ShowHelpListEvent she) { helpShown = true; } - @Subscribe - private void handleJumpToListRequestEvent(JumpToListRequestEvent je) { - targetedJumpIndex = je.targetIndex; - } @Before public void setup() { diff --git a/src/test/java/seedu/address/testutil/TestUtil.java b/src/test/java/seedu/address/testutil/TestUtil.java index 6469ec233154..1eef140d79ed 100644 --- a/src/test/java/seedu/address/testutil/TestUtil.java +++ b/src/test/java/seedu/address/testutil/TestUtil.java @@ -38,7 +38,6 @@ */ public class TestUtil { - public static String LS = System.lineSeparator(); public static void assertThrows(Class expected, Runnable executable) { try { @@ -164,35 +163,6 @@ public static KeyCode[] scrub(KeyCodeCombination keyCodeCombination) { return keys.toArray(new KeyCode[]{}); } - public static boolean isHeadlessEnvironment() { - String headlessProperty = System.getProperty("testfx.headless"); - return headlessProperty != null && headlessProperty.equals("true"); - } - - public static void captureScreenShot(String fileName) { - File file = GuiTest.captureScreenshot(); - try { - Files.copy(file, new File(fileName + ".png")); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Gets mid point of a node relative to the screen. - * @param node - * @return - */ - public static Point2D getScreenMidPoint(Node node) { - double x = getScreenPos(node).getMinX() + node.getLayoutBounds().getWidth() / 2; - double y = getScreenPos(node).getMinY() + node.getLayoutBounds().getHeight() / 2; - return new Point2D(x,y); - } - - public static Bounds getScreenPos(Node node) { - return node.localToScreen(node.getBoundsInLocal()); - } - /** * Removes a subset from the list of persons. * @param persons The list of persons From 5420263406b418312496bc2aa269e25478b076a7 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 02:02:45 +0800 Subject: [PATCH 15/24] Rearranging --- .../java/guitests/guihandles/GuiHandle.java | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/test/java/guitests/guihandles/GuiHandle.java b/src/test/java/guitests/guihandles/GuiHandle.java index 1ce09a345602..f669d88504dd 100644 --- a/src/test/java/guitests/guihandles/GuiHandle.java +++ b/src/test/java/guitests/guihandles/GuiHandle.java @@ -2,6 +2,7 @@ import guitests.GuiRobot; import javafx.scene.Node; +import javafx.scene.control.CheckBox; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.input.KeyCode; @@ -31,7 +32,7 @@ public GuiHandle(GuiRobot guiRobot, Stage primaryStage, String stageTitle) { focusOnSelf(); } - public void focusOnWindow(String stageTitle) { + private void focusOnWindow(String stageTitle) { logger.info("Focusing " + stageTitle); java.util.Optional window = guiRobot.listTargetWindows() .stream() @@ -47,33 +48,7 @@ public void focusOnWindow(String stageTitle) { logger.info("Finishing focus " + stageTitle); } - protected Node getNode(String query) { - return guiRobot.lookup(query).tryQuery().get(); - } - - protected String getTextFieldText(String field) { - return ((TextField) getNode(field)).getText(); - } - - protected void setTextField(String textFieldId, String newText) { - guiRobot.clickOn(textFieldId); - ((TextField)primaryStage.getScene().lookup(textFieldId)).setText(newText); - guiRobot.sleep(500); // so that the texts stays visible on the GUI for a short period - } - - public void pressEnter() { - guiRobot.type(KeyCode.ENTER).sleep(200); - } - - public void pressEscape() { - guiRobot.type(KeyCode.ESCAPE).sleep(200); - } - - protected String getTextFromLabel(String fieldId, Node parentNode) { - return ((Label) guiRobot.from(parentNode).lookup(fieldId).tryQuery().get()).getText(); - } - - public void focusOnSelf() { + private void focusOnSelf() { if (stageTitle != null) { focusOnWindow(stageTitle); } @@ -96,4 +71,33 @@ public void closeWindow() { guiRobot.interact(() -> ((Stage)window.get()).close()); focusOnMainApp(); } + + protected Node getNode(String query) { + return guiRobot.lookup(query).tryQuery().get(); + } + + protected String getTextFieldText(String field) { + return ((TextField) getNode(field)).getText(); + } + + protected void setTextField(String textFieldId, String newText) { + guiRobot.clickOn(textFieldId); + ((TextField)primaryStage.getScene().lookup(textFieldId)).setText(newText); + } + + protected String getTextFromLabel(String fieldId, Node parentNode) { + return ((Label) guiRobot.from(parentNode).lookup(fieldId).tryQuery().get()).getText(); + } + + protected boolean getMarkedStatusFromCheckbox(String fieldId, Node parentNode) { + return ((CheckBox)guiRobot.from(parentNode).lookup(fieldId).tryQuery().get()).isSelected(); + } + + public void pressEnter() { + guiRobot.type(KeyCode.ENTER).sleep(50); + } + + public void pressEscape() { + guiRobot.type(KeyCode.ESCAPE).sleep(200); + } } From 1afbee714f16b1c2a71cec41ede1f59777875649 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 02:03:12 +0800 Subject: [PATCH 16/24] Ain't nobody got time for that --- src/test/java/guitests/guihandles/CommandBoxHandle.java | 2 +- src/test/java/guitests/guihandles/HelpWindowHandle.java | 2 -- src/test/java/guitests/guihandles/TaskListHandle.java | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/guitests/guihandles/CommandBoxHandle.java b/src/test/java/guitests/guihandles/CommandBoxHandle.java index 57d2e8ef2239..aab5290b5407 100644 --- a/src/test/java/guitests/guihandles/CommandBoxHandle.java +++ b/src/test/java/guitests/guihandles/CommandBoxHandle.java @@ -28,7 +28,7 @@ public String getCommandInput() { public void runCommand(String command) { enterCommand(command); pressEnter(); - guiRobot.sleep(100); //Give time for the command to take effect + guiRobot.sleep(50); //Give time for the command to take effect } public HelpWindowHandle runHelpCommand() { diff --git a/src/test/java/guitests/guihandles/HelpWindowHandle.java b/src/test/java/guitests/guihandles/HelpWindowHandle.java index 0918640868c6..44dbe50523ef 100644 --- a/src/test/java/guitests/guihandles/HelpWindowHandle.java +++ b/src/test/java/guitests/guihandles/HelpWindowHandle.java @@ -16,7 +16,6 @@ public class HelpWindowHandle extends GuiHandle { public HelpWindowHandle(GuiRobot guiRobot, Stage primaryStage) { super(guiRobot, primaryStage, HELP_WINDOW_TITLE); - guiRobot.sleep(300); } public boolean isVisible() { @@ -25,7 +24,6 @@ public boolean isVisible() { public void closeWindow() { super.closeWindow(); - guiRobot.sleep(500); } } diff --git a/src/test/java/guitests/guihandles/TaskListHandle.java b/src/test/java/guitests/guihandles/TaskListHandle.java index 243b727ccc2a..44494144e7ba 100644 --- a/src/test/java/guitests/guihandles/TaskListHandle.java +++ b/src/test/java/guitests/guihandles/TaskListHandle.java @@ -114,7 +114,7 @@ public TaskCardHandle navigateToPerson(Entry person) { guiRobot.interact(() -> { getListView().scrollTo(index); - guiRobot.sleep(150); + guiRobot.sleep(100); getListView().getSelectionModel().select(index); }); guiRobot.sleep(100); From 09bde9e0a1386f8b32ad61d89b7c1ddb665eb057 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 02:03:28 +0800 Subject: [PATCH 17/24] Some cleaning up --- .../guitests/guihandles/TaskCardHandle.java | 13 ++++++-- .../guitests/guihandles/TaskListHandle.java | 30 ++++++++----------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/test/java/guitests/guihandles/TaskCardHandle.java b/src/test/java/guitests/guihandles/TaskCardHandle.java index 1403b75542c6..45b408b821ba 100644 --- a/src/test/java/guitests/guihandles/TaskCardHandle.java +++ b/src/test/java/guitests/guihandles/TaskCardHandle.java @@ -13,18 +13,23 @@ public class TaskCardHandle extends GuiHandle { private static final String DESCRIPTION_FIELD_ID = "#description"; private static final String TAGS_FIELD_ID = "#tags"; private static final String DEADLINE_FIELD_ID = "#deadline"; + private static final String CHECKBOX_FIELD_ID = "#checkBox"; private Node node; - public TaskCardHandle(GuiRobot guiRobot, Stage primaryStage, Node node){ + TaskCardHandle(GuiRobot guiRobot, Stage primaryStage, Node node){ super(guiRobot, primaryStage, null); this.node = node; } - protected String getTextFromLabel(String fieldId) { + private String getTextFromLabel(String fieldId) { return getTextFromLabel(fieldId, node); } + private boolean getMarkedStatusFromCheckbox(String fieldId) { + return getMarkedStatusFromCheckbox(fieldId, node); + } + public String getTitle() { return getTextFromLabel(TITLE_FIELD_ID); } @@ -41,6 +46,10 @@ public String getDeadline() { return getTextFromLabel(DEADLINE_FIELD_ID); } + public boolean getIsMarked() { + return getMarkedStatusFromCheckbox(CHECKBOX_FIELD_ID); + } + public boolean isSameEntry(Entry entry){ return getTitle().equals(entry.getTitle().fullTitle); } diff --git a/src/test/java/guitests/guihandles/TaskListHandle.java b/src/test/java/guitests/guihandles/TaskListHandle.java index 44494144e7ba..a1c5ebb3fa58 100644 --- a/src/test/java/guitests/guihandles/TaskListHandle.java +++ b/src/test/java/guitests/guihandles/TaskListHandle.java @@ -2,7 +2,6 @@ import guitests.GuiRobot; -import javafx.geometry.Point2D; import javafx.scene.Node; import javafx.scene.control.ListView; import javafx.stage.Stage; @@ -24,8 +23,7 @@ public class TaskListHandle extends GuiHandle { public static final int NOT_FOUND = -1; - public static final String CARD_PANE_ID = "#cardPane"; - + private static final String CARD_PANE_ID = "#cardPane"; private static final String TASK_LIST_ID = "#taskListView"; public TaskListHandle(GuiRobot guiRobot, Stage primaryStage) { @@ -38,10 +36,10 @@ public ListView getListView() { /** * Returns true if the list is showing the task details correctly and in correct order. - * @param persons A list of task in the correct order. + * @param entries A list of task in the correct order. */ - public boolean isListMatching(Entry... persons) { - return this.isListMatching(0, persons); + public boolean isListMatching(Entry... entries) { + return this.isListMatching(0, entries); } /** @@ -87,7 +85,7 @@ public boolean isListMatching(int startPosition, Entry... persons) throws Illega for (int i = 0; i < persons.length; i++) { final int scrollTo = i + startPosition; guiRobot.interact(() -> getListView().scrollTo(scrollTo)); - guiRobot.sleep(200); + guiRobot.sleep(100); if (!TestUtil.compareCardAndEntry(getPersonCardHandle(startPosition + i), persons[i])) { return false; } @@ -96,36 +94,34 @@ public boolean isListMatching(int startPosition, Entry... persons) throws Illega } - public TaskCardHandle navigateToPerson(String title) { - guiRobot.sleep(500); //Allow a bit of time for the list to be updated + public TaskCardHandle navigateToEntry(String title) { final Optional entry = getListView().getItems().stream().filter(p -> p.getTitle().fullTitle.equals(title)).findAny(); if (!entry.isPresent()) { throw new IllegalStateException("Name not found: " + title); } - return navigateToPerson(entry.get()); + return navigateToEntry(entry.get()); } /** * Navigates the listview to display and select the task. */ - public TaskCardHandle navigateToPerson(Entry person) { - int index = getPersonIndex(person); + public TaskCardHandle navigateToEntry(Entry entry) { + int index = getTaskIndex(entry); guiRobot.interact(() -> { getListView().scrollTo(index); guiRobot.sleep(100); getListView().getSelectionModel().select(index); }); - guiRobot.sleep(100); - return getPersonCardHandle(person); + return getPersonCardHandle(entry); } /** * Returns the position of the task given, {@code NOT_FOUND} if not found in the list. */ - public int getPersonIndex(Entry targetEntry) { + public int getTaskIndex(Entry targetEntry) { List personsInList = getListView().getItems(); for (int i = 0; i < personsInList.size(); i++) { if(personsInList.get(i).getTitle().equals(targetEntry.getTitle())){ @@ -138,8 +134,8 @@ public int getPersonIndex(Entry targetEntry) { /** * Gets a task from the list by index */ - public Entry getPerson(int index) { - return getListView().getItems().get(index); + public Entry getEntry(int index) { + return getListView().getItems().get(index-1); } public TaskCardHandle getPersonCardHandle(int index) { From b006b1d41e76485b8a38cc91a5c9cbcbb720f479 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 02:03:53 +0800 Subject: [PATCH 18/24] Add mark and unmark gui tests --- src/test/java/guitests/MarkCommandTest.java | 18 ++++++++++++++++++ src/test/java/guitests/UnmarkCommandTest.java | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/test/java/guitests/MarkCommandTest.java create mode 100644 src/test/java/guitests/UnmarkCommandTest.java diff --git a/src/test/java/guitests/MarkCommandTest.java b/src/test/java/guitests/MarkCommandTest.java new file mode 100644 index 000000000000..ec64c4c2cbd6 --- /dev/null +++ b/src/test/java/guitests/MarkCommandTest.java @@ -0,0 +1,18 @@ +package guitests; + +import org.junit.Test; +import seedu.address.logic.commands.MarkCommand; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX; + +public class MarkCommandTest extends TaskManagerGuiTest { + @Test + public void markFloatingTask() { + int testIndex = 1; + commandBox.runCommand(MarkCommand.COMMAND_WORD + " " + testIndex); + assertResultMessage(String.format(MarkCommand.MESSAGE_SUCCESS, taskList.getEntry(testIndex))); + + commandBox.runCommand(MarkCommand.COMMAND_WORD + " " + Integer.MAX_VALUE); + assertResultMessage(MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX); + } +} diff --git a/src/test/java/guitests/UnmarkCommandTest.java b/src/test/java/guitests/UnmarkCommandTest.java new file mode 100644 index 000000000000..b16d48f72019 --- /dev/null +++ b/src/test/java/guitests/UnmarkCommandTest.java @@ -0,0 +1,18 @@ +package guitests; + +import org.junit.Test; +import seedu.address.logic.commands.UnmarkCommand; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX; + +public class UnmarkCommandTest extends TaskManagerGuiTest{ + @Test + public void unmarkFloatingTask() { + int testIndex = 1; + commandBox.runCommand(UnmarkCommand.COMMAND_WORD + " " + testIndex); + assertResultMessage(String.format(UnmarkCommand.MESSAGE_SUCCESS, taskList.getEntry(testIndex))); + + commandBox.runCommand(UnmarkCommand.COMMAND_WORD + " " + Integer.MAX_VALUE); + assertResultMessage(MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX); + } +} From 5744398dec4f5267f1effeaa0a3a05f5c35403f6 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Sun, 30 Oct 2016 23:37:56 +0800 Subject: [PATCH 19/24] Minor renaming --- .../guitests/guihandles/TaskListHandle.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/test/java/guitests/guihandles/TaskListHandle.java b/src/test/java/guitests/guihandles/TaskListHandle.java index a1c5ebb3fa58..f2d0196a91c9 100644 --- a/src/test/java/guitests/guihandles/TaskListHandle.java +++ b/src/test/java/guitests/guihandles/TaskListHandle.java @@ -50,19 +50,19 @@ public boolean isVisible() { } /** - * Returns true if the {@code persons} appear as the sub list (in that order) at position {@code startPosition}. + * Returns true if the {@code entries} appear as the sub list (in that order) at position {@code startPosition}. */ public boolean containsInOrder(int startPosition, Entry... entries) { - List personsInList = getListView().getItems(); + List entryList = getListView().getItems(); // Return false if the list in panel is too short to contain the given list - if (startPosition + entries.length > personsInList.size()){ + if (startPosition + entries.length > entryList.size()){ return false; } - // Return false if any of the persons doesn't match + // Return false if any of the entries doesn't match for (int i = 0; i < entries.length; i++) { - if (!personsInList.get(startPosition + i).getTitle().fullTitle.equals(entries[i].getTitle().fullTitle)){ + if (!entryList.get(startPosition + i).getTitle().fullTitle.equals(entries[i].getTitle().fullTitle)){ return false; } } @@ -73,20 +73,20 @@ public boolean containsInOrder(int startPosition, Entry... entries) { /** * Returns true if the list is showing the task details correctly and in correct order. * @param startPosition The starting position of the sub list. - * @param persons A list of task in the correct order. + * @param entries A list of task in the correct order. */ - public boolean isListMatching(int startPosition, Entry... persons) throws IllegalArgumentException { - if (persons.length + startPosition != getListView().getItems().size()) { + public boolean isListMatching(int startPosition, Entry... entries) throws IllegalArgumentException { + if (entries.length + startPosition != getListView().getItems().size()) { throw new IllegalArgumentException("List size mismatched\n" + - "Got " + (persons.length) + " persons" + - "Expected " + (getListView().getItems().size() - 1) + " persons"); + "Got " + (entries.length) + " entries" + + "Expected " + (getListView().getItems().size() - 1) + " entries"); } - assertTrue(this.containsInOrder(startPosition, persons)); - for (int i = 0; i < persons.length; i++) { + assertTrue(this.containsInOrder(startPosition, entries)); + for (int i = 0; i < entries.length; i++) { final int scrollTo = i + startPosition; guiRobot.interact(() -> getListView().scrollTo(scrollTo)); guiRobot.sleep(100); - if (!TestUtil.compareCardAndEntry(getPersonCardHandle(startPosition + i), persons[i])) { + if (!TestUtil.compareCardAndEntry(getTaskCardHandle(startPosition + i), entries[i])) { return false; } } @@ -114,7 +114,7 @@ public TaskCardHandle navigateToEntry(Entry entry) { guiRobot.sleep(100); getListView().getSelectionModel().select(index); }); - return getPersonCardHandle(entry); + return getTaskCardHandle(entry); } @@ -122,9 +122,9 @@ public TaskCardHandle navigateToEntry(Entry entry) { * Returns the position of the task given, {@code NOT_FOUND} if not found in the list. */ public int getTaskIndex(Entry targetEntry) { - List personsInList = getListView().getItems(); - for (int i = 0; i < personsInList.size(); i++) { - if(personsInList.get(i).getTitle().equals(targetEntry.getTitle())){ + List entries = getListView().getItems(); + for (int i = 0; i < entries.size(); i++) { + if(entries.get(i).getTitle().equals(targetEntry.getTitle())){ return i; } } @@ -138,17 +138,17 @@ public Entry getEntry(int index) { return getListView().getItems().get(index-1); } - public TaskCardHandle getPersonCardHandle(int index) { - return getPersonCardHandle(new Task(getListView().getItems().get(index))); + public TaskCardHandle getTaskCardHandle(int index) { + return getTaskCardHandle(new Task(getListView().getItems().get(index))); } - public TaskCardHandle getPersonCardHandle(Entry person) { + public TaskCardHandle getTaskCardHandle(Entry person) { Set nodes = getAllCardNodes(); - Optional personCardNode = nodes.stream() + Optional taskCardNode = nodes.stream() .filter(n -> new TaskCardHandle(guiRobot, primaryStage, n).isSameEntry(person)) .findFirst(); - if (personCardNode.isPresent()) { - return new TaskCardHandle(guiRobot, primaryStage, personCardNode.get()); + if (taskCardNode.isPresent()) { + return new TaskCardHandle(guiRobot, primaryStage, taskCardNode.get()); } else { return null; } From 8e30f934952dd0c88ba3e848a29f2fd6391d7709 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Mon, 31 Oct 2016 00:25:09 +0800 Subject: [PATCH 20/24] Update mark command tests + test checkbox --- src/test/java/guitests/MarkCommandTest.java | 44 +++++++++++++++++-- src/test/java/guitests/UnmarkCommandTest.java | 4 +- .../guitests/guihandles/TaskCardHandle.java | 10 +++++ .../guitests/guihandles/TaskListHandle.java | 4 +- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/test/java/guitests/MarkCommandTest.java b/src/test/java/guitests/MarkCommandTest.java index ec64c4c2cbd6..22fc0c0aaf6d 100644 --- a/src/test/java/guitests/MarkCommandTest.java +++ b/src/test/java/guitests/MarkCommandTest.java @@ -1,18 +1,54 @@ package guitests; +import guitests.guihandles.TaskCardHandle; import org.junit.Test; +import seedu.address.commons.events.ui.DidMarkTaskEvent; +import seedu.address.commons.events.ui.MarkTaskEvent; import seedu.address.logic.commands.MarkCommand; +import seedu.address.logic.commands.UndoCommand; +import seedu.address.logic.commands.UnmarkCommand; +import seedu.address.testutil.EventsCollector; +import static junit.framework.TestCase.assertFalse; +import static org.junit.Assert.assertTrue; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX; public class MarkCommandTest extends TaskManagerGuiTest { + + private int testIndex = 0; + @Test - public void markFloatingTask() { - int testIndex = 1; - commandBox.runCommand(MarkCommand.COMMAND_WORD + " " + testIndex); + public void markFloatingTask_viaCommandBox() { + markTask(testIndex+1); assertResultMessage(String.format(MarkCommand.MESSAGE_SUCCESS, taskList.getEntry(testIndex))); - commandBox.runCommand(MarkCommand.COMMAND_WORD + " " + Integer.MAX_VALUE); + markTask(Integer.MAX_VALUE); assertResultMessage(MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX); } + + @Test + public void markFloatingTask_viaGuiClick() { + TaskCardHandle tch = taskList.getTaskCardHandle(testIndex); + + EventsCollector collector = new EventsCollector(); + String expectedMsg = tch.getIsMarked() ? UnmarkCommand.MESSAGE_SUCCESS : MarkCommand.MESSAGE_SUCCESS; + tch.toggleCheckBox(); + assertTrue(collector.get(0) instanceof MarkTaskEvent); + assertResultMessage(String.format(expectedMsg, taskList.getEntry(testIndex))); + } + + @Test + public void markFloatingTaskAndUndo() { + TaskCardHandle tch = taskList.getTaskCardHandle(testIndex); + boolean currState = tch.getIsMarked(); + markTask(testIndex+1); + assertTrue(currState != tch.getIsMarked()); + commandBox.runCommand(UndoCommand.COMMAND_WORD); + assertTrue(currState == tch.getIsMarked()); + } + + // Run the mark command in the command box. Note that the gui uses 1-based indexing. + private void markTask(int testIndex) { + commandBox.runCommand(MarkCommand.COMMAND_WORD + " " + testIndex); + } } diff --git a/src/test/java/guitests/UnmarkCommandTest.java b/src/test/java/guitests/UnmarkCommandTest.java index b16d48f72019..eb250f2247c9 100644 --- a/src/test/java/guitests/UnmarkCommandTest.java +++ b/src/test/java/guitests/UnmarkCommandTest.java @@ -8,8 +8,8 @@ public class UnmarkCommandTest extends TaskManagerGuiTest{ @Test public void unmarkFloatingTask() { - int testIndex = 1; - commandBox.runCommand(UnmarkCommand.COMMAND_WORD + " " + testIndex); + int testIndex = 0; + commandBox.runCommand(UnmarkCommand.COMMAND_WORD + " " + testIndex+1); // gui uses 1-based indexing assertResultMessage(String.format(UnmarkCommand.MESSAGE_SUCCESS, taskList.getEntry(testIndex))); commandBox.runCommand(UnmarkCommand.COMMAND_WORD + " " + Integer.MAX_VALUE); diff --git a/src/test/java/guitests/guihandles/TaskCardHandle.java b/src/test/java/guitests/guihandles/TaskCardHandle.java index 45b408b821ba..a35160ec77d6 100644 --- a/src/test/java/guitests/guihandles/TaskCardHandle.java +++ b/src/test/java/guitests/guihandles/TaskCardHandle.java @@ -2,6 +2,7 @@ import guitests.GuiRobot; import javafx.scene.Node; +import javafx.scene.control.CheckBox; import javafx.stage.Stage; import seedu.address.model.task.Entry; @@ -50,6 +51,15 @@ public boolean getIsMarked() { return getMarkedStatusFromCheckbox(CHECKBOX_FIELD_ID); } + private CheckBox getCheckBox() { + return (CheckBox) guiRobot.from(node).lookup(CHECKBOX_FIELD_ID).tryQuery().get(); + } + + public void toggleCheckBox() { + CheckBox checkBox = getCheckBox(); + guiRobot.clickOn(checkBox); + } + public boolean isSameEntry(Entry entry){ return getTitle().equals(entry.getTitle().fullTitle); } diff --git a/src/test/java/guitests/guihandles/TaskListHandle.java b/src/test/java/guitests/guihandles/TaskListHandle.java index f2d0196a91c9..b1cf4a0c5c41 100644 --- a/src/test/java/guitests/guihandles/TaskListHandle.java +++ b/src/test/java/guitests/guihandles/TaskListHandle.java @@ -135,11 +135,11 @@ public int getTaskIndex(Entry targetEntry) { * Gets a task from the list by index */ public Entry getEntry(int index) { - return getListView().getItems().get(index-1); + return getListView().getItems().get(index); } public TaskCardHandle getTaskCardHandle(int index) { - return getTaskCardHandle(new Task(getListView().getItems().get(index))); + return getTaskCardHandle(new Task(getEntry(index))); } public TaskCardHandle getTaskCardHandle(Entry person) { From 5036bdb4f30395cb144c7da51c2f8a97f0280941 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Mon, 31 Oct 2016 01:02:32 +0800 Subject: [PATCH 21/24] Gui Tests ++Tags, description. WIP. --- .../seedu/address/testutil/EntryBuilder.java | 5 ++ .../seedu/address/testutil/TestTasks.java | 23 +++++- .../address/testutil/TypicalTestTasks.java | 75 ++++++++++++++----- 3 files changed, 83 insertions(+), 20 deletions(-) diff --git a/src/test/java/seedu/address/testutil/EntryBuilder.java b/src/test/java/seedu/address/testutil/EntryBuilder.java index 2c020ee0efcf..ba10d36b02d3 100644 --- a/src/test/java/seedu/address/testutil/EntryBuilder.java +++ b/src/test/java/seedu/address/testutil/EntryBuilder.java @@ -32,6 +32,11 @@ public EntryBuilder withTags(String ... tags) throws IllegalValueException { return this; } + public EntryBuilder withDescription(String description) { + entry.setDescription(description); + return this; + } + public TestEntry build() { return this.entry; } diff --git a/src/test/java/seedu/address/testutil/TestTasks.java b/src/test/java/seedu/address/testutil/TestTasks.java index feac3c6bfad9..e3b1c1de5c44 100644 --- a/src/test/java/seedu/address/testutil/TestTasks.java +++ b/src/test/java/seedu/address/testutil/TestTasks.java @@ -4,17 +4,18 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; //@@author A0116603R /** * An interface representing a category of typical test tasks. */ public interface TestTasks { - default List getAllEntries(String... tasks) { - List entries = new ArrayList<>(); + default List getAllEntries(String... tasks) { + List entries = new ArrayList<>(); for (String task : tasks) { try { - entries.add(new EntryBuilder().withTitle(task).build()); + entries.add(new EntryBuilder().withTitle(task)); } catch (IllegalValueException e) { assert false : "not possible"; } @@ -22,6 +23,11 @@ default List getAllEntries(String... tasks) { return entries; } + default List build(List entryBuilders) { + if (entryBuilders == null) return null; + return entryBuilders.stream().map(EntryBuilder::build).collect(Collectors.toList()); + } + /** * Returns the entries used as sample data for this category of tasks */ @@ -32,4 +38,15 @@ default List getAllEntries(String... tasks) { * a test task manager instance */ List getNonSampleEntries(); + + List getSampleEntriesWithTags(); + List getSampleEntriesWithDescription(); + + default List getBuiltSampleEntriesWithDescription() { + return build(getSampleEntriesWithDescription()); + } + + default List getBuiltSampleEntriesWithTags() { + return build(getSampleEntriesWithTags()); + } } diff --git a/src/test/java/seedu/address/testutil/TypicalTestTasks.java b/src/test/java/seedu/address/testutil/TypicalTestTasks.java index 60c56c1b1e98..c22778ee459b 100644 --- a/src/test/java/seedu/address/testutil/TypicalTestTasks.java +++ b/src/test/java/seedu/address/testutil/TypicalTestTasks.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Set; +import java.util.stream.Collectors; //@@author A0116603R /** @@ -14,55 +15,95 @@ public class TypicalTestTasks { public static class BuyTasks implements TestTasks { + // Leave one task publicly accessible in case one needs direct access public static final String TASK_1 = "Buy apples"; - static final String TASK_2 = "Buy bananas"; - static final String TASK_3 = "Buy cookies"; - static final String TASK_4 = "Buy some time"; + static final String[] SAMPLES = new String[]{TASK_1, "Buy bananas"}; + static final String[] NON_SAMPLES = new String[]{"Buy cookies", "Buy some time"}; public static final String VERB = "Buy"; + static final String[] DEFAULT_TAGS = new String[]{"groceries", "shopping"}; + static final String DEFAULT_DESCRIPTION = "Gotta buy em' all"; + @Override public List getSampleEntries() { - return getAllEntries(TASK_1, TASK_2); + return build(getAllEntries(SAMPLES)); } @Override public List getNonSampleEntries() { - return getAllEntries(TASK_3, TASK_4); + return build(getAllEntries(NON_SAMPLES)); + } + + @Override + public List getSampleEntriesWithTags(){ + return getAllEntries(SAMPLES).stream().map(entryBuilder -> { + try { + return entryBuilder.withTags(DEFAULT_TAGS); + } catch (IllegalValueException e) { + assert false : "not possible"; + } + return null; + }).collect(Collectors.toList()); + } + + @Override + public List getSampleEntriesWithDescription() { + return getAllEntries(SAMPLES).stream().map(entryBuilder -> entryBuilder.withDescription(DEFAULT_DESCRIPTION)).collect(Collectors.toList()); } } private static class StudyTasks implements TestTasks { - static final String TASK_1 = "Study for finals"; - static final String TASK_2 = "Do assignment 1"; - static final String TASK_3 = "Read up on unit testing"; - static final String TASK_4 = "Code for project"; + static final String[] SAMPLES = new String[]{"Study for finals", "Do assignment 1"}; + static final String[] NON_SAMPLES = new String[]{"Read up on unit testing", "Code for project"}; + + static final String DEFAULT_DESCRIPTION = "A short little description which grew longer"; @Override public List getSampleEntries() { - return getAllEntries(TASK_1, TASK_2); + return build(getAllEntries(SAMPLES)); } @Override public List getNonSampleEntries() { - return getAllEntries(TASK_3, TASK_4); + return build(getAllEntries(NON_SAMPLES)); + } + + @Override + public List getSampleEntriesWithTags() { + return null; + } + + @Override + public List getSampleEntriesWithDescription() { + return getAllEntries(SAMPLES).stream().map(entryBuilder -> entryBuilder.withDescription(DEFAULT_DESCRIPTION)).collect(Collectors.toList()); } } public static class WatchTasks implements TestTasks { - static final String TASK_1 = "Watch movie"; - static final String TASK_2 = "Watch Black Mirror"; + static final String[] SAMPLES = new String[]{"Watch movie", "Watch Black Mirror"}; + static final String[] NON_SAMPLES = new String[]{"Watch Doctor Who", "Watch Big Hero 6"}; public static final String VERB = "Watch"; @Override public List getSampleEntries() { - return getAllEntries(TASK_1); + return build(getAllEntries(SAMPLES)); } @Override public List getNonSampleEntries() { - return getAllEntries(TASK_2); + return build(getAllEntries(NON_SAMPLES)); + } + + @Override + public List getSampleEntriesWithTags() { + return null; + } + + @Override + public List getSampleEntriesWithDescription() { + return null; } } @@ -77,8 +118,8 @@ public void loadAddressBookWithSampleData(TaskManager taskManager) { } private List getSampleEntries() { - List allTestEntries = new BuyTasks().getSampleEntries(); - allTestEntries.addAll(new StudyTasks().getSampleEntries()); + List allTestEntries = new BuyTasks().getBuiltSampleEntriesWithTags(); + allTestEntries.addAll(new StudyTasks().getBuiltSampleEntriesWithDescription()); allTestEntries.addAll(new WatchTasks().getSampleEntries()); return allTestEntries; } From 52b7c960824b3c00012d1e8d27a489f57210d28b Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Wed, 2 Nov 2016 01:32:52 +0800 Subject: [PATCH 22/24] Fix mark and unmark command test after merging --- src/test/java/guitests/MarkCommandTest.java | 15 +++++++++------ src/test/java/guitests/UnmarkCommandTest.java | 4 +++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/test/java/guitests/MarkCommandTest.java b/src/test/java/guitests/MarkCommandTest.java index 22fc0c0aaf6d..81889f8c277f 100644 --- a/src/test/java/guitests/MarkCommandTest.java +++ b/src/test/java/guitests/MarkCommandTest.java @@ -7,6 +7,7 @@ import seedu.address.logic.commands.MarkCommand; import seedu.address.logic.commands.UndoCommand; import seedu.address.logic.commands.UnmarkCommand; +import seedu.address.model.task.Entry; import seedu.address.testutil.EventsCollector; import static junit.framework.TestCase.assertFalse; @@ -19,8 +20,10 @@ public class MarkCommandTest extends TaskManagerGuiTest { @Test public void markFloatingTask_viaCommandBox() { + Entry entry = taskList.getEntry(testIndex); + boolean isMarked = entry.isMarked(); markTask(testIndex+1); - assertResultMessage(String.format(MarkCommand.MESSAGE_SUCCESS, taskList.getEntry(testIndex))); + assertTrue(isMarked != entry.isMarked()); markTask(Integer.MAX_VALUE); assertResultMessage(MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX); @@ -28,23 +31,23 @@ public void markFloatingTask_viaCommandBox() { @Test public void markFloatingTask_viaGuiClick() { + Entry entry = taskList.getEntry(testIndex); TaskCardHandle tch = taskList.getTaskCardHandle(testIndex); - EventsCollector collector = new EventsCollector(); String expectedMsg = tch.getIsMarked() ? UnmarkCommand.MESSAGE_SUCCESS : MarkCommand.MESSAGE_SUCCESS; tch.toggleCheckBox(); - assertTrue(collector.get(0) instanceof MarkTaskEvent); - assertResultMessage(String.format(expectedMsg, taskList.getEntry(testIndex))); + assertResultMessage(String.format(expectedMsg, entry)); } @Test public void markFloatingTaskAndUndo() { + Entry entry = taskList.getEntry(testIndex); TaskCardHandle tch = taskList.getTaskCardHandle(testIndex); boolean currState = tch.getIsMarked(); markTask(testIndex+1); - assertTrue(currState != tch.getIsMarked()); + assertTrue(currState != entry.isMarked()); commandBox.runCommand(UndoCommand.COMMAND_WORD); - assertTrue(currState == tch.getIsMarked()); + assertTrue(currState == entry.isMarked()); } // Run the mark command in the command box. Note that the gui uses 1-based indexing. diff --git a/src/test/java/guitests/UnmarkCommandTest.java b/src/test/java/guitests/UnmarkCommandTest.java index eb250f2247c9..119e1ec1d715 100644 --- a/src/test/java/guitests/UnmarkCommandTest.java +++ b/src/test/java/guitests/UnmarkCommandTest.java @@ -2,6 +2,7 @@ import org.junit.Test; import seedu.address.logic.commands.UnmarkCommand; +import seedu.address.model.task.Entry; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX; @@ -9,8 +10,9 @@ public class UnmarkCommandTest extends TaskManagerGuiTest{ @Test public void unmarkFloatingTask() { int testIndex = 0; + Entry entry = taskList.getEntry(testIndex); commandBox.runCommand(UnmarkCommand.COMMAND_WORD + " " + testIndex+1); // gui uses 1-based indexing - assertResultMessage(String.format(UnmarkCommand.MESSAGE_SUCCESS, taskList.getEntry(testIndex))); + assertResultMessage(String.format(UnmarkCommand.MESSAGE_SUCCESS, entry)); commandBox.runCommand(UnmarkCommand.COMMAND_WORD + " " + Integer.MAX_VALUE); assertResultMessage(MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX); From 5c3b0f09fe0159426e285352968da602403389ba Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Wed, 2 Nov 2016 01:33:06 +0800 Subject: [PATCH 23/24] Update TestTasks after merge --- src/test/java/seedu/address/testutil/TestTasks.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/address/testutil/TestTasks.java b/src/test/java/seedu/address/testutil/TestTasks.java index e3b1c1de5c44..b916502f0887 100644 --- a/src/test/java/seedu/address/testutil/TestTasks.java +++ b/src/test/java/seedu/address/testutil/TestTasks.java @@ -1,7 +1,9 @@ package seedu.address.testutil; import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.task.EntryViewComparator; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -15,7 +17,7 @@ default List getAllEntries(String... tasks) { List entries = new ArrayList<>(); for (String task : tasks) { try { - entries.add(new EntryBuilder().withTitle(task)); + entries.add(new EntryBuilder().withTitle(task).withLastModifiedDate(LocalDateTime.now())); } catch (IllegalValueException e) { assert false : "not possible"; } @@ -25,7 +27,7 @@ default List getAllEntries(String... tasks) { default List build(List entryBuilders) { if (entryBuilders == null) return null; - return entryBuilders.stream().map(EntryBuilder::build).collect(Collectors.toList()); + return entryBuilders.stream().map(EntryBuilder::build).sorted(new EntryViewComparator()).collect(Collectors.toList()); } /** From a9fbf79c72fb00cc232941f5df6550abffabc9e8 Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Wed, 2 Nov 2016 01:35:41 +0800 Subject: [PATCH 24/24] @@author tags --- src/test/java/guitests/CommandBoxTest.java | 1 + src/test/java/guitests/GuiUtilTest.java | 1 + src/test/java/guitests/MarkCommandTest.java | 1 + src/test/java/guitests/UnmarkCommandTest.java | 1 + 4 files changed, 4 insertions(+) diff --git a/src/test/java/guitests/CommandBoxTest.java b/src/test/java/guitests/CommandBoxTest.java index 3db3f2a3242a..18cbf7f20468 100644 --- a/src/test/java/guitests/CommandBoxTest.java +++ b/src/test/java/guitests/CommandBoxTest.java @@ -22,6 +22,7 @@ public void commandBox_commandFails_textStays(){ assertEquals(commandBox.getCommandInput(), "invalid command text remains"); } + //@@author A0116603R @Test public void commandBox_commandFails_redBorder() { commandBox.runCommand("invalid command produces error styling"); diff --git a/src/test/java/guitests/GuiUtilTest.java b/src/test/java/guitests/GuiUtilTest.java index 3555934a02b5..a33d27d7a553 100644 --- a/src/test/java/guitests/GuiUtilTest.java +++ b/src/test/java/guitests/GuiUtilTest.java @@ -8,6 +8,7 @@ import static org.junit.Assert.assertEquals; import static seedu.address.ui.util.GuiUtil.*; +//@@author A0116603R public class GuiUtilTest { private LocalDateTime now = LocalDateTime.now(); diff --git a/src/test/java/guitests/MarkCommandTest.java b/src/test/java/guitests/MarkCommandTest.java index 81889f8c277f..d22c3c7e08d8 100644 --- a/src/test/java/guitests/MarkCommandTest.java +++ b/src/test/java/guitests/MarkCommandTest.java @@ -14,6 +14,7 @@ import static org.junit.Assert.assertTrue; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX; +//@@author A0116603R public class MarkCommandTest extends TaskManagerGuiTest { private int testIndex = 0; diff --git a/src/test/java/guitests/UnmarkCommandTest.java b/src/test/java/guitests/UnmarkCommandTest.java index 119e1ec1d715..0a8c84e7e638 100644 --- a/src/test/java/guitests/UnmarkCommandTest.java +++ b/src/test/java/guitests/UnmarkCommandTest.java @@ -6,6 +6,7 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX; +//@@author A0116603R public class UnmarkCommandTest extends TaskManagerGuiTest{ @Test public void unmarkFloatingTask() {