forked from nus-cs2113-AY2021S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2113-AY2021S1#62 from tammykoh/master
Created ParserTest
- Loading branch information
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |