Skip to content

Commit

Permalink
Add JUnit tests for Parser.java
Browse files Browse the repository at this point in the history
  • Loading branch information
khinkhinn committed Aug 25, 2020
1 parent b6301b2 commit c8f47e5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Task commandToTask(String s) throws IncompleteInputException {
time = arr[3];
return new Event(name, time);
}
} catch (StringIndexOutOfBoundsException e) {
} catch (ArrayIndexOutOfBoundsException e) {
throw new IncompleteInputException();
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,18 @@ Todo completeTask() {
public String toString() {
return "[todo]" + super.toString();
}

@Override
public boolean equals(Object obj) {
Todo test = (Todo) obj;
if (obj == this) {
return true;
} else if (obj == null || obj.getClass() != this.getClass()) {
return false;
} else if (this.name.equals(test.name) && (this.completed == test.completed)) {
return true;
} else {
return false;
}
}
}
38 changes: 38 additions & 0 deletions src/test/java/ParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public class ParserTest {
Parser p = new Parser();

@Test
public void testGetTaskNumber() {
assertEquals(1, p.getTaskNumber( "done 1"));
assertEquals(17, p.getTaskNumber( "delete 17"));
assertEquals(299, p.getTaskNumber( "done 299"));
}

@Test
public void testCommandToTask_completeInput_success() throws IncompleteInputException {
assertEquals(new Todo("eat"), p.commandToTask("todo eat"));
/*assertEquals(new Deadline("homework", "2020-08-30"),
p.commandToTask("deadline homework /by 2020-08-30"));
assertEquals(new Event("birthday", "2020-12-04"),
p.commandToTask("event birthday /at 2020-12-4"));*/
}

@Test
public void testCommandToTask_incompleteInput_exceptionThrown() throws IncompleteInputException {
try {
assertEquals(new Todo("eat"), p.commandToTask("todo"));
fail(); // the test should not reach this line
} catch (Exception e) {
assertEquals("please finish your sentence.. :(\neither your task name is blank " +
"or youre missing the time!!", e.getMessage());
}
/*assertEquals(new Deadline("homework", "2020-08-30"),
p.commandToTask("deadline homework /by 2020-08-30"));
assertEquals(new Event("birthday", "2020-12-04"),
p.commandToTask("event birthday /at 2020-12-4"));*/
}
}
14 changes: 14 additions & 0 deletions src/test/java/UiTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import org.junit.jupiter.api.Test;

import java.util.Scanner;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class UiTest {
Ui ui = new Ui(new Scanner(System.in));

@Test
public void dummyTest(){
assertEquals(2, 2);
}
}

0 comments on commit c8f47e5

Please sign in to comment.