commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Papendieck, Thomas" <Thomas.Papendi...@opitz-consulting.com>
Subject AW: [CLI] Exception message for required oprion group containes other information as for "normal" option
Date Wed, 30 Nov 2011 12:16:12 GMT
I overwrote OptionsGroup.toString():

 StringBuilder optionGroupString = new StringBuilder("<");
                String separatorChar = "";
                Collection<Option> options = getOptions();
                for (Option option : options) {
                    optionGroupString.append(separatorChar);
                    optionGroupString.append(null != option.getOpt() ? option.getOpt() : option.getLongOpt());
                    separatorChar = " | ";
                }
                optionGroupString.append(">");
                return optionGroupString.toString();

This solved my Problem. 

But I think this is not the intended solution.

________________________________________
Von: Papendieck, Thomas [Thomas.Papendieck@opitz-consulting.com]
Gesendet: Mittwoch, 30. November 2011 12:17
Bis: MCommons Users List ‎[user@commons.apache.org]‎
Betreff: [CLI] Exception message for required oprion group containes other information as
for "normal" option

Hello,

how can I make second test pass?

public class CliRequiredOptionGroupTest {

    private final Option _o1 = OptionBuilder.withDescription("Test1 Description").isRequired().hasArg(true)
            .withLongOpt("testOption1").create();
    private final Option _o2 = OptionBuilder.withDescription("Test2 Description").isRequired().hasArg(true)
            .withLongOpt("testOption2").create();

    @Test
    public final void testRequiredOptions() {
        Options requiredOptions = new Options();
        requiredOptions.addOption(_o1);
        requiredOptions.addOption(_o2);
        try {
            new GnuParser().parse(requiredOptions, new String[] {});
            fail("exception not thrown");
        } catch (ParseException ex) {
            Assert.assertEquals("only short names reported",
                    "Missing required options: testOption1, testOption2",
                    ex.getMessage());
        }
    }

    @Test
    public final void testRequiredOptionGroup() {
        OptionGroup requiredOptionGroup = new OptionGroup();
        requiredOptionGroup.setRequired(true);
        requiredOptionGroup.addOption(_o1);
        requiredOptionGroup.addOption(_o2);
        Options requiredOptions = new Options();
        requiredOptions.addOptionGroup(requiredOptionGroup);
        try {
            new GnuParser().parse(requiredOptions, new String[] {});
            fail("exception not thrown");
        } catch (ParseException ex) {
            Assert.assertEquals("only short names reported",
                    "Missing required option: [testOption1, testOption2]",
                    ex.getMessage());
        }
    }

}

bye
Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message