View on GitHub

main

Must Do List ( Task Scheduler Application )

A0138696L

\java\guitests\ExportCommandTest.java

public class ExportCommandTest extends TaskSchedulerGuiTest {

    @Test
    public void exportFilePath() {
        
        // check for exported file
        String exportingPath = "datatest/testing.xml";
        String exportedFile = null;
        commandBox.runCommand("export " + exportingPath);
        File file = new File(exportingPath);
        if (FileUtil.isFileExists(file)) {
            exportedFile = exportingPath;
        }
        assertEquals(exportingPath, exportedFile);
        
        // check for invalid file path
        exportingPath = "datatest/testing@123.xml";
        commandBox.runCommand("export " + exportingPath);
        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ExportCommand.MESSAGE_USAGE));
    }
}
\java\guitests\FindCommandTest.java

public class FindCommandTest extends TaskSchedulerGuiTest {

    @Test
    public void find_nonEmptyList() {
        assertFindResult("find Mark"); //no results
        assertFindResult("find project", td.benson, td.carl, td.george); //multiple results

        //undo list command
        commandBox.runCommand("list");
        assertResultMessage(ListCommand.MESSAGE_SUCCESS);
        assertFindResult("undo", td.benson, td.carl, td.george);
        
        //find after deleting one result
        commandBox.runCommand("delete 1");
        assertFindResult("find Groupwork", td.daniel);
        //undo find command
        assertFindResult("undo", td.carl, td.george);
    }
    
    @Test
    public void find_date_success() {
        assertFindResult("find 14-Oct-2016", td.benson, td.carl);
    }
    
    @Test
    public void find_address_success() {
        assertFindResult("find hall", td.daniel, td.elle);
    }
    
    @Test
    public void find_completed_success() {
        commandBox.runCommand("mark 1");
        commandBox.runCommand("mark 4");
        assertFindResult("find Completed", td.alice, td.daniel);
    }

    @Test
    public void find_emptyList_noResults(){
        commandBox.runCommand("clear");
        assertFindResult("find Jean"); //no results
    }

    @Test
    public void find_invalidCommand_fail() {
        commandBox.runCommand("findsomething");
        assertResultMessage(Messages.MESSAGE_UNKNOWN_COMMAND);
    }

    private void assertFindResult(String command, TestTask... expectedHits ) {
        commandBox.runCommand(command);
        assertListSize(expectedHits.length);
        assertResultMessage(expectedHits.length + " tasks listed!");
        assertTrue(taskListPanel.isListMatching(expectedHits));
    }
}
\java\guitests\ImportCommandTest.java

public class ImportCommandTest extends TaskSchedulerGuiTest {

    @Test
    public void importFilePath() {
        
        // Checking for non-existence file
        String importingPath = "datatest/testing123123.xml";
        commandBox.runCommand("import " + importingPath);
        assertResultMessage(ImportCommand.MESSAGE_UNSUCCESS + importingPath + "\n" + ImportCommand.MESSAGE_USAGE_INVALID);
        
        // Checking for invalid importing file format
        importingPath = "datatest/testing.txt";
        commandBox.runCommand("import " + importingPath);
        assertResultMessage(ImportCommand.MESSAGE_UNSUCCESS + importingPath + "\n" + ImportCommand.MESSAGE_USAGE_INVALID);
        
        importingPath = "datatest/testing.asdasd";
 
        commandBox.runCommand("import " + importingPath);
        assertResultMessage(ImportCommand.MESSAGE_UNSUCCESS + importingPath + "\n" + ImportCommand.MESSAGE_USAGE_INVALID);
        
        importingPath = "datatest/-testing-.xml";
        commandBox.runCommand("import " + importingPath);
        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ImportCommand.MESSAGE_USAGE));
        
        importingPath = "datatest/@testing.xml";
        commandBox.runCommand("import " + importingPath);
        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ImportCommand.MESSAGE_USAGE));
    }
}
\java\guitests\MarkCommandTest.java
    @Test
    public void mark() {

        //mark without index given
        commandBox.runCommand("mark");
        assertResultMessage(String.format(Messages.MESSAGE_PREV_TASK_NOT_FOUND));
        
        //mark the first in the list
        TestTask[] currentList = td.getTypicalTasks();
        int targetIndex = 1;
        assertMarkSuccess(targetIndex, currentList);
        
        //mark the last in the list
        targetIndex = currentList.length;
        assertMarkSuccess(targetIndex, currentList);
        
        //invalid index
        commandBox.runCommand("mark " + currentList.length + 1);
        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        
        //mark the first in the list again
        targetIndex = 1;
        commandBox.runCommand("mark " + targetIndex);
        assertResultMessage(MarkCommand.MESSAGE_MARK_TASK_FAIL);
        
        //mark empty list
        commandBox.runCommand("clear");
        commandBox.runCommand("mark " + currentList.length + 1);
        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);

    }

\java\guitests\SetPathCommandTest.java

public class SetPathCommandTest extends TaskSchedulerGuiTest {

    @Test
    public void setPath() {
       
        // Checking for undo setpath
        Config origConfig = initConfig("ConfigTest.json");
        String exceptedInitialFilePath = origConfig.getTaskSchedulerFilePath();
        
        String setPath = "data/testing123.xml";
        commandBox.runCommand("setpath " + setPath);
        commandBox.runCommand("setpath " + setPath + "456");
        commandBox.runCommand("undo");
        commandBox.runCommand("undo");
        String currFilePath = origConfig.getTaskSchedulerFilePath();
        assertEquals(exceptedInitialFilePath.toString(), currFilePath);
        
        // Checking for the existence of User specified filename or path.
        String newPath = "testtaskscheduler.xml";
        commandBox.runCommand("setpath " + newPath);
        File expected = new File(newPath);
        assertEquals(expected.toString(), newPath);
        assertResultMessage(String.format(SetpathCommand.MESSAGE_SUCCESS, newPath));
        
        // Checking for the consistency of setting, repeatedly, of setpath <filename> in ConfigTest.json.
        origConfig = initConfig("ConfigTest.json");
        String origPath = origConfig.getTaskSchedulerFilePath();
        String newPath2 = "taskscheduler.xml";
        
        commandBox.runCommand("setpath " + newPath2);
        assertResultMessage(String.format(SetpathCommand.MESSAGE_SUCCESS, newPath2));
        
        origConfig = initConfig("ConfigTest.json");
        String compareString = origConfig.getTaskSchedulerFilePath();
        assertEquals(newPath2, compareString);
        
        commandBox.runCommand("setpath " + origPath);
        assertResultMessage(String.format(SetpathCommand.MESSAGE_SUCCESS, origPath));
        
        origConfig = initConfig("ConfigTest.json");
        String compareString2 = origConfig.getTaskSchedulerFilePath();
        assertEquals(origPath, compareString2);
        
    }
    
    protected Config initConfig(String configFilePath) {
        Config initializedConfig;
        String configFilePathUsed;

        configFilePathUsed = "ConfigTest.json";

        if(configFilePath != null) {
            configFilePathUsed = configFilePath;
        }

        try {
            Optional<Config> configOptional = ConfigUtil.readConfig(configFilePathUsed);
            initializedConfig = configOptional.orElse(new Config());
        } catch (DataConversionException e) {
            initializedConfig = new Config();
        }

        //Update config file in case it was missing to begin with or there are new/unused fields
        try {
            ConfigUtil.saveConfig(initializedConfig, configFilePathUsed);
        } catch (IOException e) {
        }
        return initializedConfig;
    }
}
\java\guitests\UnmarkCommandTest.java

/**
 * Undo a unmark command in the task scheduler.
 */

public class UnmarkCommandTest extends TaskSchedulerGuiTest {
    
    @Test
    public void unmark() {
        
        //unmark without index given
        unmark_noIndex_messageNoTaskFound();
        
        TestTask[] currentList = td.getTypicalTasks();
        
        //initialise with some marked tasks
        runMarkCommand(1, currentList.length, currentList.length/2);
        currentList = td.getTypicalTasks();
        
        //unmark the first in the list
        int targetIndex = 1;
        assertUnmarkSuccess(targetIndex, currentList);
        
        //unmark the last in the list
        targetIndex = currentList.length;
        assertUnmarkSuccess(targetIndex, currentList);
        
        //unmark the middle in the list
        targetIndex = currentList.length/2;
        assertUnmarkSuccess(targetIndex, currentList);
        
        //invalid index - unmark
        commandBox.runCommand("unmark " + currentList.length + 1);
        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
        
        //unmark the first in the list again
        targetIndex = 1;
        commandBox.runCommand("unmark " + targetIndex);
        assertResultMessage(UnmarkCommand.MESSAGE_UNMARK_TASK_FAIL);
        
        //mark empty list
        commandBox.runCommand("clear");
        commandBox.runCommand("unmark " + currentList.length + 1);
        assertResultMessage(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);

    }

    private void unmark_noIndex_messageNoTaskFound() {
        commandBox.runCommand("unmark");
        assertResultMessage(Messages.MESSAGE_PREV_TASK_NOT_FOUND);
    }
    
    public void runMarkCommand(int... indices) {
        for (int index : indices) {
            commandBox.runCommand("mark " + index);
        }
    }

    /**
     * Runs the unmark command to unmark the task at specified index as uncompleted and confirms the result is correct.
     * @param targetIndexOneIndexed e.g. to unmark the first task in the list, 1 should be given as the target index.
     * @param currentList A copy of the current list of tasks (before deletion).S
     */
    public void assertUnmarkSuccess(int targetIndexOneIndexed, final TestTask[] currentList) {
        
        TestTask taskToUnMark = currentList[targetIndexOneIndexed-1]; //-1 because array uses zero indexing
        
        commandBox.runCommand("unmark " + targetIndexOneIndexed);
        
        //confirm the task card is now marked uncompleted.
        assertFalse(taskListPanel.navigateToTask(targetIndexOneIndexed - 1).getPaintFromShape().equals(TaskCard.COMPLETED_INDICATION));
        //confirm the result message is correct
        assertResultMessage(String.format(UnmarkCommand.MESSAGE_UNMARK_TASK_SUCCESS, taskToUnMark));
    }
}
\java\seedu\taskscheduler\commons\util\CollectionUtilTest.java

public class CollectionUtilTest {

    @Test
    public void isAnyNull_nullElement_trueReturned() {
        Object nullElement = null;
        assertTrue(CollectionUtil.isAnyNull("one", "two", nullElement, "three"));
    }
    
    @Test
    public void isAllNull_emptyList_trueReturned() {
        assertTrue(CollectionUtil.isAllNull());
    }
    
    @Test
    public void elementsAreUnique_duplicateElements_falseReturned() {
        final ArrayList<String> duplicateList = new ArrayList<>();
        duplicateList.add("duplicate");
        duplicateList.add("one");
        duplicateList.add("two");
        duplicateList.add("duplicate");
        duplicateList.add("three");
        assertFalse(CollectionUtil.elementsAreUnique(duplicateList));
    }
}