Skip to content

Commit

Permalink
added some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hliejun committed Mar 23, 2016
1 parent edca72a commit 35c8a7e
Show file tree
Hide file tree
Showing 18 changed files with 571 additions and 550 deletions.
26 changes: 0 additions & 26 deletions src/application/Main.java

This file was deleted.

1 change: 0 additions & 1 deletion src/application/application.css

This file was deleted.

11 changes: 5 additions & 6 deletions src/todolist/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import todolist.ui.controllers.SideBarController;
import todolist.ui.controllers.TodayController;
import todolist.ui.controllers.WeekController;

import javafx.animation.PauseTransition;
import javafx.application.Application;
import javafx.collections.ObservableList;
Expand All @@ -22,7 +23,6 @@
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
Expand Down Expand Up @@ -52,7 +52,7 @@ public class MainApp extends Application {
private static final String MESSAGE_ERROR_LOAD_MAIN = "Error loading main view. Exiting now ...";
private static final String MESSAGE_ERROR_LOAD_TITLEBAR = "Error loading title bar view. Exiting now ...";
private static final String MESSAGE_ERROR_LOAD_SIDEBAR = "Error loading side bar view. Exiting now ...";
private static final String MESSAGE_ERROR_LOAD_EMPTY = "Error loading empty view. Exiting now ...";
// private static final String MESSAGE_ERROR_LOAD_EMPTY = "Error loading empty view. Exiting now ...";

// Notification messages and delay
private static final String NOTIFICATION_WELCOME = "Welcome to ToDoList! Let's get started...";
Expand All @@ -65,7 +65,7 @@ public class MainApp extends Application {
public static final String DIRECTORY_TASKITEM = "ui/views/TaskNode.fxml";

private static final String STYLE_CLASS_ROOT = "root-layout";
private static final String STYLE_CLASS_MAIN = "main-view";
// private static final String STYLE_CLASS_MAIN = "main-view";
private static final String STYLE_CLASS_TITLEBAR = "title-bar";
private static final String STYLE_CLASS_SIDEBAR = "side-bar";

Expand All @@ -76,19 +76,18 @@ public class MainApp extends Application {
private static final String DIRECTORY_ARCHIVE = "ui/views/ArchiveView.fxml";
private static final String DIRECTORY_SETTINGS = "ui/views/SettingsView.fxml";
private static final String DIRECTORY_HELP = "ui/views/HelpView.fxml";
private static final String DIRECTORY_EMPTY = "ui/views/EmptyView.fxml";
// private static final String DIRECTORY_EMPTY = "ui/views/EmptyView.fxml";

private static final String DIRECTORY_NOTIFICATION_SOUND = "ui/views/assets/notification-sound-flyff.wav";
private static final String DIRECTORY_WELCOME_SOUND = "ui/views/assets/notification-sound-twitch.mp3";


// Views: Display and UI components
private BorderPane rootView;
private BorderPane mainView;
private TextField commandField;
private HBox titleBarView;
private VBox sideBarView;
private BorderPane emptyView;
// private BorderPane emptyView;
private BorderPane overdueView;
private BorderPane todayView;
private BorderPane weekView;
Expand Down
64 changes: 64 additions & 0 deletions src/todolist/common/stubs/CommandHandlerStub.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package todolist.common.stubs;

//import java.util.ArrayList;
//
//import todolist.MainApp;
//import todolist.model.Category;
//import todolist.model.Reminder;
//import todolist.ui.TaskWrapper;

public class CommandHandlerStub {

// private static String status = "200: Okay";
// private static ArrayList<Category> categoriesToDisplay = new ArrayList<Category>();
// private static Category currentCategory = new Category("SAMPLE CATEGORY");
// private static ArrayList<TaskWrapper> tasksToDisplay = new ArrayList<TaskWrapper>();
// private static ArrayList<Reminder> remindersToTrack = new ArrayList<Reminder>();
// private static String currentSearch = "";
// private static Page page = Page.Home;

// private MainApp main = null;

// public CommandHandlerStub(MainApp main) {
// this.main = main;
// }

// public void execute(Command command) {

// Feedback feedback= new Feedback(status, page,
// categoriesToDisplay, currentCategory,
// tasksToDisplay,
// remindersToTrack, currentSearch);

// ... Do something

// ArrayList<TaskWrapper> tasksToDisplay = new ArrayList<TaskWrapper>();

// tasksToDisplay.add(new TaskWrapper("Do UI Handler (CHANGED)",
// LocalDateTime.now(), LocalDateTime.now().plusHours(3),
// new Category("CS2103T Project (CHANGED)"), new
// Reminder(LocalDateTime.now().plusHours(3))));
// tasksToDisplay.add(new TaskWrapper("Setup Trello (THIS ALSO CHANGED)",
// LocalDateTime.now(), LocalDateTime.now().plusHours(3),
// new Category("CS2103T Project (CHANGED)"), new
// Reminder(LocalDateTime.now().plusHours(3))));
// tasksToDisplay.add(new TaskWrapper("Prepare CV (CHANGED)",
// LocalDateTime.now(), LocalDateTime.now().plusHours(3),
// new Category("Personal (CHANGED)"), new Priority(1), new
// Reminder(LocalDateTime.now().plusHours(3))));
// tasksToDisplay.add(new TaskWrapper("Buy leather shoes (CHANGED)",
// LocalDateTime.now(), LocalDateTime.now().plusHours(3),
// new Category("Personal (CHANGED)"), new Priority(1), new
// Reminder(LocalDateTime.now().plusHours(3))));
// tasksToDisplay.add(new TaskWrapper("Send emails (CHANGED)",
// LocalDateTime.now(), LocalDateTime.now().plusHours(3),
// new Category("18th MC (CHANGED)"), new Priority(1), new
// Reminder(LocalDateTime.now().plusHours(3))));

// Call my functions ...

// main.setDisplayTasks(tasksToDisplay);

// return feedback;
// }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package todolist.storage;
package todolist.common.tests;

import static org.junit.Assert.*;

Expand All @@ -13,6 +13,7 @@
import todolist.model.Name;
import todolist.model.SearchCommand;
import todolist.model.Task;
import todolist.storage.DataBase;

public class DataBaseTest {

Expand Down
166 changes: 166 additions & 0 deletions src/todolist/common/tests/LogicTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package todolist.common.tests;

import static org.junit.Assert.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

import org.junit.Test;

import todolist.MainApp;
import todolist.logic.Logic;
import todolist.logic.MainAppStub;
import todolist.model.Name;
import todolist.model.Task;

public class LogicTest {

private MainApp mainAppStub = new MainAppStub();

private Logic logic = new Logic(mainAppStub);

public void testProcess() {
boolean expected = true;

Name name = new Name("title");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime start = LocalDateTime.parse("2017-01-01" + " " + "14:00", formatter);
LocalDateTime end = start.plus(Long.parseLong("1"), ChronoUnit.DAYS);
Task newEvent = new Task(name, start, end, null, null, false, false, null);

logic.process("add event title 2017-01-01 14:00 1 day");

Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName());

assertEquals(isEqual, expected);
}

@Test
public void testStepForward() {
int original = logic.checkStep();
logic.stepForward(1);
assertEquals(logic.checkStep(), original + 1);
}

public void testAddRecurringEvent() {
fail("Not yet implemented");
}

public void testAddRecurringDeadline() {
fail("Not yet implemented");
}

@Test
public void testAddEvent() {
Name name = new Name("title");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime start = LocalDateTime.parse("1970-01-01" + " " + "12:00", formatter);
LocalDateTime end = start.plus(Long.parseLong("1"), ChronoUnit.DAYS);
Task newEvent = new Task(name, start, end, null, null, false, false, null);

logic.addEvent("title", "1970-01-01", "12:00", "1", "day");
Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName());
assert(isEqual);
}

@Test
public void testAddDeadline() {
Name name = new Name("title");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime end = LocalDateTime.parse("1970-01-01" + " " + "12:00", formatter);
Task newEvent = new Task(name, null, end, null, null, false, false, null);

logic.addDeadline("title", "1970-01-01", "12:00");
Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName());
assert(isEqual);
}

@Test
public void testAddTask() {
Name name = new Name("title");
Task newEvent = new Task(name, null, null, null, null, false, false, null);
logic.addTask("title");
Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName());
assert(isEqual);
}

@Test
public void testDone() {
logic.addTask("title");
logic.done("title");
Name name = new Name("title");
Task newEvent = new Task(name, null, null, null, null, true, false, null);
Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName());
assert(isEqual);
}

@Test
public void testUndone() {
logic.addTask("title");
logic.done("title");
logic.undone("title");
Name name = new Name("title");
Task newEvent = new Task(name, null, null, null, null, false, false, null);
logic.addTask("title");
Boolean isEqual = logic.dataBase.taskList.get(0).getName().getName().equals(newEvent.getName().getName());
assert(isEqual);
}

public void testEdit() {
fail("Not yet implemented");
}

public void testDelete() {
fail("Not yet implemented");
}

public void testSearch() {
fail("Not yet implemented");
}

public void testLabel() {
fail("Not yet implemented");
}

public void testSetRecurring() {
fail("Not yet implemented");
}

public void testPostpone() {
fail("Not yet implemented");
}

public void testForward() {
fail("Not yet implemented");
}

public void testAddRemind() {
fail("Not yet implemented");
}

public void testAddRemindBef() {
fail("Not yet implemented");
}

public void testRemindBef() {
fail("Not yet implemented");
}

public void testRemind() {
fail("Not yet implemented");
}

public void testExit() {
fail("Not yet implemented");
}

public void testUndo() {
fail("Not yet implemented");
}

public void testRedo() {
fail("Not yet implemented");
}

}
5 changes: 5 additions & 0 deletions src/todolist/common/tests/MainParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package todolist.common.tests;

public class MainParserTest {

}
45 changes: 45 additions & 0 deletions src/todolist/common/tests/NormalCommandParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package todolist.common.tests;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import todolist.model.TokenizedCommand;
import todolist.parser.NormalCommandParser;

public class NormalCommandParserTest {
NormalCommandParser normalCommandParser = null;

@Before
public void initNormalCommandParser() {
normalCommandParser = new NormalCommandParser();
}

@Test
public void testParse() {

final String testCase = " add event CS2103T-Tutorial 2016-03-23 13:00 1 hour";
final String expectedAction = "add";
final int expectedArgsSize = 7;
String[] expectedArgs = new String[expectedArgsSize];
expectedArgs[0] = "add";
expectedArgs[1] = "event";
expectedArgs[2] = "CS2103T-Tutorial";
expectedArgs[3] = "2016-03-23";
expectedArgs[4] = "13:00";
expectedArgs[5] = "1";
expectedArgs[6] = "hour";

TokenizedCommand output = normalCommandParser.parse(testCase);

// assertEquals(expectedAction, output.getAction());
assertEquals(expectedArgsSize, output.getArgs().length);

for (int i = 0; i < output.getArgs().length; ++i) {
String arg = output.getArgs()[i];
assertEquals(expectedArgs[i], arg);
}

}
}
5 changes: 5 additions & 0 deletions src/todolist/common/tests/UIHandlerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package todolist.common.tests;

public class UIHandlerTest {

}
Loading

0 comments on commit 35c8a7e

Please sign in to comment.