@Override
  public void initializeVariablesFrom( VariableSpace parent ) {
    // only read these once. Don't overwrite values that have already been set on this variable space from other APIs
    if ( !initialized ) {
      // Clone the system properties to avoid ConcurrentModificationException while iterating
      // and then add all of them to properties variable.
      Set<String> systemPropertiesNames = System.getProperties().stringPropertyNames();
      for ( String key : systemPropertiesNames ) {
        String value = System.getProperties().getProperty( key );
        if ( value != null ) {
          getProperties().put( key, value );
        }
      }
    }

    if ( parent != null ) {
      this.parent = parent;
      copyVariablesFrom( parent );
    }
    if ( injection != null ) {
      properties.putAll( injection );
      injection = null;
    }
    initialized = true;
  }
@Test
  public void testInitializeVariablesFrom() {
    final Variables variablesMock = mock( Variables.class );
    doCallRealMethod().when( variablesMock ).initializeVariablesFrom( eq( null ) );

    @SuppressWarnings( "unchecked" )
    final Map<String, String> propertiesMock = mock( Map.class );
    when( variablesMock.getProperties() ).thenReturn( propertiesMock );

    doAnswer( new Answer<Map<String, String>>() {
      final String keyStub = "key";

      @Override
      public Map<String, String> answer( InvocationOnMock invocation ) throws Throwable {
        if ( System.getProperty( keyStub ) == null ) {
          modifySystemproperties();
        }

        if ( invocation.getArguments()[ 1 ] != null ) {
          propertiesMock.put( (String) invocation.getArguments()[ 0 ], System.getProperties().getProperty(
            (String) invocation.getArguments()[ 1 ] ) );
        }
        return propertiesMock;
      }
    } ).when( propertiesMock ).put( anyString(), anyString() );

    variablesMock.initializeVariablesFrom( null );
    int expectedNumOfProperties = System.getProperties().size() - 1;
    verify( variablesMock, times( expectedNumOfProperties ) ).getProperties();
    verify( propertiesMock, times( expectedNumOfProperties ) ).put( anyString(), anyString() );
  }