ArgHelperTestpublic class ArgHelperTest extends TestCase
Constructors Summary |
---|
public ArgHelperTest(String name)
super( name );
|
Methods Summary |
---|
private static void | dm(java.lang.Object msg)
System.out.println( SmartStringifier.toString( msg ) );
| protected void | setUp()
| ArgHelper | setupArgHelper(int startOffset, java.lang.String options, java.lang.String input)
final ArgHelperOptionsInfo optionsInfo = new ArgHelperOptionsInfo();
if ( options != null )
{
optionsInfo.addOptions( options );
}
final String [] tokens = (input.length() == 0) ?
new String [0] : input.split( "" + ArgHelperOptionsInfo.MULTIPLE_DELIM );
final ListIterator iter = Arrays.asList( tokens ).listIterator( startOffset );
final ArgHelper argHelper = new ArgHelperImpl( iter, optionsInfo );
return( argHelper );
| ArgHelper | setupArgHelper(java.lang.String options, java.lang.String input)
return( setupArgHelper( 0, options, input ) );
| protected void | tearDown()
| public void | testBooleanFailureWithEquals()
final String booleanOptions = "b1";
final String input = "--b1=hello";
try
{
ArgHelper argHelper = setupArgHelper( booleanOptions, input );
argHelper.getBoolean( "b1", null );
fail( "expecte this input to fail for boolean: " + input );
}
catch( Exception e )
{
}
| public void | testBooleanFailureWithSeparateArg()
final String booleanOptions = "testbool";
final String input = "--testbool false";// 'false' is an operand
final ArgHelper argHelper = setupArgHelper( booleanOptions, input );
final Boolean value = argHelper.getBoolean( booleanOptions, null );
assertEquals( "expected 1 operand from: " + input, 1, argHelper.getOperands().length );
assertEquals( "expected 1 option from: " + input, 1, argHelper.countOptions() );
| public void | testBooleanFailureWithSeparateArgTrue()
final String booleanOptions = "testbool";
final String input = "--testbool true";// 'true' is an operand
final ArgHelper argHelper = setupArgHelper( booleanOptions, input );
final Boolean value = argHelper.getBoolean( booleanOptions, null );
assertEquals( "expected 1 operand from: " + input, 1, argHelper.getOperands().length );
assertEquals( "expected 1 option from: " + input, 1, argHelper.countOptions() );
| public void | testBooleanWithInlineArgFalse()
final String booleanOptions = "testbool";
final String input = "--testbool=false";
final ArgHelper argHelper = setupArgHelper( booleanOptions, input );
final Boolean value = argHelper.getBoolean( booleanOptions, null );
assertEquals( "expected FALSE from " + input, Boolean.FALSE, value );
| public void | testBooleanWithInlineArgTrue()
final String booleanOptions = "testbool";
final String input = "--testbool=true";
final ArgHelper argHelper = setupArgHelper( booleanOptions, input );
final Boolean value = argHelper.getBoolean( booleanOptions, null );
assertEquals( "expected TRUE from " + input, Boolean.TRUE, value );
| public void | testBooleanWithoutArg()
final String booleanOptions = "testbool";
final String input = "--testbool";
final ArgHelper argHelper = setupArgHelper( booleanOptions, input );
final Boolean value = argHelper.getBoolean( booleanOptions, null );
assertEquals( "expected true from " + input, Boolean.TRUE, value );
| public void | testIllegalOptionsFailure()
try
{
final ArgHelper argHelper = setupArgHelper( "", "--option1=1" );
}
catch( Exception e )
{
// we expected to get here
}
| public void | testInteger0()
final ArgHelper argHelper = setupArgHelper( "i1,1", "--i1=0" );
final Integer value = argHelper.getInteger( "i1" );
assertEquals(Integer.valueOf(0), value);
| public void | testIntegerNegative()
final ArgHelper argHelper = setupArgHelper( "i1,1", "--i1=-9999" );
final Integer value = argHelper.getInteger( "i1" );
assertEquals(Integer.valueOf(-9999), value);
| public void | testIntegerPositive()
final ArgHelper argHelper = setupArgHelper( "i1,1", "--i1=9999" );
final Integer value = argHelper.getInteger( "i1" );
assertEquals(Integer.valueOf(9999), value);
| public void | testMultipleArgsWithEquals()
final ArgHelper argHelper = setupArgHelper( "a1,4", "--a1=1,2,hello,there op1 op2" );
final String [] values = argHelper.getArgValues( "a1" );
assertEquals( "expected 4 options", values.length, 4 );
assertEquals( "expected 2 operands", 2, argHelper.getOperands().length );
| public void | testMultipleArgsWithSpaces()
final ArgHelper argHelper = setupArgHelper( "a1,4", "--a1 1 2 hello there op1 op2" );
final String [] values = argHelper.getArgValues( "a1" );
assertEquals( values.length, 4 );
assertEquals( "expected 2 operands", 2, argHelper.getOperands().length );
| public void | testMultipleBooleans()
final String booleanOptions = "b1 b2 b3 b4";
final String input = "--b1 --b2=false --b3 --b4=false";
final ArgHelper argHelper = setupArgHelper( booleanOptions, input );
assertEquals( "expected b1 to be true from: " + input,
Boolean.TRUE, argHelper.getBoolean( "b1", null ) );
assertEquals( "expected b2 to be false from: " + input,
Boolean.FALSE, argHelper.getBoolean( "b2", null ) );
assertEquals( "expected b3 to be true from: " + input,
Boolean.TRUE, argHelper.getBoolean( "b3", null ) );
assertEquals( "expected b4 to be false from: " + input,
Boolean.FALSE, argHelper.getBoolean( "b4", null ) );
| public void | testNoOperands()
final ArgHelper argHelper = setupArgHelper( "b1 b2 s1,1", "--b1 --b2 --s1=hello" );
assertEquals( "expecting 0 operands", 0, argHelper.getOperands().length );
assertEquals( "expecting 3 options", 3, argHelper.countOptions() );
final String value = argHelper.getString( "s1", null);
assertEquals( "hello", value );
| public void | testNoOptionsNoOperands()
final ArgHelper argHelper = setupArgHelper( "s1,1", "--s1=" );
final String value = argHelper.getString( "s1", null);
assertEquals( "", value );
| public void | testNoOptionsNoOperandsWithCmd()
final ArgHelper argHelper = setupArgHelper( 1, null, "cmd" );
assertEquals( "expecting no options", 0, argHelper.countOptions() );
assertEquals( "expecting no operands", 0, argHelper.getOperands().length );
| public void | testNoOptionsOrOperands()
final ArgHelper argHelper = setupArgHelper( null, "" );
assertEquals( "expected no options", 0, argHelper.countOptions() );
assertEquals( "expected no operands", 0, argHelper.getOperands().length );
| public void | testOnlyOperands()
final ArgHelper argHelper = setupArgHelper( "", "op1 op2" );
assertEquals( "expecting 2 operands", 2, argHelper.getOperands().length );
assertEquals( "expecting 0 options", 0, argHelper.countOptions() );
| public void | testSingleCharBoolean()
final String booleanOptions = "b";
final String input = "-b";
try
{
final ArgHelper argHelper = setupArgHelper( booleanOptions, input );
assertEquals( "expected TRUE for: " + input,
Boolean.TRUE, argHelper.getBoolean( booleanOptions, null) );
}
catch( Exception e )
{
// we expected to get here
}
| public void | testSingleCharBooleanWithValue()
final String booleanOptions = "b";
final String input = "-b=false";
try
{
final ArgHelper argHelper = setupArgHelper( booleanOptions, input );
assertEquals( "expected FALSE for: " + input,
Boolean.FALSE, argHelper.getBoolean( booleanOptions, null) );
}
catch( Exception e )
{
// we expected to get here
}
|
|