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
|
@Override
|
||||||
public String parse(String command, CommandContextBuilder contextBuilder) throws IllegalArgumentSyntaxException, ArgumentValidationException {
|
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();
|
throw new IllegalArgumentSyntaxException();
|
||||||
}
|
}
|
||||||
|
|
||||||
int start = literal.length();
|
int start = expected.length();
|
||||||
if (command.length() > start) {
|
return command.substring(start);
|
||||||
return command.substring(start + 1);
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,11 @@ public class LiteralCommandNodeTest {
|
||||||
assertThat(node.parse("foo", contextBuilder), is(""));
|
assertThat(node.parse("foo", contextBuilder), is(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentSyntaxException.class)
|
||||||
|
public void testParseSimilar() throws Exception {
|
||||||
|
node.parse("foobar", contextBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentSyntaxException.class)
|
@Test(expected = IllegalArgumentSyntaxException.class)
|
||||||
public void testParseInvalid() throws Exception {
|
public void testParseInvalid() throws Exception {
|
||||||
node.parse("bar", contextBuilder);
|
node.parse("bar", contextBuilder);
|
||||||
|
|
Loading…
Reference in a new issue