From 6e4a525056512eb4e1ea4a57a80cda58c864e23d Mon Sep 17 00:00:00 2001 From: Karen Ang Date: Wed, 2 Nov 2016 08:21:07 +0800 Subject: [PATCH] Collated --- collated/test/A0116603R.md | 325 +++++++++++++++++++++++++++++++ collated/test/A0116603Rreused.md | 78 ++++++++ collated/test/A0121501E.md | 4 +- collated/test/A0127828W.md | 6 +- 4 files changed, 408 insertions(+), 5 deletions(-) create mode 100644 collated/test/A0116603R.md create mode 100644 collated/test/A0116603Rreused.md diff --git a/collated/test/A0116603R.md b/collated/test/A0116603R.md new file mode 100644 index 000000000000..8fbf7a2c2b1a --- /dev/null +++ b/collated/test/A0116603R.md @@ -0,0 +1,325 @@ +# A0116603R +###### /java/guitests/CommandBoxTest.java +``` java + @Test + public void commandBox_commandFails_redBorder() { + commandBox.runCommand("invalid command produces error styling"); + assertTrue(commandBox.hasErrorClass()); + } + +} +``` +###### /java/guitests/GuiUtilTest.java +``` java +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))); + } + +} +``` +###### /java/guitests/HelpWindowTest.java +``` java + @Test + public void openAndCloseHelpWindow() { + HelpWindowHandle helpWindowHandle = commandBox.runHelpCommand(); + assertHelpWindowOpen(helpWindowHandle); + + helpWindowHandle.pressEscape(); + assertHelpWindowClosed(); + } + + private void assertHelpWindowClosed() { + assertTrue(taskList.isVisible()); + } + +``` +###### /java/guitests/MarkCommandTest.java +``` java +public class MarkCommandTest extends TaskManagerGuiTest { + + private int testIndex = 0; + + @Test + public void markFloatingTask_viaCommandBox() { + Entry entry = taskList.getEntry(testIndex); + boolean isMarked = entry.isMarked(); + markTask(testIndex+1); + assertTrue(isMarked != entry.isMarked()); + + markTask(Integer.MAX_VALUE); + assertResultMessage(MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX); + } + + @Test + public void markFloatingTask_viaGuiClick() { + Entry entry = taskList.getEntry(testIndex); + TaskCardHandle tch = taskList.getTaskCardHandle(testIndex); + + String expectedMsg = tch.getIsMarked() ? UnmarkCommand.MESSAGE_SUCCESS : MarkCommand.MESSAGE_SUCCESS; + tch.toggleCheckBox(); + 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 != entry.isMarked()); + commandBox.runCommand(UndoCommand.COMMAND_WORD); + assertTrue(currState == entry.isMarked()); + } + + // 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); + } +} +``` +###### /java/guitests/UnmarkCommandTest.java +``` java +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, entry)); + + commandBox.runCommand(UnmarkCommand.COMMAND_WORD + " " + Integer.MAX_VALUE); + assertResultMessage(MESSAGE_INVALID_ENTRY_DISPLAYED_INDEX); + } +} +``` +###### /java/seedu/address/testutil/TestTasks.java +``` java +/** + * 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).withLastModifiedDate(LocalDateTime.now())); + } catch (IllegalValueException e) { + assert false : "not possible"; + } + } + return entries; + } + + default List build(List entryBuilders) { + if (entryBuilders == null) return null; + return entryBuilders.stream().map(EntryBuilder::build).sorted(new EntryViewComparator()).collect(Collectors.toList()); + } + + /** + * 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(); + + List getSampleEntriesWithTags(); + List getSampleEntriesWithDescription(); + + default List getBuiltSampleEntriesWithDescription() { + return build(getSampleEntriesWithDescription()); + } + + default List getBuiltSampleEntriesWithTags() { + return build(getSampleEntriesWithTags()); + } +} +``` +###### /java/seedu/address/testutil/TypicalTestTasks.java +``` java +/** + * A class encapsulating typical tasks for test purposes. + */ +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[] 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 build(getAllEntries(SAMPLES)); + } + + @Override + public List getNonSampleEntries() { + 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[] 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 build(getAllEntries(SAMPLES)); + } + + @Override + public List getNonSampleEntries() { + 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[] 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 build(getAllEntries(SAMPLES)); + } + + @Override + public List getNonSampleEntries() { + return build(getAllEntries(NON_SAMPLES)); + } + + @Override + public List getSampleEntriesWithTags() { + return null; + } + + @Override + public List getSampleEntriesWithDescription() { + return null; + } + } + + public void loadAddressBookWithSampleData(TaskManager taskManager) { + for (Entry entry : getSampleEntries()) { + try { + taskManager.addTask(new Task(entry)); + } catch (UniqueTaskList.DuplicateTaskException e) { + assert false : "not possible"; + } + } + } + + private List getSampleEntries() { + List allTestEntries = new BuyTasks().getBuiltSampleEntriesWithTags(); + allTestEntries.addAll(new StudyTasks().getBuiltSampleEntriesWithDescription()); + 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 TestEntry[] getTypicalSortedPersons() { + TestEntry[] testEntry = getSampleEntriesAsArray(); + Arrays.sort(testEntry, new EntryViewComparator()); + return testEntry; + } + + 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; + } + + +} +``` diff --git a/collated/test/A0116603Rreused.md b/collated/test/A0116603Rreused.md new file mode 100644 index 000000000000..40f195a68de4 --- /dev/null +++ b/collated/test/A0116603Rreused.md @@ -0,0 +1,78 @@ +# A0116603Rreused +###### /java/guitests/AddCommandTest.java +``` java + @Test + public void add() { + TestEntry[] currentList = td.getTypicalSortedPersons(); // sample entries already present + TestEntry 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(currentList[0].getAddCommand()); + assertResultMessage(AddCommand.MESSAGE_DUPLICATE_ENTRY); + assertTrue(taskList.isListMatching(currentList)); + + //add to empty list + commandBox.runCommand(ClearCommand.COMMAND_WORD); + assertAddSuccess(currentList[0]); + + //invalid command + commandBox.runCommand("adds Johnny"); + assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND); + + } + +``` +###### /java/guitests/ListCommandTest.java +``` java + @Test + public void list_nonEmptyList() { + // 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()); + + // 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(){ + // clear the list and assert search miss + commandBox.runCommand(ClearCommand.COMMAND_WORD); + assertListResult(ListCommand.COMMAND_WORD + " " + TypicalTestTasks.BuyTasks.VERB); + } + + @Test + public void list_invalidCommand_fail() { + commandBox.runCommand("listdoge"); + assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND); + } + + private void assertListResult(String command, TestEntry... expectedHits ) { + Arrays.sort(expectedHits, new EntryViewComparator()); + commandBox.runCommand(command); + assertListSize(expectedHits.length); + 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); + } +} +``` diff --git a/collated/test/A0121501E.md b/collated/test/A0121501E.md index 6b58c17cde03..2ee3ae5d176e 100644 --- a/collated/test/A0121501E.md +++ b/collated/test/A0121501E.md @@ -1,5 +1,5 @@ # A0121501E -###### \java\seedu\address\logic\LogicManagerTest.java +###### /java/seedu/address/logic/LogicManagerTest.java ``` java @Test public void execute_tag_withoutTagnameArgs_errorMessageShown() throws Exception { @@ -662,7 +662,7 @@ expectedAB.getTaskList()); } ``` -###### \java\seedu\address\testutil\TestUtil.java +###### /java/seedu/address/testutil/TestUtil.java ``` java /** * Adds persons to the array of sorted persons. diff --git a/collated/test/A0127828W.md b/collated/test/A0127828W.md index 4d34880f278b..a604591deaf0 100644 --- a/collated/test/A0127828W.md +++ b/collated/test/A0127828W.md @@ -22,7 +22,7 @@ public class EventTest { isMarked = false; description = "Description"; lastModifiedTime = LocalDateTime.parse("2016-10-10T10:00:00"); - testEvent = new Event(title, startTime, endTime, tags, isMarked, description, lastModifiedTime); + testEvent = new Event(title, startTime, endTime, tags, isMarked, description, -1, lastModifiedTime); } catch (IllegalValueException ive) { ive.printStackTrace(); } @@ -35,7 +35,7 @@ public class EventTest { @Test(expected = ClassCastException.class) public void createEventFromEntry() { - Entry eventEntry = new Event(title, startTime, endTime, tags, isMarked, description, lastModifiedTime); + Entry eventEntry = new Event(title, startTime, endTime, tags, isMarked, description, -1, lastModifiedTime); assertTrue(new Event(eventEntry) instanceof Event); Entry taskEntry = new Task(title, endTime, tags, isMarked, description, lastModifiedTime); @@ -73,7 +73,7 @@ public class EventTest { @Test public void isSameStateAs() { - Event otherEvent = new Event(title, startTime, endTime, tags, isMarked, description, lastModifiedTime); + Event otherEvent = new Event(title, startTime, endTime, tags, isMarked, description, -1, lastModifiedTime); assertTrue(testEvent.isSameStateAs(otherEvent)); }