Skip to content

Commit

Permalink
Update JUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yisiox committed Feb 17, 2024
1 parent ee119eb commit 5aea5a5
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 42 deletions.
7 changes: 7 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ applications.

![](Ui.png)

## Getting Started

1. Download the `.jar` file from [here](https://github.com/yisiox/ip/releases).
2. Open a terminal in the directory which you saved the `.jar` file, then run
1. `java -jar earl.jar` for GUI mode.
2. `java -jar earl.jar nogui` for TUI mode.

## Quick Reference

| Command | Arguments |
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/earl/Earl.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Earl(String filePath) {
storage = new Storage(filePath);
tasks = new TaskList(storage.load(TaskStorageParser::parse));
if (!storage.wasLoadSuccessful()) {
ui.makeResponse("Storage hath succumb to corruption... ",
ui.buildResponse("Storage hath succumb to corruption... ",
"initiating an unfortunate state of emptiness.");
}
ui.showGreeting();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/earl/gui/Launcher.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package earl.gui;

import earl.Earl;

import javafx.application.Application;

/**
Expand All @@ -13,7 +12,7 @@ public static void main(String[] args) {
Earl earl = new Earl("data/earl.txt");
earl.run();
return;
};
}
Application.launch(Main.class, args);
}
}
1 change: 0 additions & 1 deletion src/main/java/earl/logic/EventHandler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package earl.logic;

import earl.exceptions.EarlException;
import earl.tasks.Task;
import earl.tasks.TaskType;
import earl.util.TaskList;
import earl.util.Ui;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/earl/logic/HandlerType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,49 @@
*/
public enum HandlerType {

list {
LIST {
@Override
public Handler createHandler(String args) {
return new ListHandler(args);
}
},
todo {
TODO {
@Override
public Handler createHandler(String args) {
return new TodoHandler(args);
}
},
deadline {
DEADLINE {
@Override
public Handler createHandler(String args) {
return new DeadlineHandler(args);
}
},
event {
EVENT {
@Override
public Handler createHandler(String args) {
return new EventHandler(args);
}
},
mark {
MARK {
@Override
public Handler createHandler(String args) {
return new MarkHandler(args);
}
},
unmark {
UNMARK {
@Override
public Handler createHandler(String args) {
return new UnmarkHandler(args);
}
},
delete {
DELETE {
@Override
public Handler createHandler(String args) {
return new DeleteHandler(args);
}
},
find {
FIND {
@Override
public Handler createHandler(String args) {
return new FindHandler(args);
Expand Down
20 changes: 7 additions & 13 deletions src/main/java/earl/logic/TaskHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
import earl.tasks.Task;
import earl.tasks.TaskType;
import earl.util.TaskList;
import earl.util.Ui;

/**
* Abstract class representing the adding of a task.
*/
public abstract class TaskHandler extends Handler {

protected final String[] successMessageFormats = {
"A new %s %s",
"hath been appended to the roster of responsibilities.",
"The ledger of tasks bears witness to %d endeavour(s)."};

/** Class constructor. */
public TaskHandler(String args) {
super(args);
Expand All @@ -27,16 +21,16 @@ protected String[] addTask(TaskList tasks, TaskType type, String... data)
Task newTask = type.createTask(data);
tasks.add(newTask);

return new String[]{
String.format(successMessageFormats[0],
type.name().toLowerCase(), newTask.toString()),
successMessageFormats[1],
String.format(successMessageFormats[2], tasks.getSize())};
String first = "A new " + type.name() + " " + newTask.toString();
String second = "hath been appended to the "
+ "roster of responsibilities.";
String third = "The ledger of tasks bears witness to "
+ tasks.getSize() + " endeavour(s).";
return new String[]{first, second, third};
} catch (IndexOutOfBoundsException e) {
throw new EarlException("An error befalls. Example use:");
} catch (Exception e) {
throw new EarlException("Command hath faltered: "
+ "obscure employment of "
throw new EarlException("Incomprehensible employment of "
+ type.name().toLowerCase() + ". Example use:");
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/earl/util/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ public String appendNewline(String line) {
return line + NEWLINE;
}

/** Displays the initial greeting. */
public void showGreeting() {
makeResponse(GREETING_MESSAGE);
// response is built in case of any preceding error messages
buildResponse(GREETING_MESSAGE);
completeResponse();
}

public void showGoodbye() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/earl/util/parsers/InputParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static Handler parse(String input) throws ParserException {
// all valid input is expected to be of the format
// <command> [<arg1>, <arg2>, ...]
String[] data = input.split("\\s", 2);
String command = data[0];
String command = data[0].toUpperCase();
String args = (data.length > 1) ? data[1] : "";
HandlerType handlerType = HandlerType.valueOf(command);
return handlerType.createHandler(args);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/earl/logic/DeleteHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void setUp() {

@Test
void handle_normalInput_success() throws Exception {
Handler handler = HandlerType.delete.createHandler("1");
Handler handler = HandlerType.DELETE.createHandler("1");
handler.handle(new TaskListStub(), new UiStub());
String newLine = System.lineSeparator();
assertEquals("Item(s) heretofore have been expunged." + newLine
Expand All @@ -37,7 +37,7 @@ void handle_normalInput_success() throws Exception {
@Test
void handle_nonIntegerInput_exceptionThrown() {
try {
Handler handler = HandlerType.delete.createHandler("a");
Handler handler = HandlerType.DELETE.createHandler("a");
handler.handle(new TaskListStub(), new UiStub());
fail();
} catch (Exception e) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/earl/logic/MarkHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void setUp() {

@Test
void handle_normalCommand_success() throws Exception {
Handler handler = HandlerType.mark.createHandler("1");
Handler handler = HandlerType.MARK.createHandler("1");
handler.handle(new TaskListStub(), new UiStub());
String newLine = System.lineSeparator();
assertEquals("Item(s) duly accomplished." + newLine
Expand All @@ -38,7 +38,7 @@ void handle_normalCommand_success() throws Exception {
@Test
void handle_nonIntegerInput_exceptionThrown() {
try {
Handler handler = HandlerType.mark.createHandler("a");
Handler handler = HandlerType.MARK.createHandler("a");
handler.handle(new TaskListStub(), new UiStub());
fail();
} catch (Exception e) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/earl/logic/TodoHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ void setUp() {

@Test
void handle_normalCommand_success() throws Exception {
Handler handler = HandlerType.todo.createHandler("test");
Handler handler = HandlerType.TODO.createHandler("test");
handler.handle(new TaskListStub(), new UiStub());
String expected = "A new todo [T][ ] test"
String expected = "A new TODO [T][ ] test"
+ NEWLINE
+ "hath been appended to the roster of responsibilities."
+ NEWLINE
Expand All @@ -44,7 +44,7 @@ void handle_normalCommand_success() throws Exception {
@Test
void handle_emptyDescription_exceptionThrown() {
try {
Handler handler = HandlerType.todo.createHandler("");
Handler handler = HandlerType.TODO.createHandler("");
handler.handle(new TaskListStub(), new UiStub());
fail();
} catch (EarlException e) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/earl/util/parsers/InputParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ void parse_normalInput_handlerReturnedSuccess() throws Exception {
@Test
void parse_invalidInput_exceptionThrown() {
try {
InputParser.parse("TODO ip");
InputParser.parse("no ip");
fail();
} catch (ParserException e) {
assertEquals("TODO ip", e.getMessage());
assertEquals("no ip", e.getMessage());
}
}
}
12 changes: 6 additions & 6 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
Pray, how may I be of service to you on this auspicious day?
____________________________________________________________
____________________________________________________________
A new todo [T][ ] wash dishes, by virtue of your decree,
A new TODO [T][ ] wash dishes
hath been appended to the roster of responsibilities.
The ledger of tasks bears witness to 1 endeavour(s).
____________________________________________________________
____________________________________________________________
Command hath faltered: obscure employment of deadline. Example use:
Incomprehensible employment of deadline. Example use:
deadline <task name> /by <date time>
____________________________________________________________
____________________________________________________________
Command hath faltered: obscure employment of event. Example use:
Incomprehensible employment of event. Example use:
deadline <task name> /from <date time> /to <date time>
____________________________________________________________
____________________________________________________________
Expand All @@ -33,17 +33,17 @@
An error proclaims the absence of valid indices in range.
____________________________________________________________
____________________________________________________________
A new todo [T][ ] a, by virtue of your decree,
A new TODO [T][ ] a
hath been appended to the roster of responsibilities.
The ledger of tasks bears witness to 2 endeavour(s).
____________________________________________________________
____________________________________________________________
A new todo [T][ ] b, by virtue of your decree,
A new TODO [T][ ] b
hath been appended to the roster of responsibilities.
The ledger of tasks bears witness to 3 endeavour(s).
____________________________________________________________
____________________________________________________________
A new todo [T][ ] c, by virtue of your decree,
A new TODO [T][ ] c
hath been appended to the roster of responsibilities.
The ledger of tasks bears witness to 4 endeavour(s).
____________________________________________________________
Expand Down

0 comments on commit 5aea5a5

Please sign in to comment.