public void prepareFieldNamesParameters( String[] parameters, String[] parameterFieldNames, String[] parameterValues,
                                                    NamedParams namedParam, JobEntryTrans jobEntryTrans )
    throws UnknownParamException {
    for ( int idx = 0; idx < parameters.length; idx++ ) {
      // Grab the parameter value set in the Trans job entry
      // Set fieldNameParameter only if exists and if it is not declared any staticValue( parameterValues array )
      //
      String thisValue = namedParam.getParameterValue( parameters[ idx ] );
      // multiple executions on the same jobEntryTrans variableSpace need to be updated even for nulls or blank values.
      // so we have to ask if that same variable had a value before and if it had - and the new value is empty -
      // we should set it as a blank value instead of ignoring it.
      // NOTE: we should only replace it if we have a parameterFieldNames defined -> parameterFieldNames[ idx ] ) != null
      if ( !Utils.isEmpty( jobEntryTrans.getVariable( parameters[ idx ] ) ) && Utils.isEmpty( thisValue )
        && idx < parameterFieldNames.length && !Utils.isEmpty( Const.trim( parameterFieldNames[ idx ] ) ) ) {
        jobEntryTrans.setVariable( parameters[ idx ], "" );
      }
      // Set value only if is not empty at namedParam and exists in parameterFieldNames
      if ( !Utils.isEmpty( thisValue ) && idx < parameterFieldNames.length ) {
        // If exists then ask if is not empty
        if ( !Utils.isEmpty( Const.trim( parameterFieldNames[ idx ] ) ) ) {
          // If is not empty then we have to ask if it exists too in parameterValues array, since the values in
          // parameterValues prevail over parameterFieldNames
          if ( idx < parameterValues.length ) {
            // If is empty at parameterValues array, then we can finally add that variable with that value
            if ( Utils.isEmpty( Const.trim( parameterValues[ idx ] ) ) ) {
              jobEntryTrans.setVariable( parameters[ idx ], thisValue );
            }
          } else {
            // Or if not in parameterValues then we can add that variable with that value too
            jobEntryTrans.setVariable( parameters[ idx ], thisValue );
          }
        }
      }
    }
  }
@Test
  public void testPrepareFieldNamesParameters() throws UnknownParamException {
    // array of params
    String[] parameterNames = new String[2];
    parameterNames[0] = "param1";
    parameterNames[1] = "param2";

    // array of fieldNames params
    String[] parameterFieldNames = new String[1];
    parameterFieldNames[0] = "StreamParam1";

    // array of parameterValues params
    String[] parameterValues = new String[2];
    parameterValues[1] = "ValueParam2";


    JobEntryTrans jet = new JobEntryTrans();
    VariableSpace variableSpace = new Variables();
    jet.copyVariablesFrom( variableSpace );

    //at this point StreamColumnNameParams are already inserted in namedParams
    NamedParams namedParam = Mockito.mock( NamedParamsDefault.class );
    Mockito.doReturn( "value1" ).when( namedParam ).getParameterValue(  "param1" );
    Mockito.doReturn( "value2" ).when( namedParam ).getParameterValue(  "param2" );

    jet.prepareFieldNamesParameters( parameterNames, parameterFieldNames, parameterValues, namedParam, jet );

    Assert.assertEquals( "value1", jet.getVariable( "param1" ) );
    Assert.assertEquals( null, jet.getVariable( "param2" ) );
  }