Manager { @VisibleForTesting static Args parseArgs(String[] argsParam) throws Exception { if (argsParam.length == 0) throw new IllegalArgumentException(Args.INVALID_ARGUMENTS); if (!commandExists(argsParam[0])) throw new IllegalArgumentException(INVALID_COMMAND); return new ManagerArgs(Arrays.copyOfRange(argsParam, 1, argsParam.length)); } Manager(Args args, String commandName); static void main(String[] args); void run(); static final String INVALID_COMMAND; static final String INVALID_ZOOKEEPER; }
@Test public void testInvalidCommand() throws Exception { String[] args = {"command", "zookeeper", "table"}; try { Manager.parseArgs(args); Assert.fail(); } catch (RuntimeException e) { if (!e.getMessage().contains(Manager.INVALID_COMMAND)) throw e; } }
@Test public void testInvalidOption() throws Exception { String[] args = {"balance", "zookeeper", "table", "--nonono"}; try { Manager.parseArgs(args); Assert.fail(); } catch (OptionException ignored) { } }
@Test public void testNoArg() throws Exception { String[] args = {}; try { Manager.parseArgs(args); Assert.fail(); } catch (IllegalArgumentException ignored) { } }