package org.yi.happy.archive;

import static org.junit.Assert.assertArrayEquals;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.UnrecognizedOptionException;
import org.junit.Test;

/**
 * Experimental tests for the commons-cli library.
 */
public class CommandLineTest {
    /**
     * Show what happens when an invalid option is given.
     * 
     * @throws ParseException
     */
    @Test(expected = UnrecognizedOptionException.class)
    public void testBadOption() throws ParseException {
        Options o = new Options().addOption("a", "apple", true, "Apples");

        String[] arguments = { "--orange", "5" };
        new GnuParser().parse(o, arguments);
    }

    /**
     * End the argument list to catch an option with dashes.
     * 
     * @throws ParseException
     */
    @Test
    public void testArguments() throws ParseException {
        Options o = new Options().addOption("a", "apple", true, "Apples");

        String[] arguments = { "--", "--orange", "5" };
        CommandLine c = new GnuParser().parse(o, arguments);

        assertArrayEquals(new String[] { "--orange", "5" }, c.getArgs());
    }

}

@@ -73,16 +73,61 @@
 yEquals;
+%0Aimport static org.junit.Assert.assertEquals;
 %0A%0Aimport
@@ -1320,10 +1320,545 @@
 %0A    %7D%0A%0A
+    /**%0A     * An option that may be specified more than once.%0A     * %0A     * @throws ParseException%0A     */%0A    @Test%0A    public void testMultipleInstance() throws ParseException %7B%0A        Options o = new Options().addOption(%22a%22, %22apple%22, true, %22Apples%22);%0A%0A        String%5B%5D args = %7B %22-a%22, %22one%22, %22-a%22, %22two%22 %7D;%0A        CommandLine c = new GnuParser().parse(o, args);%0A%0A        assertArrayEquals(new String%5B%5D %7B %22one%22, %22two%22 %7D, c%0A                .getOptionValues(%22apple%22));%0A%0A        assertEquals(%22one%22, c.getOptionValue(%22apple%22));%0A    %7D%0A
 %7D%0A

check how multiple instances of an option are handled.