Added testParseSimilar testcase to LiteralCommandNode
This commit is contained in:
parent
d678a5cb21
commit
085f5b3d98
2 changed files with 10 additions and 7 deletions
|
@ -19,15 +19,13 @@ public class LiteralCommandNode extends CommandNode {
|
|||
|
||||
@Override
|
||||
public String parse(String command, CommandContextBuilder contextBuilder) throws IllegalArgumentSyntaxException, ArgumentValidationException {
|
||||
if (!command.startsWith(literal)) {
|
||||
String expected = literal + (command.length() > literal.length() ? " " : "");
|
||||
|
||||
if (!command.startsWith(expected)) {
|
||||
throw new IllegalArgumentSyntaxException();
|
||||
}
|
||||
|
||||
int start = literal.length();
|
||||
if (command.length() > start) {
|
||||
return command.substring(start + 1);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
int start = expected.length();
|
||||
return command.substring(start);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,11 @@ public class LiteralCommandNodeTest {
|
|||
assertThat(node.parse("foo", contextBuilder), is(""));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentSyntaxException.class)
|
||||
public void testParseSimilar() throws Exception {
|
||||
node.parse("foobar", contextBuilder);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentSyntaxException.class)
|
||||
public void testParseInvalid() throws Exception {
|
||||
node.parse("bar", contextBuilder);
|
||||
|
|
Loading…
Reference in a new issue