FileDocCategorySizeDatePackage
ArgHelperOptionsInfoTest.javaAPI DocGlassfish v2 API5285Fri May 04 22:24:48 BST 2007com.sun.cli.jmx.cmd

ArgHelperOptionsInfoTest

public class ArgHelperOptionsInfoTest extends TestCase

Fields Summary
Constructors Summary
public ArgHelperOptionsInfoTest()

	
Methods Summary
voidcheckCreateFailure(java.lang.String options)

		try
		{
			new ArgHelperOptionsInfo( options );
			fail( "expected failure from option description \"" + options + "\"" );
		}
		catch( Exception e )
		{
			// good
		}
	
voidcheckRedundantFailure(java.lang.String args)

		try
		{
			new ArgHelperOptionsInfo( args );
			fail( "expected rejection of redundant option" );
		}
		catch( Exception e )
		{
		}
	
public voidsetUp()

	
public voidtearDown()

	
public voidtestCreate()

		new ArgHelperOptionsInfo();
		new ArgHelperOptionsInfo( "a b c" );
		new ArgHelperOptionsInfo( "aa bb,2 cc" );
		new ArgHelperOptionsInfo( "long-option-dashed-name" );
		new ArgHelperOptionsInfo( "long.option.dotted.name" );
		new ArgHelperOptionsInfo( "long_option_underscore_name" );
		new ArgHelperOptionsInfo( "long-option_mixed.name" );
	
public voidtestCreateFailures()

		final String	illegals	= "~`!@#$%^&*()+={}[]|\\:;\"'<>?,/";
		
		for( int i = 0; i < illegals.length(); ++i )
		{
			checkCreateFailure( "" + illegals.charAt( i ) );
		}
	
public voidtestIllegals()

		final ArgHelperOptionsInfo	info	= new ArgHelperOptionsInfo( "hello h" );
		
		assertEquals( false, info.isLegalOption( "hello" ) );
		assertEquals( false, info.isLegalOption( "-hello" ) );
		assertEquals( false, info.isLegalOption( "h" ) );
		assertEquals( false, info.isLegalOption( "--h" ) );
		assertEquals( false, info.isLegalOption( "-" ) );
		assertEquals( false, info.isLegalOption( "--" ) );
		assertEquals( false, info.isLegalOption( "" ) );
	
public voidtestLegals()

		final ArgHelperOptionsInfo	info	= new ArgHelperOptionsInfo( "hello --there,3 x,1 -y,1" );
		
		assertEquals( true, info.isLegalOption( "--hello" ) );
		assertEquals( true, info.isLegalOption( "--there" ) );
		assertEquals( true, info.isLegalOption( "-x" ) );
		assertEquals( true, info.isLegalOption( "-y" ) );
	
public voidtestMixedArgs()

		final ArgHelperOptionsInfo	info	= new ArgHelperOptionsInfo( "a b,1 c,2 d,3 --xyz,4" );
		
		assertEquals( true, info.isLegalOption( "-a" ) );
		assertEquals( false, info.isLegalOption( "--a" ) );
		assertEquals( 1, info.getNumValues( "-a" ) );
		assertEquals( true, info.isBoolean( "-a" ) );
		
		assertEquals( 1, info.getNumValues( "-b" ) );
		assertEquals( 2, info.getNumValues( "-c" ) );
		assertEquals( 3, info.getNumValues( "-d" ) );
		assertEquals( 4, info.getNumValues( "--xyz" ) );
		
	
public voidtestRedundant()

		checkRedundantFailure( "a a" );
		checkRedundantFailure( "aa aa" );
		checkRedundantFailure( "--aa --aa" );
		checkRedundantFailure( "-a -a" );