@Override protected void processOptions(LinkedList<String> args) { CommandFormat cf = new CommandFormat(1, 1, "e", "d", "f", "s", "z", "w", "r"); cf.parse(args); String[] opts = cf.getOpts().toArray(new String[0]); switch (opts.length) { case 0: throw new IllegalArgumentException("No test flag given"); case 1: flag = opts[0].charAt(0); break; default: throw new IllegalArgumentException("Only one test flag is allowed"); } }
@Override protected void processOptions(LinkedList<String> args) { CommandFormat cf = new CommandFormat(1, 1, "e", "d", "f", "s", "z"); cf.parse(args); String[] opts = cf.getOpts().toArray(new String[0]); switch (opts.length) { case 0: throw new IllegalArgumentException("No test flag given"); case 1: flag = opts[0].charAt(0); break; default: throw new IllegalArgumentException("Only one test flag is allowed"); } }
@Override protected void processOptions(LinkedList<String> args) { CommandFormat cf = new CommandFormat(1, 1, "e", "d", "f", "s", "z"); cf.parse(args); String[] opts = cf.getOpts().toArray(new String[0]); switch (opts.length) { case 0: throw new IllegalArgumentException("No test flag given"); case 1: flag = opts[0].charAt(0); break; default: throw new IllegalArgumentException("Only one test flag is allowed"); } }
@Override protected void processOptions(LinkedList<String> args) { CommandFormat cf = new CommandFormat(1, 1, "e", "d", "f", "s", "z"); cf.parse(args); String[] opts = cf.getOpts().toArray(new String[0]); switch (opts.length) { case 0: throw new IllegalArgumentException("No test flag given"); case 1: flag = opts[0].charAt(0); break; default: throw new IllegalArgumentException("Only one test flag is allowed"); } }
@Override protected void processOptions(LinkedList<String> args) { CommandFormat cf = new CommandFormat(1, 1, "e", "d", "f", "s", "z", "w", "r"); cf.parse(args); String[] opts = cf.getOpts().toArray(new String[0]); switch (opts.length) { case 0: throw new IllegalArgumentException("No test flag given"); case 1: flag = opts[0].charAt(0); break; default: throw new IllegalArgumentException("Only one test flag is allowed"); } }
private static <T> CommandFormat checkArgLimits( Class<? extends IllegalArgumentException> expectedErr, int min, int max, String ... opts) { CommandFormat cf = new CommandFormat(min, max, opts); List<String> parsedArgs = new ArrayList<String>(args); Class<?> cfError = null; try { cf.parse(parsedArgs); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); cfError = e.getClass(); } assertEquals(expectedErr, cfError); if (expectedErr == null) { assertEquals(expectedArgs, parsedArgs); assertEquals(expectedOpts, cf.getOpts()); } return cf; }
private static <T> CommandFormat checkArgLimits( Class<? extends IllegalArgumentException> expectedErr, int min, int max, String ... opts) { CommandFormat cf = new CommandFormat(min, max, opts); List<String> parsedArgs = new ArrayList<String>(args); Class<?> cfError = null; try { cf.parse(parsedArgs); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); cfError = e.getClass(); } assertEquals(expectedErr, cfError); if (expectedErr == null) { assertEquals(expectedArgs, parsedArgs); assertEquals(expectedOpts, cf.getOpts()); } return cf; }
@Test public void testOldArgsWithIndex() { String[] arrayArgs = new String[]{"ignore", "-a", "b", "-c"}; { CommandFormat cf = new CommandFormat(0, 9, "a", "c"); List<String> parsedArgs = cf.parse(arrayArgs, 0); assertEquals(setOf(), cf.getOpts()); assertEquals(listOf("ignore", "-a", "b", "-c"), parsedArgs); } { CommandFormat cf = new CommandFormat(0, 9, "a", "c"); List<String> parsedArgs = cf.parse(arrayArgs, 1); assertEquals(setOf("a"), cf.getOpts()); assertEquals(listOf("b", "-c"), parsedArgs); } { CommandFormat cf = new CommandFormat(0, 9, "a", "c"); List<String> parsedArgs = cf.parse(arrayArgs, 2); assertEquals(setOf(), cf.getOpts()); assertEquals(listOf("b", "-c"), parsedArgs); } }
@Test public void testOldArgsWithIndex() { String[] arrayArgs = new String[]{"ignore", "-a", "b", "-c"}; { CommandFormat cf = new CommandFormat(0, 9, "a", "c"); List<String> parsedArgs = cf.parse(arrayArgs, 0); assertEquals(setOf(), cf.getOpts()); assertEquals(listOf("ignore", "-a", "b", "-c"), parsedArgs); } { CommandFormat cf = new CommandFormat(0, 9, "a", "c"); List<String> parsedArgs = cf.parse(arrayArgs, 1); assertEquals(setOf("a"), cf.getOpts()); assertEquals(listOf("b", "-c"), parsedArgs); } { CommandFormat cf = new CommandFormat(0, 9, "a", "c"); List<String> parsedArgs = cf.parse(arrayArgs, 2); assertEquals(setOf(), cf.getOpts()); assertEquals(listOf("b", "-c"), parsedArgs); } }