Skip to content

Commit 3ce7a6a

Browse files
committed
Add more JUnit test cases
1 parent 0fd1009 commit 3ce7a6a

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

src/test/java/gloqi/command/CommandParserTest.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
44
import static org.junit.jupiter.api.Assertions.assertEquals;
55
import static org.junit.jupiter.api.Assertions.assertThrows;
6-
import static org.junit.jupiter.api.Assertions.fail;
76

87
import java.time.LocalDate;
98

@@ -13,12 +12,39 @@
1312

1413
public class CommandParserTest {
1514
@Test
16-
public void commandParser_invalidCommand_success() {
17-
try {
18-
assertEquals(Command.INVALID, new CommandParser("any any any").getCmd());
19-
} catch (GloqiException e) {
20-
fail("Unexpected exception: " + e.getMessage());
21-
}
15+
public void commandParser_invalidCommand_success() throws GloqiException {
16+
assertEquals(Command.INVALID, new CommandParser("any any any").getCmd());
17+
}
18+
19+
@Test
20+
public void commandParser_listCommand_success() throws GloqiException {
21+
assertEquals(Command.LIST, new CommandParser("list").getCmd());
22+
}
23+
24+
@Test
25+
public void commandParser_unmarkCommand_success() throws GloqiException {
26+
CommandParser parser = new CommandParser("unmark 1");
27+
assertEquals(Command.UNMARK, parser.getCmd());
28+
assertArrayEquals(new int[]{0}, parser.getIntArg());
29+
}
30+
31+
@Test
32+
public void commandParser_byeCommand_success() throws GloqiException {
33+
assertEquals(Command.BYE, new CommandParser("bye").getCmd());
34+
}
35+
36+
@Test
37+
public void commandParser_deleteCommand_success() throws GloqiException {
38+
CommandParser parser = new CommandParser("delete 1,2");
39+
assertEquals(Command.DELETE, parser.getCmd());
40+
assertArrayEquals(new int[]{0, 1}, parser.getIntArg());
41+
}
42+
43+
@Test
44+
public void commandParser_findCommand_success() throws GloqiException {
45+
CommandParser parser = new CommandParser("find star");
46+
assertEquals(Command.FIND, parser.getCmd());
47+
assertArrayEquals(new String[]{"star"}, parser.getStringArg());
2248
}
2349

2450
@Test
@@ -32,7 +58,7 @@ public void getShowArg_noArg_exceptionThrow() {
3258
"Show"));
3359
assertEquals("""
3460
Missing argument!!! Please follow following format:
35-
show <date:yyyy-MM-dd>""", exception.getMessage());
61+
show <date>""", exception.getMessage());
3662
}
3763

3864
@Test
@@ -41,7 +67,7 @@ public void getShowArg_invalidDateFormat_exceptionThrow() {
4167
"Show 2019/5/5"));
4268
assertEquals("""
4369
Date for the show is Invalid!!!Please follow my show format:
44-
show <date:yyyy-MM-dd>""", exception.getMessage());
70+
show <yyyy-MM-dd>""", exception.getMessage());
4571
}
4672

4773
@Test

text-ui-test/runtest.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ then
2020
fi
2121

2222
# run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
23-
java -classpath ../bin Duke < input.txt > ACTUAL.TXT
23+
java -classpath ../bin Gloqi < input.txt > ACTUAL.TXT
2424

2525
# convert to UNIX format
2626
cp EXPECTED.TXT EXPECTED-UNIX.TXT

0 commit comments

Comments
 (0)