forked from nus-cs2103-AY2324S2/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create JUnit Tests for Parser and TaskList classes, tested with Gradle
- Loading branch information
Showing
9 changed files
with
225 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,5 @@ shadowJar { | |
|
||
run{ | ||
standardInput = System.in | ||
enableAssertions = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package pingmebot; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import pingmebot.task.Deadline; | ||
import pingmebot.task.Events; | ||
import pingmebot.task.ToDos; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ParserTest { | ||
@Test | ||
public void todoParserTest() throws myBotException { | ||
String command = "todo project"; | ||
Parser parser = new Parser(command); | ||
assertEquals(new ToDos("project"),parser.todoParser()); | ||
} | ||
|
||
@Test | ||
public void deadlineParserTest() throws myBotException { | ||
String command = "deadline project /by 05/05/2000 1800"; | ||
Parser parser = new Parser(command); | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyyy HHmm"); | ||
String time = "05/05/2000 1800"; | ||
assertEquals(new Deadline("project", LocalDateTime.parse(time, formatter)),parser.deadlineParser()); | ||
} | ||
|
||
@Test | ||
public void eventParserTest() throws myBotException { | ||
String command = "event project /from 9am /to 8pm"; | ||
Parser parser = new Parser(command); | ||
assertEquals(new Events("project", " 9am"," 8pm"),parser.eventsParser()); | ||
} | ||
|
||
@Test | ||
public void markParserTest() throws myBotException { | ||
String command = "mark 2"; | ||
int arbituaryNumOfTask = 3; | ||
Parser parser = new Parser(command); | ||
assertEquals(1, parser.markParser(arbituaryNumOfTask)); | ||
} | ||
|
||
@Test | ||
public void unmarkParserTest() throws myBotException { | ||
String command = "unmark 2"; | ||
int arbituaryNumOfTask = 3; | ||
Parser parser = new Parser(command); | ||
assertEquals(1, parser.markParser(arbituaryNumOfTask)); | ||
} | ||
|
||
@Test | ||
public void deleteParserTest() throws myBotException { | ||
String command = "delete 2"; | ||
int arbituaryNumOfTask = 3; | ||
Parser parser = new Parser(command); | ||
assertEquals(1, parser.markParser(arbituaryNumOfTask)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package pingmebot; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import pingmebot.task.Task; | ||
import pingmebot.task.ToDos; | ||
|
||
import java.io.*; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class TaskListTest { | ||
@Test | ||
public void getTaskSizeTest() { | ||
ArrayList<Task> tasks = new ArrayList<>(); | ||
TaskList tl = new TaskList(tasks); | ||
tasks.add(new ToDos("project 1")); | ||
tasks.add(new ToDos("project 2")); | ||
tasks.add(new ToDos("project 3")); | ||
assertEquals(3, tl.getTaskSize()); | ||
} | ||
|
||
@Test | ||
public void updateTaskToStorageTest() { | ||
try { | ||
ArrayList<Task> tasks = new ArrayList<>(); | ||
tasks.add(new ToDos("project 1")); | ||
tasks.add(new ToDos("project 2")); | ||
TaskList tl = new TaskList(tasks); | ||
String filePath = "./data/dukeData.txt"; | ||
// File will always exist since it will be created in the file storage constructor if not found | ||
tl.updateTaskToStorage(new fileStorage(filePath)); | ||
|
||
String line; | ||
String totalLine = ""; | ||
try (BufferedReader reader = new BufferedReader(new FileReader(Paths.get(filePath).toFile()))) { | ||
while ((line = reader.readLine()) != null) { | ||
totalLine += line + "\n"; | ||
} | ||
} catch (IOException e) { | ||
fail("Test Failed."); | ||
} | ||
|
||
assertEquals("todo | 0 | project 1" + "\n" + "todo | 0 | project 2" + "\n",totalLine); | ||
} catch (myBotException e) { | ||
fail("Test Failed."); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void addTaskTest() { | ||
ArrayList<Task> tasks = new ArrayList<>(); | ||
TaskList tl = new TaskList(tasks); | ||
tl.addTask(new ToDos("project")); | ||
assertEquals(1,tl.tasks.size()); | ||
} | ||
|
||
@Test | ||
public void removeTaskTest() { | ||
ArrayList<Task> tasks = new ArrayList<>(); | ||
tasks.add(new ToDos("project")); | ||
TaskList tl = new TaskList(tasks); | ||
// Task number is 0-based | ||
tl.removeTask(0); | ||
assertEquals(0, tl.tasks.size()); | ||
} | ||
|
||
@Test | ||
public void taskToStringTest() { | ||
ArrayList<Task> tasks = new ArrayList<>(); | ||
tasks.add(new ToDos("project")); | ||
TaskList tl = new TaskList(tasks); | ||
assertEquals("[T][ ] project", tl.taskToString(0)); | ||
} | ||
|
||
@Test | ||
public void taskStatusIconTest() { | ||
ArrayList<Task> tasks = new ArrayList<>(); | ||
tasks.add(new ToDos("project")); | ||
TaskList tl = new TaskList(tasks); | ||
assertEquals(" ", tl.taskStatusIcon(0)); | ||
} | ||
|
||
@Test | ||
public void taskMarkAsDoneTest() { | ||
ArrayList<Task> tasks = new ArrayList<>(); | ||
tasks.add(new ToDos("project")); | ||
TaskList tl = new TaskList(tasks); | ||
tl.taskMarkAsDone(0); | ||
assertEquals("[T][X] project", tl.tasks.get(0).toString()); | ||
} | ||
|
||
@Test | ||
public void taskUncheckTaskTest() { | ||
ArrayList<Task> tasks = new ArrayList<>(); | ||
tasks.add(new ToDos("project")); | ||
TaskList tl = new TaskList(tasks); | ||
tl.taskMarkAsDone(0); | ||
tl.taskUncheckTask(0); | ||
assertEquals("[T][ ] project", tl.tasks.get(0).toString()); | ||
} | ||
|
||
@Test | ||
public void listTaskTest() { | ||
ArrayList<Task> tasks = new ArrayList<>(); | ||
tasks.add(new ToDos("project")); | ||
TaskList tl = new TaskList(tasks); | ||
|
||
PrintStream originalOut = System.out; | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
PrintStream newOut = new PrintStream(outputStream); | ||
System.setOut(newOut); | ||
tl.listTask(); | ||
System.setOut(originalOut); | ||
String capturedOutput = outputStream.toString(); | ||
assertEquals("1.[T][ ] project" + "\n", capturedOutput); | ||
} | ||
|
||
|
||
|
||
} |