[Japi-cvs] SF.net SVN: japi: [497] libs/argparser/trunk/src
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2007-07-05 20:06:55
|
Revision: 497 http://svn.sourceforge.net/japi/?rev=497&view=rev Author: christianhujer Date: 2007-07-05 13:06:54 -0700 (Thu, 05 Jul 2007) Log Message: ----------- Fix: [ 1748308 ] Options that only differ in case are not listed in --help Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/MethodOptionComparator.java libs/argparser/trunk/src/test/net/sf/japi/io/args/MethodOptionComparatorTest.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/MethodOptionComparator.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/MethodOptionComparator.java 2007-07-05 20:05:05 UTC (rev 496) +++ libs/argparser/trunk/src/net/sf/japi/io/args/MethodOptionComparator.java 2007-07-05 20:06:54 UTC (rev 497) @@ -20,8 +20,8 @@ package net.sf.japi.io.args; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.Comparator; -import java.util.Arrays; import org.jetbrains.annotations.NotNull; /** Compares methods by their options. @@ -40,7 +40,11 @@ final String[] names2 = option2.value(); Arrays.sort(names1); Arrays.sort(names2); - return String.CASE_INSENSITIVE_ORDER.compare(names1[0], names2[0]); + int result = String.CASE_INSENSITIVE_ORDER.compare(names1[0], names2[0]); + if (result == 0) { + result = names1[0].compareTo(names2[0]); + } + return result; } } // class MethodOptionComparator Modified: libs/argparser/trunk/src/test/net/sf/japi/io/args/MethodOptionComparatorTest.java =================================================================== --- libs/argparser/trunk/src/test/net/sf/japi/io/args/MethodOptionComparatorTest.java 2007-07-05 20:05:05 UTC (rev 496) +++ libs/argparser/trunk/src/test/net/sf/japi/io/args/MethodOptionComparatorTest.java 2007-07-05 20:06:54 UTC (rev 497) @@ -19,15 +19,15 @@ package test.net.sf.japi.io.args; +import java.lang.reflect.Method; +import java.util.Comparator; +import java.util.List; +import net.sf.japi.io.args.BasicCommand; import net.sf.japi.io.args.MethodOptionComparator; -import net.sf.japi.io.args.BasicCommand; import net.sf.japi.io.args.Option; +import org.jetbrains.annotations.NotNull; +import org.junit.Assert; import org.junit.Test; -import org.junit.Assert; -import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Method; -import java.util.Comparator; -import java.util.List; /** * Test for {@link MethodOptionComparator}. @@ -53,6 +53,19 @@ Assert.assertTrue("-f / --foo must be sorted before -Z.", comparator.compare(mFoo, mZ) < 0); } + /** Tests whether comparing two methods that only differ in case yields the difference. + * Test for <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=1748308&group_id=149894&atid=776737">[ 1748308 ] Options that only differ in case are not listed in --help</a> + * @throws NoSuchMethodException (unexpected) + */ + @Test + public void testCompareCase() throws NoSuchMethodException { + final Comparator<Method> comparator = MethodOptionComparator.INSTANCE; + final Class<MockCommand> cmdClass = MockCommand.class; + final Method mC1 = cmdClass.getMethod("c"); + final Method mC2 = cmdClass.getMethod("C"); + Assert.assertTrue("-c and -C must not be the same.", comparator.compare(mC1, mC2) != 0); + } + /** Mock Command with methods that should be properly sorted. * The sorting should be: * a(), bar(), buzz(), foo(), Z(). @@ -79,6 +92,14 @@ @Option({"a"}) public void a() {} + /** Dummy command method. */ + @Option({"c"}) + public void c() {} + + /** Dummy command method. */ + @Option({"C"}) + public void C() {} + /** {@inheritDoc} */ @SuppressWarnings({"InstanceMethodNamingConvention"}) public int run(@NotNull final List<String> args) throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |