Skip to content

Commit

Permalink
Collated
Browse files Browse the repository at this point in the history
  • Loading branch information
karen committed Nov 2, 2016
1 parent 72bc2f4 commit 6e4a525
Show file tree
Hide file tree
Showing 4 changed files with 408 additions and 5 deletions.
325 changes: 325 additions & 0 deletions collated/test/A0116603R.md
Original file line number Diff line number Diff line change
@@ -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<EntryBuilder> getAllEntries(String... tasks) {
List<EntryBuilder> 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<TestEntry> build(List<EntryBuilder> 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<TestEntry> getSampleEntries();

/**
* Returns the entries used as new data that can be arbitrarily added to
* a test task manager instance
*/
List<TestEntry> getNonSampleEntries();

List<EntryBuilder> getSampleEntriesWithTags();
List<EntryBuilder> getSampleEntriesWithDescription();

default List<TestEntry> getBuiltSampleEntriesWithDescription() {
return build(getSampleEntriesWithDescription());
}

default List<TestEntry> 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<TestEntry> getSampleEntries() {
return build(getAllEntries(SAMPLES));
}

@Override
public List<TestEntry> getNonSampleEntries() {
return build(getAllEntries(NON_SAMPLES));
}

@Override
public List<EntryBuilder> 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<EntryBuilder> 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<TestEntry> getSampleEntries() {
return build(getAllEntries(SAMPLES));
}

@Override
public List<TestEntry> getNonSampleEntries() {
return build(getAllEntries(NON_SAMPLES));
}

@Override
public List<EntryBuilder> getSampleEntriesWithTags() {
return null;
}

@Override
public List<EntryBuilder> 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<TestEntry> getSampleEntries() {
return build(getAllEntries(SAMPLES));
}

@Override
public List<TestEntry> getNonSampleEntries() {
return build(getAllEntries(NON_SAMPLES));
}

@Override
public List<EntryBuilder> getSampleEntriesWithTags() {
return null;
}

@Override
public List<EntryBuilder> 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<TestEntry> getSampleEntries() {
List<TestEntry> allTestEntries = new BuyTasks().getBuiltSampleEntriesWithTags();
allTestEntries.addAll(new StudyTasks().getBuiltSampleEntriesWithDescription());
allTestEntries.addAll(new WatchTasks().getSampleEntries());
return allTestEntries;
}

public TestEntry[] getSampleEntriesAsArray() {
List<TestEntry> allTestEntries = getSampleEntries();
TestEntry[] result = new TestEntry[allTestEntries.size()];
return allTestEntries.toArray(result);
}

public List<TestEntry> getNonSampleEntries() {
List<TestEntry> 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;
}


}
```
Loading

0 comments on commit 6e4a525

Please sign in to comment.