Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added proper testing of invalid command lines

  • Loading branch information...
commit f8e8eac4eec48f748c051498e7e04c1dd3af9716 1 parent e307c58
@tenorviol authored
View
BIN  lib/gitsearch-0.1.jar
Binary file not shown
View
8 src/CommandLine.java
@@ -15,15 +15,15 @@ public CommandLine(String[] args) throws IllegalArgumentException {
if ("index".equals(command)) {
parseIndexArgs();
- } else if ("search".equals(command)) {
- parseSearchArgs();
+ } else if ("query".equals(command)) {
+ parseQueryArgs();
} else {
throw new IllegalArgumentException("Unknown command, '" + command + "'");
}
}
private void parseCommand(List<String> args) throws IllegalArgumentException {
- if (!"--index".equals(args.get(0)) || args.size() < 2) {
+ if (args.size() < 2 || !"--index".equals(args.get(0))) {
throw new IllegalArgumentException("--index <path> required");
}
indexPath = args.get(1);
@@ -41,7 +41,7 @@ private void parseIndexArgs() throws IllegalArgumentException {
}
}
- private void parseSearchArgs() throws IllegalArgumentException {
+ private void parseQueryArgs() throws IllegalArgumentException {
if (commandArgs.size() == 0) {
throw new IllegalArgumentException("No search query given");
}
View
27 test/CommandLineTest.java
@@ -5,14 +5,23 @@
public class CommandLineTest {
- @Test
- public void testFoo() {
- String[] args = {"--index", "./foo/index", "index"};
- try {
- CommandLine cl = new CommandLine(args);
- } catch (Exception e) {
- System.out.println(e);
- }
- Assert.assertEquals(1,1);
+ @DataProvider(name = "invalid-command-lines")
+ public Object[][] illegalCommandLineProvider() {
+ return new Object[][] {
+ { null },
+ { "--index" },
+ { "--index ./.index" },
+ { "--index ./.index index" },
+ { "--index ./.index query" },
+ { "--index ./.index non-command" },
+ { "query --index ./.index foo" },
+ };
+ }
+
+ @Test(dataProvider = "invalid-command-lines",
+ expectedExceptions = IllegalArgumentException.class)
+ public void testInvalidCommandLineThrowsIllegalArgumentException(String commandLine) {
+ String[] args = (null == commandLine) ? new String[] {} : commandLine.split(" ");
+ CommandLine cl = new CommandLine(args);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.