### Question:
InputConversionEngine { protected final List<Token> orderTokens(List<Token> tokens, ShellCommandParamSpec[] specs) { if(!Token.isCustomizedParamOrder(tokens)){ return tokens; } Token[] newOrder = new Token[tokens.size()]; newOrder[0] = tokens.get(0); List<Token> varArgs = new ArrayList<Token>(); for(int i=1; i < tokens.size(); i += 2){ final String paramName = tokens.get(i).getString().substring(2); boolean found = false; for(int j=0; j < specs.length; j++){ ShellCommandParamSpec currentSpec = specs[j]; if(paramName.equals(currentSpec.getName())){ if(currentSpec.isVarArgs()){ varArgs.add(tokens.get(i + 1)); }else{ newOrder[j + 1] = tokens.get(i + 1); } found = true; break; } } if(!found){ return tokens; } } List<Token> result = new ArrayList<Token>(Arrays.asList(newOrder)); result.addAll(varArgs); Iterator<Token> iter = result.iterator(); while(iter.hasNext()){ if(iter.next() == null){ iter.remove(); } } return result; }  void addConverter(InputConverter converter); boolean removeConverter(InputConverter converter); Object convertInput(String string, Class aClass); final Object[] convertToParameters(List<Token> tokens, ShellCommandParamSpec[] specs, Class[] paramClasses, boolean isVarArgs); void addDeclaredConverters(Object handler);  }### Answer:
@Test public void orderTokens(){ InputConversionEngine engine = new InputConversionEngine(); ShellCommandParamSpec[] specs = new ShellCommandParamSpec[]{ new ShellCommandParamSpec("arg1", null, null, 1, null, false), new ShellCommandParamSpec("arg2", null, null, 2, null, false), new ShellCommandParamSpec("varArg", null, null, 3, null, true) }; List<Token> tokens = Arrays.asList( new Token(0, "cmd"), new Token(1, "--arg2"), new Token(2, "arg2Value"), new Token(3, "--varArg"), new Token(4, "varArg1"), new Token(5, "--arg1"), new Token(6, "arg1Value"), new Token(7, "--varArg"), new Token(8, "varArg2"), new Token(9, "--varArg"), new Token(10, "varArg3") ); List<Token> result = engine.orderTokens(tokens, specs); assertEquals(6, result.size()); assertSame(result.get(0), tokens.get(0)); assertSame(result.get(1), tokens.get(6)); assertSame(result.get(2), tokens.get(2)); assertSame(result.get(3), tokens.get(4)); assertSame(result.get(4), tokens.get(8)); assertSame(result.get(5), tokens.get(10)); }