CommandLineProcessor implements Closeable { protected String getOptionValue( final String option, final boolean required, final boolean emptyOk ) throws ParseException { final String value = StringUtils.trim( commandLine.getOptionValue( option ) ); if ( required && StringUtils.isEmpty( value ) ) { throw new ParseException( Messages.getInstance().getErrorString( "CommandLineProcessor.ERROR_0001_MISSING_ARG", option ) ); } if ( !emptyOk && StringUtils.isEmpty( value ) ) { throw new ParseException( Messages.getInstance().getErrorString( "CommandLineProcessor.ERROR_0001_MISSING_ARG", option ) ); } return StringUtils.removeStart( value, "=" ); } protected  CommandLineProcessor( String[] args ); static void main( String[] args ); static Exception getException(); @Override void close(); synchronized void setRepository( final IUnifiedRepository repository ); static String getErrorMessage();  }
@Test public void get004GetOptionValueTest() throws ParseException { depensOnConstructor(); String requestType = getOption( "-", "i" ); String shortOption = getOption( "u" ); String longOption = getOption( "username" ); try ( CommandLineProcessor clp = new CommandLineProcessor( new String[] { requestType, "-" + shortOption + "=value" } ) ) { assertEquals( "value", clp.getOptionValue( shortOption, false, true ) ); assertEquals( "value", clp.getOptionValue( longOption, false, true ) ); assertNull( clp.getOptionValue( "wrongKey", false, true ) ); try { assertNull( clp.getOptionValue( "wrongKey", true, true ) ); fail(); } catch ( ParseException e ) { } try { assertNull( clp.getOptionValue( "wrongKey", false, false ) ); fail(); } catch ( ParseException e ) { } assertEquals( "value", clp.getOptionValue( longOption, false, true ) ); assertNull( clp.getOptionValue( "wrongKey", false, true ) ); try { assertNull( clp.getOptionValue( "wrongKey", true, true ) ); fail(); } catch ( ParseException e ) { } try { assertNull( clp.getOptionValue( "wrongKey", false, false ) ); fail(); } catch ( ParseException e ) { } } catch ( IOException e ) { e.printStackTrace(); } }