@Test public void testConvert() throws ArgumentParserException { ArgumentParser ap = ArgumentParsers .newFor("argparse4j").locale(Locale.US).build(); BooleanArgumentType t = new BooleanArgumentType(); assertEquals(Boolean.TRUE, t.convert(null, ma, "true")); assertEquals(Boolean.FALSE, t.convert(null, ma, "false")); try { t.convert(ap, ma, "TRUE"); fail(); } catch (ArgumentParserException e) { assertEquals( "argument null: could not convert 'TRUE' (choose from {true,false})", e.getMessage()); } t = new BooleanArgumentType("yes", "no"); assertEquals(Boolean.TRUE, t.convert(null, ma, "yes")); assertEquals(Boolean.FALSE, t.convert(null, ma, "no")); try { t.convert(ap, ma, "Yes"); fail(); } catch (ArgumentParserException e) { assertEquals( "argument null: could not convert 'Yes' (choose from {yes,no})", e.getMessage()); } }
@Override public Boolean convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (trueValue_.equals(value)) { return Boolean.TRUE; } if (falseValue_.equals(value)) { return Boolean.FALSE; } throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); }
BooleanArgumentType implements ArgumentType<Boolean>,
        MetavarInference { @Override public Boolean convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (trueValue_.equals(value)) { return Boolean.TRUE; } if (falseValue_.equals(value)) { return Boolean.FALSE; } throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); } }
BooleanArgumentType implements ArgumentType<Boolean>,
        MetavarInference { @Override public Boolean convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (trueValue_.equals(value)) { return Boolean.TRUE; } if (falseValue_.equals(value)) { return Boolean.FALSE; } throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); } BooleanArgumentType();  BooleanArgumentType(String trueValue, String falseValue); }
BooleanArgumentType implements ArgumentType<Boolean>,
        MetavarInference { @Override public Boolean convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (trueValue_.equals(value)) { return Boolean.TRUE; } if (falseValue_.equals(value)) { return Boolean.FALSE; } throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); } BooleanArgumentType();  BooleanArgumentType(String trueValue, String falseValue); @Override Boolean convert(ArgumentParser parser, Argument arg, String value); @Override String[] inferMetavar(); }
BooleanArgumentType implements ArgumentType<Boolean>,
        MetavarInference { @Override public Boolean convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (trueValue_.equals(value)) { return Boolean.TRUE; } if (falseValue_.equals(value)) { return Boolean.FALSE; } throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); } BooleanArgumentType();  BooleanArgumentType(String trueValue, String falseValue); @Override Boolean convert(ArgumentParser parser, Argument arg, String value); @Override String[] inferMetavar();  }