@Test public void testConvert() throws ArgumentParserException { ArgumentParser ap = ArgumentParsers.newFor("argparse4j") .locale(Locale.US).build(); EnumArgumentType<Foo> type = new EnumArgumentType<Foo>(Foo.class); assertEquals(Foo.BRAVO, type.convert(null, null, "BRAVO")); try { type.convert(ap, new MockArgument(), "DELTA"); } catch (ArgumentParserException e) { assertEquals( "argument null: could not convert 'DELTA' (choose from {ALPHA,BRAVO,CHARLIE})", e.getMessage()); } }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { try { return Enum.valueOf(type_, value); } catch (IllegalArgumentException e) { String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), e, parser, arg); } }
EnumArgumentType implements ArgumentType<T> { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { try { return Enum.valueOf(type_, value); } catch (IllegalArgumentException e) { String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), e, parser, arg); } } }
EnumArgumentType implements ArgumentType<T> { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { try { return Enum.valueOf(type_, value); } catch (IllegalArgumentException e) { String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), e, parser, arg); } } EnumArgumentType(Class<T> type); }
EnumArgumentType implements ArgumentType<T> { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { try { return Enum.valueOf(type_, value); } catch (IllegalArgumentException e) { String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), e, parser, arg); } } EnumArgumentType(Class<T> type); @Override T convert(ArgumentParser parser, Argument arg, String value); }
EnumArgumentType implements ArgumentType<T> { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { try { return Enum.valueOf(type_, value); } catch (IllegalArgumentException e) { String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), e, parser, arg); } } EnumArgumentType(Class<T> type); @Override T convert(ArgumentParser parser, Argument arg, String value);  }