You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2011/10/15 03:26:13 UTC

svn commit: r1183578 - in /oodt/branches/cas-cl/src: main/java/org/apache/oodt/cas/cl/option/handler/ main/java/org/apache/oodt/cas/cl/util/ test/org/apache/oodt/cas/cl/util/

Author: bfoster
Date: Sat Oct 15 01:26:12 2011
New Revision: 1183578

URL: http://svn.apache.org/viewvc?rev=1183578&view=rev
Log:
- more unit-tests and javadoc
- method cleanup

Modified:
    oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionBeanHandler.java
    oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/StdCmdLineOptionHandler.java
    oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/util/CmdLineUtils.java
    oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestCmdLineUtils.java

Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionBeanHandler.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionBeanHandler.java?rev=1183578&r1=1183577&r2=1183578&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionBeanHandler.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/CmdLineOptionBeanHandler.java Sat Oct 15 01:26:12 2011
@@ -64,20 +64,20 @@ public class CmdLineOptionBeanHandler im
 		for (BeanInfo beanInfo : applyToBeans) {
 			try {
 				Class<?> type = optionInstance.getOption().getType();
-				Object[] vals = (optionInstance.getValues().isEmpty()) ? convertToType(
+				List<?> vals = (optionInstance.getValues().isEmpty()) ? convertToType(
 						Arrays.asList(new String[] { "true" }), type = Boolean.TYPE)
 						: convertToType(optionInstance.getValues(), type);
 				Object applyToBean = appContext.getBean(beanInfo.getBeanId());
 				if (beanInfo.getMethodName() != null) {
 					applyToBean.getClass()
 							.getMethod(beanInfo.getMethodName(), type)
-							.invoke(applyToBean, vals);
+							.invoke(applyToBean, vals.toArray(new Object[vals.size()]));
 				} else {
 					applyToBean
 							.getClass()
 							.getMethod(
 									"set" + StringUtils.capitalize(optionInstance.getOption().getLongOption()), type)
-							.invoke(applyToBean, vals);
+							.invoke(applyToBean, vals.toArray(new Object[vals.size()]));
 				}
 			} catch (Exception e) {
 				throw new RuntimeException(e);

Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/StdCmdLineOptionHandler.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/StdCmdLineOptionHandler.java?rev=1183578&r1=1183577&r2=1183578&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/StdCmdLineOptionHandler.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/option/handler/StdCmdLineOptionHandler.java Sat Oct 15 01:26:12 2011
@@ -3,6 +3,7 @@ package org.apache.oodt.cas.cl.option.ha
 import static org.apache.oodt.cas.cl.util.CmdLineUtils.convertToType;
 
 import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.lang.StringUtils;
@@ -21,19 +22,19 @@ public class StdCmdLineOptionHandler {
 	public void handleOption(CmdLineAction action, CmdLineOptionInstance optionInstance) {
 		try {
 			Class<?> type = optionInstance.getOption().getType();
-			Object[] vals = (optionInstance.getValues().isEmpty()) ? convertToType(
+			List<?> vals = (optionInstance.getValues().isEmpty()) ? convertToType(
 					Arrays.asList(new String[] { "true" }), type = Boolean.TYPE)
 					: convertToType(optionInstance.getValues(), type);
 			if (actionToMethodMap != null && actionToMethodMap.containsKey(action.getName())) {
 				action.getClass()
 						.getMethod(actionToMethodMap.get(action.getName()), type)
-						.invoke(action, vals);
+						.invoke(action, vals.toArray(new Object[vals.size()]));
 			} else {
 				action
 					.getClass()
 					.getMethod(
 							"set" + StringUtils.capitalize(optionInstance.getOption().getLongOption()), type)
-					.invoke(action, vals);
+					.invoke(action, vals.toArray(new Object[vals.size()]));
 			}
 		} catch (Exception e) {
 			throw new RuntimeException(e);

Modified: oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/util/CmdLineUtils.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/util/CmdLineUtils.java?rev=1183578&r1=1183577&r2=1183578&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/util/CmdLineUtils.java (original)
+++ oodt/branches/cas-cl/src/main/java/org/apache/oodt/cas/cl/util/CmdLineUtils.java Sat Oct 15 01:26:12 2011
@@ -45,6 +45,9 @@ import org.apache.oodt.cas.cl.option.req
 import org.apache.oodt.cas.cl.option.validator.CmdLineOptionValidator;
 import org.apache.oodt.cas.cl.action.CmdLineAction;
 
+//Google imports
+import com.google.common.collect.Lists;
+
 /**
  * Collection of common helper methods.
  *
@@ -67,6 +70,9 @@ public class CmdLineUtils {
 	 */
 	public static Set<CmdLineOption> determineRequired(CmdLineAction action,
 			Set<CmdLineOption> options) {
+		Validate.notNull(action);
+		Validate.notNull(options);
+
 		Set<CmdLineOption> requiredOptions = getRequiredOptions(options);
 		for (CmdLineOption option : options) {
 			if (isRequired(action, option)) {
@@ -115,6 +121,9 @@ public class CmdLineUtils {
 	 */
 	public static Set<CmdLineOption> determineOptional(CmdLineAction action,
 			Set<CmdLineOption> options) {
+		Validate.notNull(action);
+		Validate.notNull(options);
+
 		Set<CmdLineOption> optionalOptions = new HashSet<CmdLineOption>();
 		for (CmdLineOption option : options) {
 			if (isOptional(action, option)) {
@@ -135,8 +144,8 @@ public class CmdLineUtils {
 	 * @return True is option is optional, false otherwise.
 	 */
 	public static boolean isOptional(CmdLineAction action, CmdLineOption option) {
-		Validate.notNull(option);
 		Validate.notNull(action);
+		Validate.notNull(option);
 
 		if (option instanceof ActionCmdLineOption) {
 			return false;
@@ -180,6 +189,8 @@ public class CmdLineUtils {
 	 */
 	public static Set<CmdLineOption> getRequiredOptions(
 			Set<CmdLineOption> options, boolean ignoreActionOption) {
+		Validate.notNull(options);
+
 		HashSet<CmdLineOption> requiredOptions = new HashSet<CmdLineOption>();
 		for (CmdLineOption option : options) {
 			if (option.isRequired()
@@ -202,6 +213,8 @@ public class CmdLineUtils {
 	 */
 	public static List<CmdLineOption> sortOptionsByRequiredStatus(
 			Set<CmdLineOption> options) {
+		Validate.notNull(options);
+
 		ArrayList<CmdLineOption> optionsList = new ArrayList<CmdLineOption>(options);
 		Collections.sort(optionsList, new Comparator<CmdLineOption>() {
 			public int compare(CmdLineOption option1, CmdLineOption option2) {
@@ -216,7 +229,21 @@ public class CmdLineUtils {
 		return optionsList;
 	}
 
-	public static CmdLineOption getOptionByName(String optionName, Set<CmdLineOption> options) {
+	/**
+	 * Finds {@link CmdLineOption} whose short name or long name equals given
+	 * option name.
+	 * 
+	 * @param optionName
+	 *          The short or long name of the {@link CmdLineOption} to find
+	 * @param options
+	 *          The {@link CmdLineOption}s to search in
+	 * @return The {@link CmdLineOption} found or null if not found.
+	 */
+	public static CmdLineOption getOptionByName(String optionName,
+			Set<CmdLineOption> options) {
+		Validate.notNull(optionName);
+		Validate.notNull(options);
+
 		for (CmdLineOption option : options)
 			if (option.getLongOption().equals(optionName)
 					|| option.getShortOption().equals(optionName))
@@ -224,8 +251,22 @@ public class CmdLineUtils {
 		return null;
 	}
 
+	/**
+	 * Finds {@link CmdLineOptionInstance} whose {@link CmdLineOption}'s short
+	 * name or long name equals given option name.
+	 * 
+	 * @param optionName
+	 *          The short or long name of the {@link CmdLineOptionInstance}'s
+	 *          {@link CmdLineOption} to find
+	 * @param optionInsts
+	 *          The {@link CmdLineOptionIntance}s to search in
+	 * @return The {@link CmdLineOptionInstance} found or null if not found.
+	 */
 	public static CmdLineOptionInstance getOptionInstanceByName(
 			String optionName, Set<CmdLineOptionInstance> optionInsts) {
+		Validate.notNull(optionName);
+		Validate.notNull(optionInsts);
+
 		for (CmdLineOptionInstance optionInst : optionInsts)
 			if (optionInst.getOption().getLongOption().equals(optionName)
 					|| optionInst.getOption().getShortOption().equals(optionName))
@@ -391,52 +432,52 @@ public class CmdLineUtils {
 		return outputString.toString();
 	}
 
-	public static Object[] convertToType(List<String> values, Class<?> type)
+	public static List<?> convertToType(List<String> values, Class<?> type)
 			throws MalformedURLException, ClassNotFoundException {
 		if (type.equals(File.class)) {
 			List<Object> files = new LinkedList<Object>();
 			for (String value : values)
 				files.add(new File(value));
-			return files.toArray(new Object[files.size()]);
+			return files;
 		} else if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) {
 			List<Object> booleans = new LinkedList<Object>();
 			for (String value : values)
 				booleans.add(value.toLowerCase().trim().equals("true"));
-			return booleans.toArray(new Object[booleans.size()]);
+			return booleans;
 		} else if (type.equals(URL.class)) {
 			List<Object> urls = new LinkedList<Object>();
 			for (String value : values)
 				urls.add(new URL(value));
-			return urls.toArray(new Object[urls.size()]);
+			return urls;
 		} else if (type.equals(Class.class)) {
 			List<Object> classes = new LinkedList<Object>();
 			for (String value : values)
 				classes.add(Class.forName(value));
-			return classes.toArray(new Object[classes.size()]);
+			return classes;
 		} else if (type.equals(List.class)) {
-			return new Object[] { values };
+			return values;
 		} else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) {
 			List<Object> ints = new LinkedList<Object>();
 			for (String value : values)
 				ints.add(new Integer(value));
-			return ints.toArray(new Object[ints.size()]);
+			return ints;
 		} else if (type.equals(Long.class) || type.equals(Long.TYPE)) {
 			List<Object> longs = new LinkedList<Object>();
 			for (String value : values)
 				longs.add(new Long(value));
-			return longs.toArray(new Object[longs.size()]);
+			return longs;
 		} else if (type.equals(Double.class) || type.equals(Double.TYPE)) {
 			List<Object> doubles = new LinkedList<Object>();
 			for (String value : values)
 				doubles.add(new Double(value));
-			return doubles.toArray(new Object[doubles.size()]);
+			return doubles;
 		} else if (type.equals(String.class)) {
 			StringBuffer combinedString = new StringBuffer("");
 			for (String value : values)
 				combinedString.append(value + " ");
-			return new String[] { combinedString.toString().trim() };
+			return Lists.newArrayList(combinedString.toString().trim());
 		} else {
-			return values.toArray(new Object[values.size()]);
+			return values;
 		}
 	}
 }

Modified: oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestCmdLineUtils.java
URL: http://svn.apache.org/viewvc/oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestCmdLineUtils.java?rev=1183578&r1=1183577&r2=1183578&view=diff
==============================================================================
--- oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestCmdLineUtils.java (original)
+++ oodt/branches/cas-cl/src/test/org/apache/oodt/cas/cl/util/TestCmdLineUtils.java Sat Oct 15 01:26:12 2011
@@ -17,6 +17,7 @@
 package org.apache.oodt.cas.cl.util;
 
 //JDK imports
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -29,6 +30,7 @@ import junit.framework.TestCase;
 import org.apache.oodt.cas.cl.action.CmdLineAction;
 import org.apache.oodt.cas.cl.option.ActionCmdLineOption;
 import org.apache.oodt.cas.cl.option.CmdLineOption;
+import org.apache.oodt.cas.cl.option.CmdLineOptionInstance;
 import org.apache.oodt.cas.cl.option.GroupCmdLineOption;
 import org.apache.oodt.cas.cl.option.SimpleCmdLineOption;
 import org.apache.oodt.cas.cl.option.require.RequirementRule;
@@ -41,8 +43,8 @@ import org.apache.oodt.cas.cl.util.CmdLi
 import com.google.common.collect.Sets;
 
 /**
- * Test class for {@link CmdLineUtils}. 
- *
+ * Test class for {@link CmdLineUtils}.
+ * 
  * @author bfoster (Brian Foster)
  */
 public class TestCmdLineUtils extends TestCase {
@@ -52,19 +54,20 @@ public class TestCmdLineUtils extends Te
 		CmdLineOption urlOption, passOption;
 
 		HashSet<CmdLineOption> options = Sets.newHashSet(
-			urlOption = createSimpleOption("url", createRequiredRequirementRule(action)),
-			passOption = createSimpleOption("pass", false),
-			createSimpleOption("user", false),
-			createActionOption("operation"));
+				urlOption = createSimpleOption("url",
+						createRequiredRequirementRule(action)),
+				passOption = createSimpleOption("pass", false),
+				createSimpleOption("user", false), createActionOption("operation"));
 
-		Set<CmdLineOption> requiredOptions = CmdLineUtils.determineRequired(action, options);
+		Set<CmdLineOption> requiredOptions = CmdLineUtils.determineRequired(action,
+				options);
 		assertEquals(Sets.newHashSet(urlOption), requiredOptions);
 
 		options = Sets.newHashSet(
-				urlOption = createSimpleOption("url", createRequiredRequirementRule(action)),
+				urlOption = createSimpleOption("url",
+						createRequiredRequirementRule(action)),
 				passOption = createSimpleOption("pass", true),
-				createSimpleOption("user", false),
-				createActionOption("operation"));
+				createSimpleOption("user", false), createActionOption("operation"));
 
 		requiredOptions = CmdLineUtils.determineRequired(action, options);
 		assertEquals(Sets.newHashSet(urlOption, passOption), requiredOptions);
@@ -72,9 +75,12 @@ public class TestCmdLineUtils extends Te
 
 	public void testIsRequired() {
 		CmdLineAction action = createAction("TestAction");
-		assertTrue(CmdLineUtils.isRequired(action, createSimpleOption("url", createRequiredRequirementRule(action))));
-		assertFalse(CmdLineUtils.isRequired(action, createSimpleOption("url", true)));
-		assertFalse(CmdLineUtils.isRequired(action, createSimpleOption("url", false)));
+		assertTrue(CmdLineUtils.isRequired(action,
+				createSimpleOption("url", createRequiredRequirementRule(action))));
+		assertFalse(CmdLineUtils
+				.isRequired(action, createSimpleOption("url", true)));
+		assertFalse(CmdLineUtils.isRequired(action,
+				createSimpleOption("url", false)));
 	}
 
 	public void testDetermineOptional() {
@@ -82,27 +88,26 @@ public class TestCmdLineUtils extends Te
 		CmdLineOption actionOption = new ActionCmdLineOption();
 
 		HashSet<CmdLineOption> options = Sets.newHashSet(
-			createSimpleOption("url", createRequiredRequirementRule(action)),
-			createSimpleOption("pass", false),
-			createSimpleOption("user", false),
-			actionOption);
+				createSimpleOption("url", createRequiredRequirementRule(action)),
+				createSimpleOption("pass", false), createSimpleOption("user", false),
+				actionOption);
 
-		Set<CmdLineOption> optionalOptions = CmdLineUtils.determineOptional(action, options);
+		Set<CmdLineOption> optionalOptions = CmdLineUtils.determineOptional(action,
+				options);
 		assertTrue(optionalOptions.isEmpty());
 
-		options = Sets.newHashSet(
-			createSimpleOption("pass", true),
-			createSimpleOption("user", true),
-			actionOption);
+		options = Sets.newHashSet(createSimpleOption("pass", true),
+				createSimpleOption("user", true), actionOption);
 
 		optionalOptions = CmdLineUtils.determineOptional(action, options);
 		assertTrue(optionalOptions.isEmpty());
 
-		CmdLineOption passOption, userOption; 
+		CmdLineOption passOption, userOption;
 		options = Sets.newHashSet(
-			passOption = createSimpleOption("pass", createOptionalRequirementRule(action)),
-			userOption = createSimpleOption("user", createOptionalRequirementRule(action)),
-			actionOption);
+				passOption = createSimpleOption("pass",
+						createOptionalRequirementRule(action)),
+				userOption = createSimpleOption("user",
+						createOptionalRequirementRule(action)), actionOption);
 
 		optionalOptions = CmdLineUtils.determineOptional(action, options);
 		assertEquals(Sets.newHashSet(passOption, userOption), optionalOptions);
@@ -110,31 +115,33 @@ public class TestCmdLineUtils extends Te
 
 	public void testIsOptional() {
 		CmdLineAction action = createAction("TestAction");
-		assertTrue(CmdLineUtils.isOptional(action, createSimpleOption("url", createOptionalRequirementRule(action))));
-		assertFalse(CmdLineUtils.isOptional(action, createSimpleOption("url", true)));
-		assertFalse(CmdLineUtils.isOptional(action, createSimpleOption("url", false)));
+		assertTrue(CmdLineUtils.isOptional(action,
+				createSimpleOption("url", createOptionalRequirementRule(action))));
+		assertFalse(CmdLineUtils
+				.isOptional(action, createSimpleOption("url", true)));
+		assertFalse(CmdLineUtils.isOptional(action,
+				createSimpleOption("url", false)));
 	}
 
 	public void testGetRequiredOptions() {
 		CmdLineOption urlOption = createSimpleOption("url", true);
-		HashSet<CmdLineOption> options = Sets.newHashSet(
-			urlOption,
-			createActionOption("action"),
-			createSimpleOption("user", false),
-			createSimpleOption("pass", false));
+		HashSet<CmdLineOption> options = Sets.newHashSet(urlOption,
+				createActionOption("action"), createSimpleOption("user", false),
+				createSimpleOption("pass", false));
 
-		assertEquals(Sets.newHashSet(urlOption), CmdLineUtils.getRequiredOptions(options));
+		assertEquals(Sets.newHashSet(urlOption),
+				CmdLineUtils.getRequiredOptions(options));
 	}
 
 	public void testGetRequiredOptionsDoNotIgnoreActionOptions() {
 		CmdLineOption actionOption, urlOption;
 		HashSet<CmdLineOption> options = Sets.newHashSet(
-			actionOption = createActionOption("action"),
-			urlOption = createSimpleOption("url", true),
-			createSimpleOption("user", false),
-			createSimpleOption("pass", false));
+				actionOption = createActionOption("action"),
+				urlOption = createSimpleOption("url", true),
+				createSimpleOption("user", false), createSimpleOption("pass", false));
 
-		assertEquals(Sets.newHashSet(actionOption, urlOption), CmdLineUtils.getRequiredOptions(options, false));
+		assertEquals(Sets.newHashSet(actionOption, urlOption),
+				CmdLineUtils.getRequiredOptions(options, false));
 	}
 
 	public void testSortOptionsByRequiredStatus() {
@@ -142,15 +149,79 @@ public class TestCmdLineUtils extends Te
 		CmdLineOption userOption, urlOption, passOption, actionOption;
 		HashSet<CmdLineOption> options = Sets.newHashSet(
 				userOption = createSimpleOption("user", false),
-				urlOption = createSimpleOption("url", createRequiredRequirementRule(action)),
+				urlOption = createSimpleOption("url",
+						createRequiredRequirementRule(action)),
 				passOption = createSimpleOption("pass", false),
 				actionOption = createActionOption("action"));
 
-		List<CmdLineOption> sortedOptions = CmdLineUtils.sortOptionsByRequiredStatus(options);
+		List<CmdLineOption> sortedOptions = CmdLineUtils
+				.sortOptionsByRequiredStatus(options);
 		assertEquals(options.size(), sortedOptions.size());
 		assertEquals(actionOption, sortedOptions.get(0));
 		assertEquals(urlOption, sortedOptions.get(1));
-		assertEquals(Sets.newHashSet(userOption, passOption), Sets.newHashSet(sortedOptions.get(2), sortedOptions.get(3)));
+		assertEquals(Sets.newHashSet(userOption, passOption),
+				Sets.newHashSet(sortedOptions.get(2), sortedOptions.get(3)));
+	}
+
+	public void testGetOptionByName() {
+		CmdLineAction action = createAction("action");
+		CmdLineOption userOption, urlOption, passOption, actionOption;
+		HashSet<CmdLineOption> options = Sets.newHashSet(
+				userOption = createSimpleOption("user", "username", false),
+				urlOption = createSimpleOption("u", "url",
+						createRequiredRequirementRule(action)),
+				passOption = createSimpleOption("pass", "password", false),
+				actionOption = createActionOption("action"));
+
+		assertEquals(userOption,
+				CmdLineUtils.getOptionByName(userOption.getShortOption(), options));
+		assertEquals(userOption,
+				CmdLineUtils.getOptionByName(userOption.getLongOption(), options));
+		assertEquals(urlOption,
+				CmdLineUtils.getOptionByName(urlOption.getShortOption(), options));
+		assertEquals(urlOption,
+				CmdLineUtils.getOptionByName(urlOption.getLongOption(), options));
+		assertEquals(passOption,
+				CmdLineUtils.getOptionByName(passOption.getShortOption(), options));
+		assertEquals(passOption,
+				CmdLineUtils.getOptionByName(passOption.getLongOption(), options));
+		assertEquals(actionOption,
+				CmdLineUtils.getOptionByName(actionOption.getShortOption(), options));
+		assertEquals(actionOption,
+				CmdLineUtils.getOptionByName(actionOption.getLongOption(), options));
+	}
+
+	public void testGetOptionInstanceByName() {
+		CmdLineAction action = createAction("action");
+		CmdLineOptionInstance userOptionInst, urlOptionInst, passOptionInst,
+				actionOptionInst;
+		HashSet<CmdLineOptionInstance> optionInsts = Sets.newHashSet(
+				userOptionInst = new CmdLineOptionInstance(createSimpleOption("user",
+						"username", false), new ArrayList<String>()),
+				urlOptionInst = new CmdLineOptionInstance(createSimpleOption("u",
+						"url", createRequiredRequirementRule(action)),
+						new ArrayList<String>()),
+				passOptionInst = new CmdLineOptionInstance(createSimpleOption("pass",
+						"password", false), new ArrayList<String>()),
+				actionOptionInst = new CmdLineOptionInstance(
+						createActionOption("action"), new ArrayList<String>()));
+
+		assertEquals(userOptionInst, CmdLineUtils.getOptionInstanceByName(
+				userOptionInst.getOption().getShortOption(), optionInsts));
+		assertEquals(userOptionInst, CmdLineUtils.getOptionInstanceByName(
+				userOptionInst.getOption().getLongOption(), optionInsts));
+		assertEquals(urlOptionInst, CmdLineUtils.getOptionInstanceByName(
+				urlOptionInst.getOption().getShortOption(), optionInsts));
+		assertEquals(urlOptionInst, CmdLineUtils.getOptionInstanceByName(
+				urlOptionInst.getOption().getLongOption(), optionInsts));
+		assertEquals(passOptionInst, CmdLineUtils.getOptionInstanceByName(
+				passOptionInst.getOption().getShortOption(), optionInsts));
+		assertEquals(passOptionInst, CmdLineUtils.getOptionInstanceByName(
+				passOptionInst.getOption().getLongOption(), optionInsts));
+		assertEquals(actionOptionInst, CmdLineUtils.getOptionInstanceByName(
+				actionOptionInst.getOption().getShortOption(), optionInsts));
+		assertEquals(actionOptionInst, CmdLineUtils.getOptionInstanceByName(
+				actionOptionInst.getOption().getLongOption(), optionInsts));
 	}
 
 	private static CmdLineAction createAction(String name) {
@@ -160,11 +231,12 @@ public class TestCmdLineUtils extends Te
 			public void execute() {
 				// do nothing
 			}
-			
+
 		};
 	}
 
-	private static GroupCmdLineOption createGroupOption(String longName, boolean required) {
+	private static GroupCmdLineOption createGroupOption(String longName,
+			boolean required) {
 		GroupCmdLineOption option = new GroupCmdLineOption();
 		option.setLongOption(longName);
 		option.setShortOption(longName);
@@ -172,18 +244,30 @@ public class TestCmdLineUtils extends Te
 		return option;
 	}
 
-	private static SimpleCmdLineOption createSimpleOption(String longName, boolean required) {
+	private static SimpleCmdLineOption createSimpleOption(String longName,
+			boolean required) {
+		return createSimpleOption(longName, longName, required);
+	}
+
+	private static SimpleCmdLineOption createSimpleOption(String shortName,
+			String longName, boolean required) {
 		SimpleCmdLineOption option = new SimpleCmdLineOption();
+		option.setShortOption(shortName);
 		option.setLongOption(longName);
-		option.setShortOption(longName);
 		option.setRequired(required);
 		return option;
 	}
 
-	private static SimpleCmdLineOption createSimpleOption(String longName, RequirementRule rule) {
+	private static SimpleCmdLineOption createSimpleOption(String longName,
+			RequirementRule rule) {
+		return createSimpleOption(longName, longName, rule);
+	}
+
+	private static SimpleCmdLineOption createSimpleOption(String shortName,
+			String longName, RequirementRule rule) {
 		SimpleCmdLineOption option = new SimpleCmdLineOption();
+		option.setShortOption(shortName);
 		option.setLongOption(longName);
-		option.setShortOption(longName);
 		option.setRequirementRules(Collections.singletonList(rule));
 		return option;
 	}
@@ -195,15 +279,19 @@ public class TestCmdLineUtils extends Te
 		return option;
 	}
 
-	private static RequirementRule createRequiredRequirementRule(CmdLineAction action) {
+	private static RequirementRule createRequiredRequirementRule(
+			CmdLineAction action) {
 		StdRequirementRule rule = new StdRequirementRule();
-		rule.addActionDependency(new ActionDependency(action.getName(), Relation.REQUIRED));
+		rule.addActionDependency(new ActionDependency(action.getName(),
+				Relation.REQUIRED));
 		return rule;
 	}
 
-	private static RequirementRule createOptionalRequirementRule(CmdLineAction action) {
+	private static RequirementRule createOptionalRequirementRule(
+			CmdLineAction action) {
 		StdRequirementRule rule = new StdRequirementRule();
-		rule.addActionDependency(new ActionDependency(action.getName(), Relation.OPTIONAL));
+		rule.addActionDependency(new ActionDependency(action.getName(),
+				Relation.OPTIONAL));
 		return rule;
 	}
 }