Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2021S1#62 from tammykoh/master
Browse files Browse the repository at this point in the history
Created ParserTest
  • Loading branch information
yeapcl authored Oct 19, 2020
2 parents bc5036d + e0e2e60 commit 9c62300
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/test/java/seedu/duke/parser/ParserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package seedu.duke.parser;

import org.junit.jupiter.api.Test;
import seedu.duke.command.Command;
import seedu.duke.command.AddCommand;
import seedu.duke.command.ByeCommand;
import seedu.duke.command.CompareCommand;
import seedu.duke.command.ClearCommand;
import seedu.duke.command.DeleteCommand;
import seedu.duke.command.EditCommand;
import seedu.duke.command.ListCommand;
import seedu.duke.command.LogInCommand;
import seedu.duke.exception.DukeException;

//import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ParserTest {

@Test
public void parse_unknownCommand_throwDukeException() {
final String input = "hello, testing";
assertThrows(DukeException.class, () -> Parser.parse(input));
}

@Test
public void parse_addCommand_parsedCorrectly() throws DukeException {
final String input = "add CS2113 Lecture /fri /1600-1800 /LT15";
parseAndAssertCommandType(input, AddCommand.class);
}

@Test
public void parse_byeCommand_parsedCorrectly() throws DukeException {
final String input = "bye";
parseAndAssertCommandType(input, ByeCommand.class);
}

@Test
public void parse_clearCommand_parsedCorrectly() throws DukeException {
final String input = "clear /sun";
parseAndAssertCommandType(input, ClearCommand.class);
}

@Test
public void parse_compareCommand_parsedCorrectly() throws DukeException {
final String input = "compare /Alex /mon";
parseAndAssertCommandType(input, CompareCommand.class);
}

@Test
public void parse_deleteCommand_parsedCorrectly() throws DukeException {
final String input = "delete /tue /2";
parseAndAssertCommandType(input, DeleteCommand.class);
}

@Test
public void parse_editCommand_parsedCorrectly() throws DukeException {
final String input = "edit /mon /2 /1000-1200";
parseAndAssertCommandType(input, EditCommand.class);
}

@Test
public void parse_listCommand_parsedCorrectly() throws DukeException {
final String input = "list /all";
parseAndAssertCommandType(input, ListCommand.class);
}

@Test
public void parse_loginCommand_parsedCorrectly() throws DukeException {
final String input = "login John /1324";
parseAndAssertCommandType(input, LogInCommand.class);
}

/**
* Parses input and asserts the class/type of the returned command object.
*
* @param input to be parsed
* @param expectedCommandClass expected class of returned command
*/
private <T extends Command> void parseAndAssertCommandType(String input, Class<T> expectedCommandClass)
throws DukeException {
final Command result = Parser.parse(input);
assertTrue(result.getClass().isAssignableFrom(expectedCommandClass));
}
}

0 comments on commit 9c62300

Please sign in to comment.