public static final String[] getVariableNames( VariableSpace space ) {
    String[] variableNames = space.listVariables();
    for ( int i = 0; i < variableNames.length; i++ ) {
      for ( int j = 0; j < Const.DEPRECATED_VARIABLES.length; j++ ) {
        if ( variableNames[i].equals( Const.DEPRECATED_VARIABLES[j] ) ) {
          variableNames[i] = variableNames[i] + Const.getDeprecatedPrefix();
          break;
        }
      }
    }

    Arrays.sort( variableNames, new Comparator<String>() {
      public int compare( String var1, String var2 ) {
        if ( var1.endsWith( Const.getDeprecatedPrefix() ) && var2.endsWith( Const.getDeprecatedPrefix() ) ) {
          return 0;
        }
        if ( var1.endsWith( Const.getDeprecatedPrefix() ) && !var2.endsWith( Const.getDeprecatedPrefix() ) ) {
          return 1;
        }
        if ( !var1.endsWith( Const.getDeprecatedPrefix() ) && var2.endsWith( Const.getDeprecatedPrefix() ) ) {
          return -1;
        }
        return var1.compareTo( var2 );
      }
    } );
    return variableNames;
  }
@Test
  public void testGetVariableNames() {
    Assert.assertTrue( Const.DEPRECATED_VARIABLES.length > 0 );

    String deprecatedVariableName = Const.DEPRECATED_VARIABLES[0];
    String deprecatedPrefix = Const.getDeprecatedPrefix();
    String[] variableNames = new String[] { "test_variable1", "test_variable2", deprecatedVariableName };
    String[] expectedVariables = new String[] { "test_variable1", "test_variable2", deprecatedVariableName + deprecatedPrefix };

    VariableSpace variableSpace = mock( VariableSpace.class );

    doReturn( variableNames ).when( variableSpace ).listVariables();

    Assert.assertArrayEquals( expectedVariables, ControlSpaceKeyAdapter.getVariableNames( variableSpace ) );
  }