|
| 1 | +package gloqi.ui; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | + |
| 5 | +import java.nio.file.Path; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | +import org.junit.jupiter.api.io.TempDir; |
| 9 | + |
| 10 | +public class GloqiTest { |
| 11 | + @Test |
| 12 | + public void initialize_invalidStorage_success(@TempDir Path tmp) throws GloqiException { |
| 13 | + Gloqi gloqi = new Gloqi(); |
| 14 | + Path file = tmp.resolve("gloqi.txt"); |
| 15 | + String response = gloqi.initialize(file.toString()); |
| 16 | + assertEquals("No data file found!\nStart up with a fresh file!", response); |
| 17 | + } |
| 18 | + @Test |
| 19 | + public void initialize_validStorage_success(@TempDir Path tmp) { |
| 20 | + Gloqi gloqi = new Gloqi(); |
| 21 | + Path file = tmp.resolve("gloqi.txt"); |
| 22 | + gloqi.initialize(file.toString()); |
| 23 | + gloqi.run("todo Read book"); |
| 24 | + String response = gloqi.initialize(file.toString()); |
| 25 | + assertEquals("Tasks are loaded successfully!", response); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void getGreeting_success() { |
| 30 | + Gloqi gloqi = new Gloqi(); |
| 31 | + String response = gloqi.getGreeting(); |
| 32 | + assertEquals("Hello I am Gloqi\nhow can i help you", response); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void run_validList_success(@TempDir Path tmp) { |
| 37 | + Gloqi gloqi = testFileInistalize(tmp); |
| 38 | + gloqi.run("todo Read book"); |
| 39 | + String response = gloqi.run("List"); |
| 40 | + assertEquals("1. [T][ ] Read book", response); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void run_validMark_success(@TempDir Path tmp) { |
| 45 | + Gloqi gloqi = testFileInistalize(tmp); |
| 46 | + gloqi.run("todo Read book"); |
| 47 | + String response = gloqi.run("mark 1"); |
| 48 | + assertEquals("Nice! I've marked this task as done:\n[T][x] Read book", response); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void run_invalidMark_success(@TempDir Path tmp) { |
| 53 | + Gloqi gloqi = testFileInistalize(tmp); |
| 54 | + String response = gloqi.run("mark 999"); |
| 55 | + assertEquals("Task index 999 is out of range", response); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void run_validUnmark_success(@TempDir Path tmp) { |
| 60 | + Gloqi gloqi = testFileInistalize(tmp); |
| 61 | + gloqi.run("todo Read book"); |
| 62 | + String response = gloqi.run("unmark 1"); |
| 63 | + assertEquals("OK, I've marked this task as not done yet:\n[T][ ] Read book", response); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void run_validDeadline_success(@TempDir Path tmp) { |
| 68 | + Gloqi gloqi = testFileInistalize(tmp); |
| 69 | + String response = gloqi.run("Deadline Submit assignment /by 2024-09-30 2359"); |
| 70 | + String expected = """ |
| 71 | + Got it. I've added this task: |
| 72 | + [D][ ] Submit assignment (by: Sep 30 2024 11 pm) |
| 73 | + Now you have 1 tasks in the bank."""; |
| 74 | + assertEquals(expected, response); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void run_validEvent_success(@TempDir Path tmp) { |
| 79 | + Gloqi gloqi = testFileInistalize(tmp); |
| 80 | + String response = gloqi.run("Event Team meeting /from 2024-10-01 1400 /to 2024-10-01 1500"); |
| 81 | + String expected = """ |
| 82 | + Got it. I've added this task: |
| 83 | + [E][ ] Team meeting (from: Oct 01 2024 2 pm to: Oct 01 2024 3 pm) |
| 84 | + Now you have 1 tasks in the bank."""; |
| 85 | + assertEquals(expected, response); |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + public void run_validDelete_success(@TempDir Path tmp) { |
| 90 | + Gloqi gloqi = testFileInistalize(tmp); |
| 91 | + gloqi.run("todo Read book"); |
| 92 | + String response = gloqi.run("delete 1"); |
| 93 | + String expected = """ |
| 94 | + Tasks have been deleted: |
| 95 | + [T][ ] Read book\n |
| 96 | + Now you have 0 tasks in the bank."""; |
| 97 | + assertEquals(expected, response); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + public void run_validShow_success(@TempDir Path tmp) { |
| 102 | + Gloqi gloqi = testFileInistalize(tmp); |
| 103 | + gloqi.run("Deadline Submit assignment /by 2024-09-30 2359"); |
| 104 | + String response = gloqi.run("show 2024-09-30"); |
| 105 | + String expected = """ |
| 106 | + Tasks found on date: Sep 30 2024 |
| 107 | + 1. [D][ ] Submit assignment (by: Sep 30 2024 11 pm)"""; |
| 108 | + assertEquals(expected, response); |
| 109 | + } |
| 110 | + |
| 111 | + @Test |
| 112 | + public void run_validFind_success(@TempDir Path tmp) { |
| 113 | + Gloqi gloqi = testFileInistalize(tmp); |
| 114 | + gloqi.run("Deadline Submit assignment /by 2024-09-30 2359"); |
| 115 | + String response = gloqi.run("find assignment"); |
| 116 | + String expected = """ |
| 117 | + 1. [D][ ] Submit assignment (by: Sep 30 2024 11 pm)"""; |
| 118 | + assertEquals(expected, response); |
| 119 | + } |
| 120 | + |
| 121 | + @Test |
| 122 | + public void run_validBye_success() { |
| 123 | + Gloqi gloqi = new Gloqi(); |
| 124 | + String response = gloqi.run("bye"); |
| 125 | + String expected = "Bye, see you next time!"; |
| 126 | + assertEquals(expected, response); |
| 127 | + } |
| 128 | + |
| 129 | + @Test |
| 130 | + public void run_invalidCommand_success() { |
| 131 | + Gloqi gloqi = new Gloqi(); |
| 132 | + String response = gloqi.run("bye1231"); |
| 133 | + String expected = """ |
| 134 | + Invalid command, only following commands are supported: |
| 135 | + list, mark, unmark, bye, deadline, event, todo, show, delete, find"""; |
| 136 | + assertEquals(expected, response); |
| 137 | + } |
| 138 | + |
| 139 | + private Gloqi testFileInistalize(@TempDir Path tmp) { |
| 140 | + Gloqi gloqi = new Gloqi(); |
| 141 | + Path file = tmp.resolve("gloqi.txt"); |
| 142 | + gloqi.initialize(file.toString()); |
| 143 | + return gloqi; |
| 144 | + } |
| 145 | +} |
0 commit comments