Option { @Override public String toString() { if (Type.LIST.equals(this.type)) { return ("INT_LIST" + ((value.length() != 0) ? (":" + value) : (""))); } else { return (name + ((value.length() != 0) ? (":" + value) : (""))); } } Option(Type type, String name, int numvalues, String description); static Option createFlag(String name, String description); static Option createList(String description); static Option createOption(String name, String description); static Option createOption(String name, int numvalues, String description); static Option findListOption(Option[] options); static Option findOption(String name, Option[] options); static Option[] parseCLArgs(String[] args, Option[] templates); String getDescription(); int getLen(); String getName(); Type getType(); String getValue(); String[] getValues(); void setValue(String value); @Override String toString(); static final int UNKNOWN; static final int UNLIMITED_LENGTH; }
@Test public void testOptionTypes() { TreeMap<String, Option.Type> values = new TreeMap<String, Option.Type>(); for (final Option.Type type : Option.Type.values()) { values.put(type.toString(), type); } assertTrue(values.containsKey("FLAG")); assertTrue(values.containsKey("OPTION")); assertTrue(values.containsKey("LIST")); assertTrue(values.size() == 3); assertTrue(Option.Type.valueOf("FLAG").equals(values.get("FLAG"))); assertTrue(Option.Type.valueOf("OPTION").equals(values.get("OPTION"))); assertTrue(Option.Type.valueOf("LIST").equals(values.get("LIST"))); }
@Test public void testToString() { Option list = Option.createList("list"); assertEquals("INT_LIST", list.toString()); assertEquals("", list.getValue()); assertArrayEquals(new String[] {}, list.getValues()); list.setValue("a b c"); assertEquals("INT_LIST:a b c", list.toString()); assertArrayEquals(new String[] { "a", "b", "c" }, list.getValues()); Option flag = Option.createFlag("flag", "flag"); assertEquals("flag", flag.toString()); assertEquals("", flag.getValue()); assertArrayEquals(new String[] {}, flag.getValues()); flag.setValue("a"); assertEquals("flag:a", flag.toString()); assertArrayEquals(new String[] { "a" }, flag.getValues()); Option option = Option.createOption("option", "option"); assertEquals("option", option.toString()); assertEquals("", option.getValue()); assertArrayEquals(new String[] {}, option.getValues()); option.setValue("a"); assertEquals("option:a", option.toString()); assertArrayEquals(new String[] { "a" }, option.getValues()); }