### Question:
CleanArgument { public static String[] cleanArgs( String[] args ) { List<String> cleaned = new ArrayList<>(); StringBuilder currentArg = null; for ( String arg : args ) { boolean addedToBuffer = false; if ( arg.startsWith( "\"" ) ) { if ( currentArg != null ) { cleaned.add( currentArg.toString() ); } currentArg = new StringBuilder( arg.substring( 1 ) ); addedToBuffer = true; } if ( addedToBuffer && arg.endsWith( "\"" ) ) { String cleanArgPart = arg.substring( 0, arg.length() - 1 ); if ( currentArg != null ) { if ( addedToBuffer ) { currentArg.setLength( currentArg.length() - 1 ); } else { currentArg.append( ' ' ).append( cleanArgPart ); } cleaned.add( currentArg.toString() ); } else { cleaned.add( cleanArgPart ); } currentArg = null; addedToBuffer = false; continue; } if ( !addedToBuffer ) { if ( currentArg != null ) { currentArg.append( ' ' ).append( arg ); } else { cleaned.add( arg ); } } } if ( currentArg != null ) { cleaned.add( currentArg.toString() ); } int cleanedSz = cleaned.size(); String[] cleanArgs; if ( cleanedSz == 0 ) { cleanArgs = args; } else { cleanArgs = cleaned.toArray( new String[0] ); } return cleanArgs; }  static String[] cleanArgs( String[] args );  }### Answer:
@Test public void cleanArgsShouldRemoveWrongSurroundingQuotes() { String[] args = { "\"-Dfoo=bar", "\"-Dfoo2=bar two\"" }; String[] cleanArgs = CleanArgument.cleanArgs( args ); assertEquals( args.length, cleanArgs.length ); assertEquals( "-Dfoo=bar", cleanArgs[0] ); assertEquals( "-Dfoo2=bar two", cleanArgs[1] ); }
@Test public void testCleanArgsShouldNotTouchCorrectlyQuotedArgumentsUsingDoubleQuotes() { String information = "-Dinformation=\"The Information is important.\""; String[] args = { information }; String[] cleanArgs = CleanArgument.cleanArgs( args ); assertEquals( args.length, cleanArgs.length ); assertEquals( information, cleanArgs[0] ); }
@Test public void testCleanArgsShouldNotTouchCorrectlyQuotedArgumentsUsingSingleQuotes() { String information = "-Dinformation='The Information is important.'"; String[] args = { information }; String[] cleanArgs = CleanArgument.cleanArgs( args ); assertEquals( args.length, cleanArgs.length ); assertEquals( information, cleanArgs[0] ); }