public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
    VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
    int nrFields = fieldInStream == null ? 0 : fieldInStream.length;
    for ( int i = 0; i < nrFields; i++ ) {
      String fieldName = space.environmentSubstitute( fieldOutStream[i] );
      ValueMetaInterface valueMeta;
      if ( !Utils.isEmpty( fieldOutStream[i] ) ) {
        // We have a new field
        valueMeta = new ValueMetaString( fieldName );
        valueMeta.setOrigin( name );
        //set encoding to new field from source field http://jira.pentaho.com/browse/PDI-11839
        ValueMetaInterface sourceField = inputRowMeta.searchValueMeta( fieldInStream[i] );
        if ( sourceField != null ) {
          valueMeta.setStringEncoding( sourceField.getStringEncoding() );
        }
        inputRowMeta.addValueMeta( valueMeta );
      } else {
        valueMeta = inputRowMeta.searchValueMeta( fieldInStream[i] );
        if ( valueMeta == null ) {
          continue;
        }
        valueMeta.setStorageType( ValueMetaInterface.STORAGE_TYPE_NORMAL );
      }
    }
  }
@Test
  public void testGetFields() throws KettleStepException {
    ReplaceStringMeta meta = new ReplaceStringMeta();
    meta.setFieldInStream( new String[] { FIELD_NAME } );
    meta.setFieldOutStream( new String[] { FIELD_NAME } );

    ValueMetaInterface inputFieldMeta = mock( ValueMetaInterface.class );
    when( inputFieldMeta.getStringEncoding() ).thenReturn( ENCODING_NAME );

    RowMetaInterface inputRowMeta = mock( RowMetaInterface.class );
    when( inputRowMeta.searchValueMeta( anyString() ) ).thenReturn( inputFieldMeta );

    StepMeta nextStep = mock( StepMeta.class );
    VariableSpace space = mock( VariableSpace.class );
    Repository repository = mock( Repository.class );
    IMetaStore metaStore = mock( IMetaStore.class );
    meta.getFields( inputRowMeta, "test", null, nextStep, space, repository, metaStore );

    ArgumentCaptor<ValueMetaInterface> argument = ArgumentCaptor.forClass( ValueMetaInterface.class );
    verify( inputRowMeta ).addValueMeta( argument.capture() );
    assertEquals( ENCODING_NAME, argument.getValue().getStringEncoding() );
  }