@Test public void defaultCommands() { OptionsAndArgs o = opts(); assertEquals(o.getCommand(), "list"); o = opts("12"); assertEquals(o.getCommand(), "toggle"); }
@Test public void help() { OptionsAndArgs o = opts("--help", "--verbose"); assertEquals(o.getCommand(), "help"); assertFalse(o.isQuiet()); assertTrue(o.isVerbose()); }
@Test public void toggleDefaultWithPattern() { OptionsAndArgs o = opts("bla"); assertNull(o.getPid()); Pattern pat = o.getProcessPattern(); assertEquals(pat.pattern(), "bla"); assertEquals(o.getCommand(), "toggle"); }
@Test public void simple() { OptionsAndArgs o = opts("--host", "localhost", "start", "12", "--password=bla", "-u", "roland", "--quiet"); assertEquals(o.getCommand(), "start"); assertTrue(o.isQuiet()); assertFalse(o.isVerbose()); assertEquals(o.getPid(), "12"); assertNull(o.getProcessPattern()); String args = o.toAgentArg(); assertTrue(args.matches(".*host=localhost.*")); assertTrue(args.matches(".*user=roland.*")); assertTrue(args.matches(".*password=bla.*")); Map<String, String> opts = new HashMap<String, String>(); for (String s : args.split(",")) { String[] p = s.split("="); assertEquals(p.length, 2); opts.put(p[0], p[1]); } assertEquals(opts.size(), 3); assertEquals(opts.get("host"), "localhost"); assertEquals(opts.get("user"), "roland"); assertEquals(opts.get("password"), "bla"); }