Skip to content

Commit 86129ad

Browse files
committed
Implemented JUnit tests ParserTest and TodoTest
1 parent 6e4ada3 commit 86129ad

File tree

7 files changed

+80
-6
lines changed

7 files changed

+80
-6
lines changed

.classpath

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="bin/main" path="src/main/java">
4+
<attributes>
5+
<attribute name="gradle_scope" value="main"/>
6+
<attribute name="gradle_used_by_scope" value="main,test"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="bin/test" path="src/test/java">
10+
<attributes>
11+
<attribute name="gradle_scope" value="test"/>
12+
<attribute name="gradle_used_by_scope" value="test"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
16+
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
17+
<classpathentry kind="output" path="bin/default"/>
18+
</classpath>

.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>duke</name>
4+
<comment>Project Duke created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
22+
</natures>
23+
</projectDescription>

build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ repositories {
1010
mavenCentral()
1111
}
1212

13+
dependencies {
14+
testImplementation 'org.junit.jupiter:junit-jupiter:5.5.0'
15+
}
16+
17+
test {
18+
useJUnitPlatform()
19+
}
20+
1321
application {
1422
// Change this to your main class.
15-
mainClassName = "seedu.duke.Duke"
23+
mainClassName = "Duke"
1624
}
1725

1826
run {

src/main/java/Duke.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public Duke(String fileName) {
2323
Ui.printLines("File creation failed.");
2424
}
2525
}
26+
2627
public static void main(String[] args) {
27-
new Duke("../data/tasks.txt").run();
28+
new Duke("src/main/data/tasks.txt").run();
2829
}
2930

3031
private void run() {

src/main/java/Storage.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ public void writeToFile(String fileName, String data) {
5757

5858
public void doTask(int idx) {
5959
File originalFile = new File(this.fileName);
60-
File tempFile = new File("../data/temp.txt");
60+
File tempFile = new File("src/main/data/temp.txt");
6161

6262
try {
63-
FileWriter fw = new FileWriter("../data/temp.txt", false);
63+
FileWriter fw = new FileWriter("src/main/data/temp.txt", false);
6464
Scanner sc = new Scanner(originalFile);
6565
int i = 1;
6666

@@ -89,10 +89,10 @@ public void doTask(int idx) {
8989

9090
public void deleteTask(int idx) {
9191
File originalFile = new File(this.fileName);
92-
File tempFile = new File("../data/temp.txt");
92+
File tempFile = new File("src/main/data/temp.txt");
9393

9494
try {
95-
FileWriter fw = new FileWriter("../data/temp.txt", false);
95+
FileWriter fw = new FileWriter("src/main/data/temp.txt", false);
9696
Scanner sc = new Scanner(originalFile);
9797
int i = 1;
9898

src/test/java/ParserTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import org.junit.jupiter.api.Test;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
public class ParserTest {
6+
@Test
7+
public void testCommandParsing() {
8+
assertEquals(true, new Parser().parseCommand("delete", "delete"));
9+
}
10+
11+
@Test
12+
public void testTimeParsing() {
13+
assertEquals("Jan 1 2019", Parser.parseTime("2019-01-01"));
14+
}
15+
}

src/test/java/TodoTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import org.junit.jupiter.api.Test;
2+
import static org.junit.jupiter.api.Assertions.assertEquals;
3+
4+
public class TodoTest {
5+
@Test
6+
public void testStringConversion() {
7+
assertEquals("[T][O] Todo Testing", new Todo("Todo Testing", true).toString());
8+
}
9+
}

0 commit comments

Comments
 (0)