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 [CLI] Exception message for required oprion group containes other information as for "normal" option
Date Wed, 30 Nov 2011 11:17:07 GMT
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


Mime
View raw message