geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [49/49] incubator-geode git commit: Complete JoptOptionParserTest. Refactor CLI exceptions.
Date Fri, 20 May 2016 16:30:20 GMT
Complete JoptOptionParserTest. Refactor CLI exceptions.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/955275f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/955275f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/955275f4

Branch: refs/heads/feature/GEODE-835-test
Commit: 955275f41911a656ba5a99b3d820115c7ad909e8
Parents: 45b4247
Author: Kirk Lund <klund@apache.org>
Authored: Fri May 20 09:28:57 2016 -0700
Committer: Kirk Lund <klund@apache.org>
Committed: Fri May 20 09:28:57 2016 -0700

----------------------------------------------------------------------
 .../management/internal/cli/CommandManager.java |   4 +-
 .../cli/exceptions/CliCommandException.java     |  37 +-
 .../exceptions/CliCommandInvalidException.java  |  16 +-
 .../CliCommandMultiModeOptionException.java     |  16 +-
 .../CliCommandNotAvailableException.java        |  12 +-
 .../exceptions/CliCommandOptionException.java   |  36 +-
 ...CommandOptionHasMultipleValuesException.java |  17 +-
 .../CliCommandOptionInvalidException.java       |  14 +-
 .../CliCommandOptionMissingException.java       |  17 +-
 .../CliCommandOptionNotApplicableException.java |  20 +-
 ...liCommandOptionValueConversionException.java |  16 +-
 .../CliCommandOptionValueException.java         |  25 +-
 .../CliCommandOptionValueMissingException.java  |  20 +-
 .../internal/cli/exceptions/CliException.java   |  17 +-
 .../cli/exceptions/ExceptionGenerator.java      |  28 +-
 .../management/internal/cli/parser/Option.java  |   2 +-
 .../cli/parser/jopt/JoptOptionParser.java       |  27 +-
 .../internal/cli/JoptOptionParserTest.java      | 466 ++++++++++++++++++-
 18 files changed, 636 insertions(+), 154 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/CommandManager.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/CommandManager.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/CommandManager.java
index 46a8226..9c8025e 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/CommandManager.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/CommandManager.java
@@ -365,8 +365,8 @@ public class CommandManager {
           for (Annotation annotation : annotations) {
             if (annotation instanceof CliArgument) {
               // Here we need to create the argument Object
-              arguments.add(createArgument((CliArgument) annotation,
-                  parameterType, parameterNo));
+              Argument argumentToAdd = createArgument((CliArgument) annotation, parameterType, parameterNo);
+              arguments.add(argumentToAdd);
               parameterNo++;
             } else if (annotation instanceof CliOption) {
               Option createdOption = createOption((CliOption) annotation, parameterType, parameterNo);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandException.java
index eb019a7..29358f3 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandException.java
@@ -16,50 +16,51 @@
  */
 package com.gemstone.gemfire.management.internal.cli.exceptions;
 
-import java.util.List;
-
 import com.gemstone.gemfire.management.internal.cli.parser.CommandTarget;
 import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
 
 public class CliCommandException extends CliException {
+
   private CommandTarget commandTarget;
   private OptionSet optionSet;
 
-  public OptionSet getOptionSet() {
-    return optionSet;
+  public CliCommandException(final CommandTarget commandTarget) {
+    this(commandTarget, null, null);
   }
 
-  public CommandTarget getCommandTarget() {
-    return commandTarget;
+  public CliCommandException(final CommandTarget commandTarget, final OptionSet optionSet) {
+    this(commandTarget, optionSet, null);
   }
 
-  public CliCommandException(CommandTarget commandTarget) {
+  public CliCommandException(final CommandTarget commandTarget, final OptionSet optionSet, final Throwable cause) {
+    super(cause);
     this.setCommandTarget(commandTarget);
-  }
-
-  public CliCommandException(CommandTarget commandTarget, OptionSet optionSet) {
-    this(commandTarget);
     this.setOptionSet(optionSet);
   }
 
-  public CliCommandException(CommandTarget commandTarget2,
-      List<String> nonOptionArguments) {
+  public CommandTarget getCommandTarget() {
+    return commandTarget;
   }
 
   /**
-   * @param commandTarget
-   *          the commandTarget to set
+   * TODO: make this immutable
+   *
+   * @param commandTarget the commandTarget to set
    */
   public void setCommandTarget(CommandTarget commandTarget) {
     this.commandTarget = commandTarget;
   }
 
+  public OptionSet getOptionSet() {
+    return optionSet;
+  }
+
   /**
-   * @param optionSet
-   *          the optionSet to set
+   * TODO: make this immutable
+   *
+   * @param optionSet the optionSet to set
    */
   public void setOptionSet(OptionSet optionSet) {
     this.optionSet = optionSet;
   }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandInvalidException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandInvalidException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandInvalidException.java
index 6fde9db..b3d3775 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandInvalidException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandInvalidException.java
@@ -21,13 +21,19 @@ import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
 
 public class CliCommandInvalidException extends CliCommandException {
 
-  public CliCommandInvalidException(CommandTarget commandTarget) {
-    super(commandTarget);
+  public CliCommandInvalidException(final CommandTarget commandTarget) {
+    this(commandTarget, null, null);
   }
 
-  public CliCommandInvalidException(CommandTarget commandTarget,
-      OptionSet optionSet) {
-    super(commandTarget, optionSet);
+  public CliCommandInvalidException(final CommandTarget commandTarget, OptionSet optionSet) {
+    this(commandTarget, optionSet, null);
   }
 
+  public CliCommandInvalidException(final Throwable cause) {
+    this(null, null, cause);
+  }
+
+  public CliCommandInvalidException(final CommandTarget commandTarget, OptionSet optionSet, Throwable cause) {
+    super(commandTarget, optionSet, cause);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandMultiModeOptionException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandMultiModeOptionException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandMultiModeOptionException.java
index 5f5cbfd..3259406 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandMultiModeOptionException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandMultiModeOptionException.java
@@ -22,15 +22,18 @@ import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
 
 public class CliCommandMultiModeOptionException extends CliCommandOptionException {
   
-  public static final int MULTIPLE_LEAD_OPTIONS=1;
-  public static final int OPTIONS_FROM_MULTIPLE_MODES=2;
+  public static final int MULTIPLE_LEAD_OPTIONS = 1; // TODO: move or delete
+  public static final int OPTIONS_FROM_MULTIPLE_MODES = 2; // TODO: move or delete
   
   private String leadOptionString;
   private int code;
 
-  public CliCommandMultiModeOptionException(CommandTarget commandTarget,
-      Option option, String string, int code) {
-    super(commandTarget, option);
+  public CliCommandMultiModeOptionException(final CommandTarget commandTarget, final Option option, final String string, final int code) {
+    this(commandTarget, option, string, code, null);
+  }
+
+  public CliCommandMultiModeOptionException(final CommandTarget commandTarget, final Option option, final String string, final int code, final Throwable cause) {
+    super(commandTarget, option, cause);
     this.leadOptionString = string;
     this.code = code;
   }
@@ -42,7 +45,4 @@ public class CliCommandMultiModeOptionException extends CliCommandOptionExceptio
   public int getCode() {
     return code;
   }
-  
-  
 }
-

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandNotAvailableException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandNotAvailableException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandNotAvailableException.java
index cf8bc06..c1e1358 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandNotAvailableException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandNotAvailableException.java
@@ -21,13 +21,15 @@ import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
 
 public class CliCommandNotAvailableException extends CliCommandException {
 
-  public CliCommandNotAvailableException(CommandTarget commandTarget) {
-    super(commandTarget);
+  public CliCommandNotAvailableException(final CommandTarget commandTarget) {
+    this(commandTarget, null, null);
   }
 
-  public CliCommandNotAvailableException(CommandTarget commandTarget,
-      OptionSet optionSet) {
-    super(commandTarget, optionSet);
+  public CliCommandNotAvailableException(final CommandTarget commandTarget, final OptionSet optionSet) {
+    this(commandTarget, optionSet, null);
   }
 
+  public CliCommandNotAvailableException(final CommandTarget commandTarget, final OptionSet optionSet, final Throwable cause) {
+    super(commandTarget, optionSet, cause);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionException.java
index bfe6c3a..3fdec10 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionException.java
@@ -24,30 +24,36 @@ public class CliCommandOptionException extends CliCommandException {
 
   private Option option;
 
+  public CliCommandOptionException(final CommandTarget commandTarget, final Option option) {
+    this(commandTarget, option, null, null);
+  }
+
+  public CliCommandOptionException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet) {
+    this(commandTarget, option, optionSet, null);
+  }
+
+  public CliCommandOptionException(final CommandTarget commandTarget, final Option option, final Throwable cause) {
+    this(commandTarget, option, null, cause);
+  }
+
+  public CliCommandOptionException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, final Throwable cause) {
+    super(commandTarget, optionSet, cause);
+    this.setOption(option);
+  }
+
   /**
-   * @return option for which the exception occured
+   * @return option for which the exception occurred
    */
   public Option getOption() {
     return option;
   }
 
   /**
-   * @param option
-   *          the option to set
+   * TODO: make this immutable
+   *
+   * @param option the option to set
    */
   public void setOption(Option option) {
     this.option = option;
   }
-
-  public CliCommandOptionException(CommandTarget commandTarget, Option option) {
-    super(commandTarget);
-    this.setOption(option);
-  }
-
-  public CliCommandOptionException(CommandTarget commandTarget, Option option,
-      OptionSet optionSet) {
-    super(commandTarget, optionSet);
-    this.setOption(option);
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionHasMultipleValuesException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionHasMultipleValuesException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionHasMultipleValuesException.java
index 3932636..2439945 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionHasMultipleValuesException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionHasMultipleValuesException.java
@@ -21,13 +21,22 @@ import com.gemstone.gemfire.management.internal.cli.parser.Option;
 import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
 
 public class CliCommandOptionHasMultipleValuesException extends CliCommandOptionValueException {
+
   private static final long serialVersionUID = -5277268341319591711L;
 
-  public CliCommandOptionHasMultipleValuesException(CommandTarget commandTarget, Option option, String value) {
-    super(commandTarget, option, value);
+  public CliCommandOptionHasMultipleValuesException(final CommandTarget commandTarget, final Option option, final String value) {
+    this(commandTarget, option, null, value, null);
+  }
+
+  public CliCommandOptionHasMultipleValuesException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, final String value) {
+    this(commandTarget, option, optionSet, value, null);
+  }
+
+  public CliCommandOptionHasMultipleValuesException(final Throwable cause) {
+    this(null, null, null, null, cause);
   }
 
-  public CliCommandOptionHasMultipleValuesException(CommandTarget commandTarget, Option option, OptionSet optionSet, String value) {
-    super(commandTarget, option, optionSet, value);
+  public CliCommandOptionHasMultipleValuesException(final CommandTarget commandTarget, Option option, final OptionSet optionSet, final String value, final Throwable cause) {
+    super(commandTarget, option, optionSet, value, cause);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionInvalidException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionInvalidException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionInvalidException.java
index af7e44a..7ce747a 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionInvalidException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionInvalidException.java
@@ -22,13 +22,15 @@ import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
 
 public class CliCommandOptionInvalidException extends CliCommandOptionException {
 
-  public CliCommandOptionInvalidException(CommandTarget commandTarget,
-      Option option) {
-    super(commandTarget, option);
+  public CliCommandOptionInvalidException(final CommandTarget commandTarget, final Option option) {
+    this(commandTarget, option, null, null);
   }
 
-  public CliCommandOptionInvalidException(CommandTarget commandTarget,
-      Option option, OptionSet optionSet) {
-    super(commandTarget, option, optionSet);
+  public CliCommandOptionInvalidException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet) {
+    this(commandTarget, option, optionSet, null);
+  }
+
+  public CliCommandOptionInvalidException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, final Throwable cause) {
+    super(commandTarget, option, optionSet, cause);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionMissingException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionMissingException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionMissingException.java
index 00481fc..1a2c8fe 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionMissingException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionMissingException.java
@@ -22,14 +22,19 @@ import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
 
 public class CliCommandOptionMissingException extends CliCommandOptionException {
 
-  public CliCommandOptionMissingException(CommandTarget commandTarget,
-      Option option) {
-    super(commandTarget, option);
+  public CliCommandOptionMissingException(final CommandTarget commandTarget, final Option option) {
+    this(commandTarget, option, null, null);
   }
 
-  public CliCommandOptionMissingException(CommandTarget commandTarget,
-      Option option, OptionSet optionSet) {
-    super(commandTarget, option, optionSet);
+  public CliCommandOptionMissingException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet) {
+    this(commandTarget, option, optionSet, null);
   }
 
+  public CliCommandOptionMissingException(final Throwable cause) {
+    this(null, null, null, cause);
+  }
+
+  public CliCommandOptionMissingException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, final Throwable cause) {
+    super(commandTarget, option, optionSet, cause);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionNotApplicableException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionNotApplicableException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionNotApplicableException.java
index 4e99ba1..1e9f726 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionNotApplicableException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionNotApplicableException.java
@@ -20,17 +20,21 @@ import com.gemstone.gemfire.management.internal.cli.parser.CommandTarget;
 import com.gemstone.gemfire.management.internal.cli.parser.Option;
 import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
 
-public class CliCommandOptionNotApplicableException extends
-    CliCommandOptionException {
+public class CliCommandOptionNotApplicableException extends CliCommandOptionException {
 
-  public CliCommandOptionNotApplicableException(CommandTarget commandTarget,
-      Option option) {
-    super(commandTarget, option);
+  public CliCommandOptionNotApplicableException(final CommandTarget commandTarget, final Option option) {
+    this(commandTarget, option, null, null);
   }
 
-  public CliCommandOptionNotApplicableException(CommandTarget commandTarget,
-      Option option, OptionSet optionSet) {
-    super(commandTarget, option, optionSet);
+  public CliCommandOptionNotApplicableException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet) {
+    this(commandTarget, option, optionSet, null);
   }
 
+  public CliCommandOptionNotApplicableException(final Throwable cause) {
+    this(null, null, null, cause);
+  }
+
+  public CliCommandOptionNotApplicableException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, Throwable cause) {
+    super(commandTarget, option, optionSet, cause);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueConversionException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueConversionException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueConversionException.java
index b16c8f2..8330f79 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueConversionException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueConversionException.java
@@ -20,17 +20,17 @@ import com.gemstone.gemfire.management.internal.cli.parser.CommandTarget;
 import com.gemstone.gemfire.management.internal.cli.parser.Option;
 import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
 
-public class CliCommandOptionValueConversionException extends
-    CliCommandOptionValueException {
+public class CliCommandOptionValueConversionException extends CliCommandOptionValueException {
 
-  public CliCommandOptionValueConversionException(CommandTarget commandTarget,
-      Option option, String value) {
-    super(commandTarget, option, value);
+  public CliCommandOptionValueConversionException(final CommandTarget commandTarget, final Option option, final String value) {
+    this(commandTarget, option, null, value, null);
   }
 
-  public CliCommandOptionValueConversionException(CommandTarget commandTarget,
-      Option option, OptionSet optionSet, String value) {
-    super(commandTarget, option, optionSet, value);
+  public CliCommandOptionValueConversionException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, final String value) {
+    this(commandTarget, option, optionSet, value, null);
   }
 
+  public CliCommandOptionValueConversionException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, final String value, final Throwable cause) {
+    super(commandTarget, option, optionSet, value, null);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueException.java
index 774a8b1..4e04578 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueException.java
@@ -22,21 +22,26 @@ import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
 
 public class CliCommandOptionValueException extends CliCommandOptionException {
 
-  private String value;
+  private final String value;
 
-  public String getValue() {
-    return value;
+  public CliCommandOptionValueException(final CommandTarget commandTarget, final Option option, final String value) {
+    this(commandTarget, option, null, value, null);
   }
 
-  public CliCommandOptionValueException(CommandTarget commandTarget,
-      Option option, String value) {
-    super(commandTarget, option);
-    this.value = value;
+  public CliCommandOptionValueException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, final String value) {
+    this(commandTarget, option, null, value, null);
+  }
+
+  public CliCommandOptionValueException(final Throwable cause) {
+    this(null, null, null, null, cause);
   }
 
-  public CliCommandOptionValueException(CommandTarget commandTarget,
-      Option option, OptionSet optionSet, String value) {
-    super(commandTarget, option, optionSet);
+  public CliCommandOptionValueException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, final String value, final Throwable cause) {
+    super(commandTarget, option, optionSet, cause);
     this.value = value;
   }
+
+  public String getValue() {
+    return value;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueMissingException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueMissingException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueMissingException.java
index 4eb2a6b..5fa02d9 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueMissingException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliCommandOptionValueMissingException.java
@@ -20,17 +20,21 @@ import com.gemstone.gemfire.management.internal.cli.parser.CommandTarget;
 import com.gemstone.gemfire.management.internal.cli.parser.Option;
 import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
 
-public class CliCommandOptionValueMissingException extends
-    CliCommandOptionValueException {
+public class CliCommandOptionValueMissingException extends CliCommandOptionValueException {
 
-  public CliCommandOptionValueMissingException(CommandTarget commandTarget,
-      Option option, String value) {
-    super(commandTarget, option, value);
+  public CliCommandOptionValueMissingException(final CommandTarget commandTarget, final Option option, final String value) {
+    this(commandTarget, option, null, value, null);
   }
 
-  public CliCommandOptionValueMissingException(CommandTarget commandTarget,
-      Option option, OptionSet optionSet, String value) {
-    super(commandTarget, option, optionSet, value);
+  public CliCommandOptionValueMissingException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, final String value) {
+    this(commandTarget, option, optionSet, value, null);
+  }
+
+  public CliCommandOptionValueMissingException(final Throwable cause) {
+    this(null, null, null, null, cause);
   }
 
+  public CliCommandOptionValueMissingException(final CommandTarget commandTarget, final Option option, final OptionSet optionSet, final String value, final Throwable cause) {
+    super(commandTarget, option, optionSet, value);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliException.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliException.java
index bc0db3f..3e0551e 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/CliException.java
@@ -16,6 +16,21 @@
  */
 package com.gemstone.gemfire.management.internal.cli.exceptions;
 
-public class CliException extends Exception {
+public abstract class CliException extends Exception {
 
+  public CliException() {
+    this(null, null);
+  }
+
+  public CliException(String message) {
+    this(message, null);
+  }
+
+  public CliException(Throwable cause) {
+    super(null, cause);
+  }
+
+  public CliException(String message, Throwable cause) {
+    super(message, cause);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/ExceptionGenerator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/ExceptionGenerator.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/ExceptionGenerator.java
index 6824735..61af7a4 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/ExceptionGenerator.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/exceptions/ExceptionGenerator.java
@@ -22,22 +22,26 @@ import joptsimple.OptionException;
 import joptsimple.OptionMissingRequiredArgumentException;
 import joptsimple.UnrecognizedOptionException;
 
+import com.gemstone.gemfire.management.internal.cli.parser.Option;
+
 /**
- * 
- *         Converts joptsimple exceptions into corresponding exceptions for cli
- * 
+ * Converts joptsimple exceptions into corresponding exceptions for cli
  */
 public class ExceptionGenerator {
 
-  public static CliException generate(OptionException oe) {
-    if (oe instanceof MissingRequiredOptionException) {
-      return new CliCommandOptionMissingException(null, null, null);
-    } else if (oe instanceof OptionMissingRequiredArgumentException) {
-      return new CliCommandOptionValueMissingException(null, null, null, null);
-    } else if (oe instanceof UnrecognizedOptionException) {
-      return new CliCommandOptionNotApplicableException(null, null, null);
-    } else if (oe instanceof MultipleArgumentsForOptionException) {
-      return new CliCommandOptionHasMultipleValuesException(null, null, null);
+  public static CliCommandOptionException generate(Option option, OptionException e) {
+    if (MissingRequiredOptionException.class.isInstance(e)) {
+      return new CliCommandOptionMissingException(e);
+
+    } else if (OptionMissingRequiredArgumentException.class.isInstance(e)) {
+      return new CliCommandOptionValueMissingException(e);
+
+    } else if (UnrecognizedOptionException.class.isInstance(e)) {
+      return new CliCommandOptionNotApplicableException(e);
+
+    } else if (MultipleArgumentsForOptionException.class.isInstance(e)) {
+      return new CliCommandOptionHasMultipleValuesException(e);
+
     } else {
       return null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/Option.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/Option.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/Option.java
index 09aabd8..1d115ce 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/Option.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/Option.java
@@ -124,7 +124,7 @@ public class Option extends Parameter {
     return true;
   }
 
-  public final List<String> getAggregate() {
+  public List<String> getAggregate() {
     return aggregate;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java
index 6e56bf4..4ea9516 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/parser/jopt/JoptOptionParser.java
@@ -44,9 +44,11 @@ import com.gemstone.gemfire.management.internal.cli.parser.preprocessor.TrimmedI
 /**
  * Implementation of {@link GfshOptionParser} which internally makes use of
  * {@link joptsimple.OptionParser}
+ *
+ * Newly constructed JoptOptionParser must be loaded with arguments and
+ * options before parsing command strings.
  * 
  * @since 7.0
- * 
  */
 public class JoptOptionParser implements GfshOptionParser {
 
@@ -119,11 +121,9 @@ public class JoptOptionParser implements GfshOptionParser {
       // int factor = 0;
       try {
         joptOptionSet = parser.parse(preProcessedInput);
-      } catch (Exception e) {
-        if (e instanceof OptionException) {
-          ce = processException(e);
-          joptOptionSet = ((OptionException) e).getDetected();
-        }
+      } catch (OptionException e) {
+        ce = processException(e);
+        joptOptionSet = e.getDetected();
       }
       if (joptOptionSet != null) {
 
@@ -244,19 +244,8 @@ public class JoptOptionParser implements GfshOptionParser {
     return optionSet;
   }
 
-  private CliCommandOptionException processException(Exception e) {
-    CliCommandOptionException ce = null;
-    if (e instanceof OptionException) {
-      ce = (CliCommandOptionException) ExceptionGenerator
-          .generate((OptionException) e);
-      if (ce != null) {
-        if (ce instanceof CliCommandOptionException) {
-          ((CliCommandOptionException) ce)
-              .setOption(getOption((OptionException) e));
-        }
-      }
-    }
-    return ce;
+  private CliCommandOptionException processException(final OptionException exception) {
+    return ExceptionGenerator.generate(getOption(exception), exception);
   }
 
   private Option getOption(OptionException oe) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/955275f4/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/JoptOptionParserTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/JoptOptionParserTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/JoptOptionParserTest.java
index 564ec37..ad82a94 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/JoptOptionParserTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/JoptOptionParserTest.java
@@ -17,11 +17,21 @@
 package com.gemstone.gemfire.management.internal.cli;
 
 import static org.assertj.core.api.Assertions.*;
+import static org.mockito.Mockito.*;
 
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
 
+import com.gemstone.gemfire.management.internal.cli.exceptions.CliCommandOptionMissingException;
+import com.gemstone.gemfire.management.internal.cli.exceptions.CliCommandOptionNotApplicableException;
 import com.gemstone.gemfire.management.internal.cli.parser.Argument;
 import com.gemstone.gemfire.management.internal.cli.parser.Option;
 import com.gemstone.gemfire.management.internal.cli.parser.OptionSet;
@@ -29,49 +39,469 @@ import com.gemstone.gemfire.management.internal.cli.parser.jopt.JoptOptionParser
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
+@RunWith(JUnitParamsRunner.class)
 public class JoptOptionParserTest {
 
-  private JoptOptionParser defaultJoptOptionParser;
-  private OptionSet defaultOptionSet;
+  private JoptOptionParser emptyOptionParser;
+  private OptionSet emptyOptionSet;
+
+  private Argument requiredArgument;
+  private Argument optionalArgument;
+
+  private Option requiredOption;
+  private Option optionalOption;
+
+  private JoptOptionParser simpleOptionParser;
+  private JoptOptionParser exampleOptionParser;
 
   @Before
   public void setUp() throws Exception {
-    this.defaultJoptOptionParser = new JoptOptionParser();
-    this.defaultOptionSet = new OptionSet();
+    this.emptyOptionParser = new JoptOptionParser();
+    this.emptyOptionSet = new OptionSet();
+    defineSimpleOptionParser();
+    defineExampleOptionParser();
   }
 
   @Test
   public void getArgumentsIsEmptyByDefault() throws Exception {
-    assertThat(this.defaultJoptOptionParser.getArguments()).isEmpty();
+    assertThat(this.emptyOptionParser.getArguments()).isEmpty();
   }
 
   @Test
   public void getOptionsIsNullByDefault() throws Exception {
-    assertThat(this.defaultJoptOptionParser.getOptions()).isNull();
+    assertThat(this.emptyOptionParser.getOptions()).isNull();
   }
 
   @Test
   public void parseNullReturnsDefaultOptionSet() throws Exception {
-    OptionSet optionSet = this.defaultJoptOptionParser.parse(null);
-    assertThat(optionSet.areArgumentsPresent()).isEqualTo(defaultOptionSet.areArgumentsPresent());
-    assertThat(optionSet.areOptionsPresent()).isEqualTo(defaultOptionSet.areOptionsPresent());
-    assertThat(optionSet.getNoOfSpacesRemoved()).isEqualTo(defaultOptionSet.getNoOfSpacesRemoved());
-    assertThat(optionSet.getSplit()).isEqualTo(defaultOptionSet.getSplit());
-    assertThat(optionSet.getNoOfSpacesRemoved()).isEqualTo(defaultOptionSet.getNoOfSpacesRemoved());
-    assertThat(optionSet.getUserInput()).isEqualTo(""); //defaultOptionSet.getUserInput());
-    assertThat(optionSet.getValue((Argument)null)).isEqualTo(defaultOptionSet.getValue((Argument)null));
-    assertThat(optionSet.getValue((Option)null)).isEqualTo(defaultOptionSet.getValue((Option)null));
+    OptionSet optionSet = this.emptyOptionParser.parse(null);
+    assertThat(optionSet.areArgumentsPresent()).isEqualTo(emptyOptionSet.areArgumentsPresent());
+    assertThat(optionSet.areOptionsPresent()).isEqualTo(emptyOptionSet.areOptionsPresent());
+    assertThat(optionSet.getNoOfSpacesRemoved()).isEqualTo(emptyOptionSet.getNoOfSpacesRemoved());
+    assertThat(optionSet.getSplit()).isEqualTo(emptyOptionSet.getSplit());
+    assertThat(optionSet.getNoOfSpacesRemoved()).isEqualTo(emptyOptionSet.getNoOfSpacesRemoved());
+    assertThat(optionSet.getUserInput()).isEqualTo(""); //emptyOptionSet.getUserInput());
+    assertThat(optionSet.getValue((Argument)null)).isEqualTo(emptyOptionSet.getValue((Argument)null));
+    assertThat(optionSet.getValue((Option)null)).isEqualTo(emptyOptionSet.getValue((Option)null));
   }
 
   @Test
   public void parseEmptyThrowsNullPointerException() throws Exception {
-    assertThatThrownBy(() -> this.defaultJoptOptionParser.parse("")).isInstanceOf(NullPointerException.class);
+    assertThatThrownBy(() -> this.emptyOptionParser.parse("")).isInstanceOf(NullPointerException.class);
+  }
+
+  @Test
+  public void setArgumentsShouldCreateCopy() throws Exception {
+    Argument argument = mock(Argument.class);
+    when(argument.isRequired()).thenReturn(true);
+
+    LinkedList<Argument> arguments = new LinkedList<>();
+    arguments.add(argument);
+
+    this.emptyOptionParser.setArguments(arguments);
+
+    assertThat(this.emptyOptionParser.getArguments()).isNotSameAs(arguments);
+    assertThat(this.emptyOptionParser.getArguments()).hasSize(1);
+
+    arguments.clear();
+
+    assertThat(arguments).hasSize(0);
+    assertThat(this.emptyOptionParser.getArguments()).hasSize(1);
+  }
+
+  @Test
+  public void setArgumentsShouldKeepRequiredBeforeOptional() throws Exception {
+    Argument requiredArgument1 = mock(Argument.class);
+    when(requiredArgument1.isRequired()).thenReturn(true);
+    Argument optionalArgument1 = mock(Argument.class);
+    when(optionalArgument1.isRequired()).thenReturn(false);
+
+    LinkedList<Argument> arguments = new LinkedList<>();
+    arguments.add(requiredArgument1);
+    arguments.add(optionalArgument1);
+
+    this.emptyOptionParser.setArguments(arguments);
+
+    LinkedList<Argument> argumentsReturned = this.emptyOptionParser.getArguments();
+
+    assertThat(argumentsReturned).hasSize(2);
+    assertThat(argumentsReturned.getFirst()).isSameAs(requiredArgument1);
+    assertThat(argumentsReturned.getLast()).isSameAs(optionalArgument1);
   }
 
   @Test
-  public void foo() throws Exception {
-    //assertThatThrownBy(() -> this.defaultJoptOptionParser.parse(null)
+  public void setArgumentsShouldMoveRequiredBeforeOptional() throws Exception {
+    Argument requiredArgument1 = mock(Argument.class);
+    when(requiredArgument1.isRequired()).thenReturn(true);
+    Argument optionalArgument1 = mock(Argument.class);
+    when(optionalArgument1.isRequired()).thenReturn(false);
+
+    LinkedList<Argument> arguments = new LinkedList<>();
+    arguments.add(optionalArgument1);
+    arguments.add(requiredArgument1);
+
+    this.emptyOptionParser.setArguments(arguments);
+
+    LinkedList<Argument> argumentsReturned = this.emptyOptionParser.getArguments();
+
+    assertThat(argumentsReturned).hasSize(2);
+    assertThat(argumentsReturned.getFirst()).isSameAs(requiredArgument1);
+    assertThat(argumentsReturned.getLast()).isSameAs(optionalArgument1);
   }
 
+  @Test
+  public void setOptionsShouldKeepSameInstance() throws Exception {
+    Option option = mock(Option.class);
+    ArrayList aggregate = new ArrayList<String>();
+    aggregate.add("option");
+    when(option.getAggregate()).thenReturn(aggregate);
+    when(option.getHelp()).thenReturn("help text");
+
+    LinkedList<Option> options = new LinkedList<>();
+    options.add(option);
+
+    this.emptyOptionParser.setOptions(options);
+
+    assertThat(this.emptyOptionParser.getOptions()).isSameAs(options);
+    assertThat(this.emptyOptionParser.getOptions()).hasSize(1);
+
+    options.clear();
+
+    assertThat(options).hasSize(0);
+    assertThat(this.emptyOptionParser.getOptions()).hasSize(0);
+  }
+
+  @Test
+  public void parseInputWithDefinedArgumentShouldWork() throws Exception {
+    LinkedList<Argument> arguments = new LinkedList<>();
+    LinkedList<Option> options = new LinkedList<>();
+
+    arguments.add(this.requiredArgument);
+
+    JoptOptionParser optionParser = new JoptOptionParser();
+    optionParser.setArguments(arguments);
+    optionParser.setOptions(options);
+
+    OptionSet optionSet = optionParser.parse("command1 argument1_value");
+    assertThat(optionSet.areArgumentsPresent()).isTrue();
+    assertThat(optionSet.hasArgument(this.requiredArgument)).isTrue();
+  }
+
+  @Test
+  public void parseInputWithOneArgumentShouldFindJustOneArgument() throws Exception {
+    LinkedList<Argument> arguments = new LinkedList<>();
+    LinkedList<Option> options = new LinkedList<>();
+
+    arguments.add(this.requiredArgument);
+
+    JoptOptionParser optionParser = new JoptOptionParser();
+    optionParser.setArguments(arguments);
+    optionParser.setOptions(options);
+
+    OptionSet optionSet = optionParser.parse("command1 argument1_value");
+    assertThat(optionSet.areArgumentsPresent()).isTrue();
+    assertThat(optionSet.hasArgument(this.requiredArgument)).isTrue();
+    assertThat(optionSet.hasArgument(this.optionalArgument)).isFalse();
+  }
+
+  @Test
+  public void parseInputWithTwoArgumentsShouldFindTwoArguments() throws Exception {
+    LinkedList<Argument> arguments = new LinkedList<>();
+    LinkedList<Option> options = new LinkedList<>();
+
+    arguments.add(this.requiredArgument);
+    arguments.add(this.optionalArgument);
+
+    JoptOptionParser optionParser = new JoptOptionParser();
+    optionParser.setArguments(arguments);
+    optionParser.setOptions(options);
+
+    OptionSet optionSet = optionParser.parse("command1 argument1_value? argument2_value");
+    assertThat(optionSet.areArgumentsPresent()).isTrue();
+    assertThat(optionSet.hasArgument(this.requiredArgument)).isTrue();
+    assertThat(optionSet.hasArgument(this.optionalArgument)).isTrue();
+  }
+
+  @Test
+  public void parseInputWithUndefinedArgumentShouldThrow() throws Exception {
+    LinkedList<Argument> arguments = new LinkedList<>();
+    LinkedList<Option> options = new LinkedList<>();
+
+    arguments.add(this.requiredArgument);
 
+    JoptOptionParser optionParser = new JoptOptionParser();
+    optionParser.setArguments(arguments);
+    optionParser.setOptions(options);
+
+    assertThatThrownBy(() -> optionParser.parse("command1 argument1_value? argument2_value")).isOfAnyClassIn(CliCommandOptionNotApplicableException.class);
+  }
+
+  @Test
+  public void parseInputWithUndefinedOptionShouldThrow() throws Exception {
+    assertThatThrownBy(() -> this.simpleOptionParser.parse("command1 argument1_value argument2_value --undefinedOption")).isExactlyInstanceOf(CliCommandOptionNotApplicableException.class);
+  }
+
+  @Test
+  public void parseInputWithOneOptionShouldFindOneOption() throws Exception {
+    OptionSet optionSet = this.simpleOptionParser.parse("command1 argument1_value --option1");
+    assertThat(optionSet.areOptionsPresent()).isTrue();
+    assertThat(optionSet.hasOption(this.requiredOption)).isTrue();
+    assertThat(optionSet.hasOption(this.optionalOption)).isFalse();
+  }
+
+  @Test
+  public void parseInputWithTwoOptionsShouldFindTwoOptions() throws Exception {
+    OptionSet optionSet = this.simpleOptionParser.parse("command1 argument1_value --option1 --option2");
+    assertThat(optionSet.areOptionsPresent()).isTrue();
+    assertThat(optionSet.hasOption(this.requiredOption)).isTrue();
+    assertThat(optionSet.hasOption(this.optionalOption)).isTrue();
+  }
+
+  @Test
+  public void parseInputWithOptionWithValueShouldFindOption() throws Exception {
+    OptionSet optionSet = this.simpleOptionParser.parse("command1 argument1_value --option1=value");
+    assertThat(optionSet.areOptionsPresent()).isTrue();
+    assertThat(optionSet.hasOption(this.requiredOption)).isTrue();
+  }
+
+  @Test
+  public void parseInputWithOptionWithoutValueShouldFindOption() throws Exception {
+    OptionSet optionSet = this.simpleOptionParser.parse("command1 argument1_value --option1");
+    assertThat(optionSet.areOptionsPresent()).isTrue();
+    assertThat(optionSet.hasOption(this.requiredOption)).isTrue();
+  }
+
+  @Test
+  public void parseInputWithoutOptionShouldNotFindOptions() throws Exception {
+    LinkedList<Argument> arguments = new LinkedList<>();
+    LinkedList<Option> options = new LinkedList<>();
+
+    arguments.add(this.requiredArgument);
+
+    JoptOptionParser optionParser = new JoptOptionParser();
+    optionParser.setArguments(arguments);
+    optionParser.setOptions(options);
+
+    OptionSet optionSet = optionParser.parse("command1 argument1_value");
+    assertThat(optionSet.areOptionsPresent()).isFalse();
+    assertThat(optionSet.hasOption(this.requiredOption)).isFalse();
+  }
+
+  @Test
+  @Parameters(method = "exampleInputParameters")
+  public void parseInputWithExampleInputParametesr(String command, boolean expectException, boolean hasArguments, boolean hasOptions) throws Exception {
+    if (expectException) {
+      assertThatThrownBy(() -> this.exampleOptionParser.parse(command)).isExactlyInstanceOf(CliCommandOptionMissingException.class);
+      return;
+    }
+
+    OptionSet options = this.exampleOptionParser.parse(command);
+    assertThat(options).isNotNull();
+    assertThat(options.areArgumentsPresent()).isEqualTo(hasArguments);
+    assertThat(options.areOptionsPresent()).isEqualTo(hasOptions);
+  }
+
+  private static Object[] exampleInputParameters() {
+    return new Object[]{
+      // 0
+      new Object[] { " ARGUMENT1_VALUE —option1=somevalue", false, true, false },
+      // 1
+      new Object[] { " ARGUMENT1_VALUE?      ARGUMENT2_VALUE -- ----------", false, true, false },
+      // 2
+      new Object[] { " --option1=value", false, false, true },
+      // 3
+      new Object[] { "         ARGUMENT1_VALUE?       ARGUMENT2_VALUE --option1=option1value --option2", false, true, true },
+      // 4
+      new Object[] { "         ARGUMENT1_VALUE?       ARGUMENT2_VALUE --option1=option1value --option2=option2value --option3=option3value", false, true, true },
+      // 5
+      new Object[] { " --string=string1 --stringArray=1,2 --stringArray=3,4 --stringList=11,12,13 --integer=10 --stringArray=5 --stringList=14,15", false, false, true },
+      // 6
+      new Object[] { " --stringArray=1,2 --stringArray='3,4'", false, false, true },
+      // 7
+      new Object[] { " --string=\"1\" --colonArray=2:3:4 --stringArray=5,\"6,7\",8 --stringList=\"9,10,11,12\"", false, false, true },
+      // 8
+      new Object[] { " --string=string1 --stringArray=1,2 --string=string2", false, false, true },
+      // 9
+      new Object[] { " this is just one argument?this is a second argument", false, true, false }
+    };
+  }
+
+  private void defineSimpleOptionParser() {
+    LinkedList<Argument> arguments = new LinkedList<Argument>();
+    LinkedList<Option> options = new LinkedList<Option>();
+
+    this.requiredArgument = mock(Argument.class);
+    when(this.requiredArgument.getArgumentName()).thenReturn("argument1");
+    when(this.requiredArgument.getContext()).thenReturn("context for argument1");
+    when(this.requiredArgument.getHelp()).thenReturn("help for argument1");
+    when(this.requiredArgument.isRequired()).thenReturn(true);
+    arguments.add(this.requiredArgument);
+
+    this.optionalArgument = mock(Argument.class);
+    when(this.optionalArgument.getArgumentName()).thenReturn("argument2");
+    when(this.optionalArgument.getContext()).thenReturn("context for argument2");
+    when(this.optionalArgument.getHelp()).thenReturn("help for argument2");
+    when(this.optionalArgument.isRequired()).thenReturn(false);
+    when(this.optionalArgument.getUnspecifiedDefaultValue()).thenReturn("{unspecified default value for argument2}");
+    when(this.optionalArgument.isSystemProvided()).thenReturn(false);
+    arguments.add(this.optionalArgument);
+
+    this.requiredOption = mock(Option.class);
+    when(this.requiredOption.getLongOption()).thenReturn("--option1");
+    List<String> aggregate = new ArrayList<>();
+    aggregate.add("option1");
+    when(this.requiredOption.getAggregate()).thenReturn(aggregate);
+    when(this.requiredOption.getLongOption()).thenReturn("option1");
+    when(this.requiredOption.getHelp()).thenReturn("help for option1");
+    when(this.requiredOption.getValueSeparator()).thenReturn("=");
+    when(this.requiredOption.isRequired()).thenReturn(true);
+    assertThat(this.requiredOption.getAggregate()).isNotEmpty();
+    options.add(this.requiredOption);
+
+    this.optionalOption = mock(Option.class);
+    when(this.optionalOption.getLongOption()).thenReturn("--option2");
+    aggregate = new ArrayList<>();
+    aggregate.add("option2");
+    when(this.optionalOption.getAggregate()).thenReturn(aggregate);
+    when(this.optionalOption.getLongOption()).thenReturn("option2");
+    when(this.optionalOption.getHelp()).thenReturn("help for option2");
+    when(this.optionalOption.getValueSeparator()).thenReturn("=");
+    when(this.optionalOption.isRequired()).thenReturn(false);
+    assertThat(this.optionalOption.getAggregate()).isNotEmpty();
+    options.add(this.optionalOption);
+
+    this.simpleOptionParser = new JoptOptionParser();
+    this.simpleOptionParser.setArguments(arguments);
+    this.simpleOptionParser.setOptions(options);
+  }
+
+  private void defineExampleOptionParser() {
+    LinkedList<Argument> arguments = new LinkedList<Argument>();
+    LinkedList<Option> options = new LinkedList<Option>();
+
+    Argument argument1 = mock(Argument.class);
+    when(argument1.getArgumentName()).thenReturn("argument1");
+    when(argument1.getContext()).thenReturn("context for argument1");
+    when(argument1.getHelp()).thenReturn("help for argument1");
+    when(argument1.isRequired()).thenReturn(true);
+    arguments.add(argument1);
+
+    Argument argument2 = mock(Argument.class);
+    when(argument2.getArgumentName()).thenReturn("argument2");
+    when(argument2.getContext()).thenReturn("context for argument2");
+    when(argument2.getHelp()).thenReturn("help for argument2");
+    when(argument2.isRequired()).thenReturn(false);
+    when(argument2.getUnspecifiedDefaultValue()).thenReturn("{unspecified default value for argument2}");
+    when(argument2.isSystemProvided()).thenReturn(false);
+    arguments.add(argument2);
+
+    Argument argument3 = mock(Argument.class);
+    when(argument3.getArgumentName()).thenReturn("argument3");
+    when(argument3.getContext()).thenReturn("context for argument3");
+    when(argument3.getHelp()).thenReturn("help for argument3");
+    when(argument3.isRequired()).thenReturn(false);
+    when(argument3.getUnspecifiedDefaultValue()).thenReturn("{unspecified default value for argument3}");
+    when(argument2.isSystemProvided()).thenReturn(false);
+    arguments.add(argument3);
+
+    Option option1 = mock(Option.class);
+    when(option1.getLongOption()).thenReturn("--option1");
+    List<String> aggregate1 = new ArrayList<>();
+    aggregate1.add("option1");
+    when(option1.getAggregate()).thenReturn(aggregate1);
+    when(option1.getLongOption()).thenReturn("option1");
+    when(option1.getHelp()).thenReturn("help for option1");
+    when(option1.getValueSeparator()).thenReturn("=");
+    when(option1.isRequired()).thenReturn(false);
+    assertThat(option1.getAggregate()).isNotEmpty();
+    options.add(option1);
+
+    Option option2 = mock(Option.class);
+    when(option2.getLongOption()).thenReturn("--option2");
+    List<String> aggregate2 = new ArrayList<>();
+    aggregate2.add("option2");
+    when(option2.getAggregate()).thenReturn(aggregate2);
+    when(option2.getLongOption()).thenReturn("option2");
+    when(option2.getHelp()).thenReturn("help for option2");
+    when(option2.getValueSeparator()).thenReturn("=");
+    when(option2.isRequired()).thenReturn(false);
+    assertThat(option2.getAggregate()).isNotEmpty();
+    options.add(option2);
+
+    Option option3 = mock(Option.class);
+    when(option3.getLongOption()).thenReturn("--option3");
+    List<String> aggregate3 = new ArrayList<>();
+    aggregate3.add("option3");
+    when(option3.getAggregate()).thenReturn(aggregate3);
+    when(option3.getLongOption()).thenReturn("option3");
+    when(option3.getHelp()).thenReturn("help for option3");
+    when(option3.getValueSeparator()).thenReturn("=");
+    when(option3.isRequired()).thenReturn(false);
+    assertThat(option3.getAggregate()).isNotEmpty();
+    options.add(option3);
+
+    Option stringOption = mock(Option.class);
+    when(stringOption.getLongOption()).thenReturn("--string");
+    List<String> aggregateStringOption = new ArrayList<>();
+    aggregateStringOption.add("string");
+    when(stringOption.getAggregate()).thenReturn(aggregateStringOption);
+    when(stringOption.getLongOption()).thenReturn("string");
+    when(stringOption.getHelp()).thenReturn("help for string");
+    when(stringOption.getValueSeparator()).thenReturn("=");
+    when(stringOption.isRequired()).thenReturn(false);
+    assertThat(stringOption.getAggregate()).isNotEmpty();
+    options.add(stringOption);
+
+    Option stringArrayOption = mock(Option.class);
+    when(stringArrayOption.getLongOption()).thenReturn("--stringArray");
+    List<String> aggregateStringArrayOption = new ArrayList<>();
+    aggregateStringArrayOption.add("stringArray");
+    when(stringArrayOption.getAggregate()).thenReturn(aggregateStringArrayOption);
+    when(stringArrayOption.getLongOption()).thenReturn("stringArray");
+    when(stringArrayOption.getHelp()).thenReturn("help for stringArray");
+    when(stringArrayOption.getValueSeparator()).thenReturn("=");
+    when(stringArrayOption.isRequired()).thenReturn(false);
+    assertThat(stringArrayOption.getAggregate()).isNotEmpty();
+    options.add(stringArrayOption);
+
+    Option stringListOption = mock(Option.class);
+    when(stringListOption.getLongOption()).thenReturn("--stringList");
+    List<String> aggregateStringListOption = new ArrayList<>();
+    aggregateStringListOption.add("stringList");
+    when(stringListOption.getAggregate()).thenReturn(aggregateStringListOption);
+    when(stringListOption.getLongOption()).thenReturn("stringList");
+    when(stringListOption.getHelp()).thenReturn("help for stringList");
+    when(stringListOption.getValueSeparator()).thenReturn("=");
+    when(stringListOption.isRequired()).thenReturn(false);
+    assertThat(stringListOption.getAggregate()).isNotEmpty();
+    options.add(stringListOption);
+
+    Option integerOption = mock(Option.class);
+    when(integerOption.getLongOption()).thenReturn("--integer");
+    List<String> aggregateIntegerOption = new ArrayList<>();
+    aggregateIntegerOption.add("integer");
+    when(integerOption.getAggregate()).thenReturn(aggregateIntegerOption);
+    when(integerOption.getLongOption()).thenReturn("integer");
+    when(integerOption.getHelp()).thenReturn("help for integer");
+    when(integerOption.getValueSeparator()).thenReturn("=");
+    when(integerOption.isRequired()).thenReturn(false);
+    assertThat(integerOption.getAggregate()).isNotEmpty();
+    options.add(integerOption);
+
+    Option colonArrayOption = mock(Option.class);
+    when(colonArrayOption.getLongOption()).thenReturn("--colonArray");
+    List<String> aggregateColonArrayOption = new ArrayList<>();
+    aggregateColonArrayOption.add("colonArray");
+    when(colonArrayOption.getAggregate()).thenReturn(aggregateColonArrayOption);
+    when(colonArrayOption.getLongOption()).thenReturn("colonArray");
+    when(colonArrayOption.getHelp()).thenReturn("help for colonArray");
+    when(colonArrayOption.getValueSeparator()).thenReturn("=");
+    when(colonArrayOption.isRequired()).thenReturn(false);
+    assertThat(colonArrayOption.getAggregate()).isNotEmpty();
+    options.add(colonArrayOption);
+
+    this.exampleOptionParser = new JoptOptionParser();
+    this.exampleOptionParser.setArguments(arguments);
+    this.exampleOptionParser.setOptions(options);
+  }
 }


Mime
View raw message