forked from nus-cs2103-AY2324S1/ip
-
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.
Add unit test for validateArguments method
- Loading branch information
1 parent
3a51309
commit 6154c7b
Showing
1 changed file
with
62 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,62 @@ | ||
package corgi.parsers; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class CommandValidatorTest { | ||
|
||
@Test | ||
public void validateArguments_invalidNumberOfArguments_throwsInvalidCommandFormatException() { | ||
CommandValidator validator = new CommandValidator(); | ||
|
||
String command1 = "command /arg1 text1 /arg1 text2 /arg2 text3 /arg3 text4"; | ||
String command2 = "command /arg1 text1 /arg2 text2 /arg2 text3 /arg3 text4"; | ||
String command3 = "command /arg1 text1 /arg3 text2 /arg2 text3 /arg3 text4"; | ||
|
||
Set<String> arguments = new HashSet<>(); | ||
arguments.add("/arg1"); | ||
arguments.add("/arg2"); | ||
arguments.add("/arg3"); | ||
|
||
InvalidCommandFormatException exception1 = assertThrows(InvalidCommandFormatException.class, | ||
() -> validator.validateArguments(command1, arguments)); | ||
InvalidCommandFormatException exception2 = assertThrows(InvalidCommandFormatException.class, | ||
() -> validator.validateArguments(command2, arguments)); | ||
InvalidCommandFormatException exception3 = assertThrows(InvalidCommandFormatException.class, | ||
() -> validator.validateArguments(command3, arguments)); | ||
|
||
assertEquals("Invalid number of argument \"/arg1\" !", exception1.getMessage()); | ||
assertEquals("Invalid number of argument \"/arg2\" !", exception2.getMessage()); | ||
assertEquals("Invalid number of argument \"/arg3\" !", exception3.getMessage()); | ||
} | ||
|
||
@Test | ||
public void validateArguments_missingArguments_throwsInvalidCommandFormatException() { | ||
CommandValidator validator = new CommandValidator(); | ||
|
||
String command1 = "command /arg2 text1 /arg3 text2"; | ||
String command2 = "command /arg1 text1 /arg3 text2"; | ||
String command3 = "command /arg1 text1 /arg2 text2"; | ||
|
||
Set<String> arguments = new HashSet<>(); | ||
arguments.add("/arg1"); | ||
arguments.add("/arg2"); | ||
arguments.add("/arg3"); | ||
|
||
InvalidCommandFormatException exception1 = assertThrows(InvalidCommandFormatException.class, | ||
() -> validator.validateArguments(command1, arguments)); | ||
InvalidCommandFormatException exception2 = assertThrows(InvalidCommandFormatException.class, | ||
() -> validator.validateArguments(command2, arguments)); | ||
InvalidCommandFormatException exception3 = assertThrows(InvalidCommandFormatException.class, | ||
() -> validator.validateArguments(command3, arguments)); | ||
|
||
assertEquals("Missing argument \"/arg1\" !", exception1.getMessage()); | ||
assertEquals("Missing argument \"/arg2\" !", exception2.getMessage()); | ||
assertEquals("Missing argument \"/arg3\" !", exception3.getMessage()); | ||
} | ||
} |