@Test
public void testGetIntegerValue() throws ParseException
{

    final Integer testDefaultValue = 500;
    final Integer testMinValue = 0;
    final Integer testMaxValue = 1000;
    ArgumentParser argParser = new ArgumentParser("");
    Option intOpt = argParser.addArgument("i", "int", true, "Some integer parameter", false);
    Integer inputValue;
    Integer resultValue;
    final String shortIntOpt = String.format("-%s", intOpt.getOpt());
    final String longIntOpt = String.format("--%s", intOpt.getLongOpt());
    argParser.parseArguments(new String[] {});
    assertNull(argParser.getIntegerValue(intOpt));
    assertEquals(testDefaultValue, argParser.getIntegerValue(intOpt, testDefaultValue));
    inputValue = 123;
    argParser.parseArguments(new String[] {shortIntOpt, inputValue.toString()});
    resultValue = argParser.getIntegerValue(intOpt);
    assertNotNull(resultValue);
    assertEquals(inputValue, resultValue);
    inputValue = 456;
    argParser.parseArguments(new String[] {shortIntOpt, inputValue.toString()});
    resultValue = argParser.getIntegerValue(intOpt, testDefaultValue);
    assertNotNull(resultValue);
    assertEquals(inputValue, resultValue);
    inputValue = 789;
    argParser.parseArguments(new String[] {longIntOpt, inputValue.toString()});
    resultValue = argParser.getIntegerValue(intOpt);
    assertNotNull(resultValue);
    assertEquals(inputValue, resultValue);
    // The "happy path" test case for the minimum and maximum allowed values.
    inputValue = 234;
    argParser.parseArguments(new String[] {longIntOpt, inputValue.toString()});
    resultValue = argParser.getIntegerValue(intOpt, testDefaultValue, testMinValue, testMaxValue);
    assertNotNull(resultValue);
    assertEquals(inputValue, resultValue);
    // The default value test case the minimum and maximum allowed values.
    argParser.parseArguments(new String[] {});
    resultValue = argParser.getIntegerValue(intOpt, testDefaultValue, testMinValue, testMaxValue);
    assertNotNull(resultValue);
    assertEquals(testDefaultValue, resultValue);
    // The edge test case for the minimum allowed value.
    argParser.parseArguments(new String[] {longIntOpt, testMinValue.toString()});
    resultValue = argParser.getIntegerValue(intOpt, testDefaultValue, testMinValue, testMaxValue);
    assertNotNull(resultValue);
    assertEquals(testMinValue, resultValue);
    // The edge test case for the maximum allowed value.
    argParser.parseArguments(new String[] {longIntOpt, testMaxValue.toString()});
    resultValue = argParser.getIntegerValue(intOpt, testDefaultValue, testMinValue, testMaxValue);
    assertNotNull(resultValue);
    assertEquals(testMaxValue, resultValue);
    // The edge test case for the minimum and maximum allowed values.
    argParser.parseArguments(new String[] {longIntOpt, testDefaultValue.toString()});
    resultValue = argParser.getIntegerValue(intOpt, testDefaultValue, testDefaultValue, testDefaultValue);
    assertNotNull(resultValue);
    assertEquals(testDefaultValue, resultValue);
    // Try to get an option value what is less than the minimum allowed value.
    inputValue = testMinValue - 1;
    argParser.parseArguments(new String[] {longIntOpt, inputValue.toString()});
    try
    {
        argParser.getIntegerValue(intOpt, testDefaultValue, testMinValue, testMaxValue);
        fail("Suppose to throw an IllegalArgumentException when option value is less than the minimum allowed value.");
    }
    catch (IllegalArgumentException e)
    {
        assertEquals(String.format("The %s option value %d is less than the minimum allowed value of %d.", intOpt.getLongOpt(), inputValue, testMinValue),
            e.getMessage());
    }
    // Try to get an option value what is greater than the maximum allowed value.
    inputValue = testMaxValue + 1;
    argParser.parseArguments(new String[] {longIntOpt, inputValue.toString()});
    try
    {
        argParser.getIntegerValue(intOpt, testDefaultValue, testMinValue, testMaxValue);
        fail("Suppose to throw an IllegalArgumentException when option value is greater than the maximum allowed value.");
    }
    catch (IllegalArgumentException e)
    {
        assertEquals(String.format("The %s option value %d is bigger than maximum allowed value of %d.", intOpt.getLongOpt(), inputValue, testMaxValue),
            e.getMessage());
    }
}