### Question:
TableOutputStepAnalyzer extends ConnectionExternalResourceStepAnalyzer<TableOutputMeta> { @Override public Set<String> getOutputResourceFields( TableOutputMeta meta ) { String[] fieldArray = meta.getFieldDatabase(); if ( ArrayUtils.isEmpty( fieldArray ) || !meta.specifyFields() ) { fieldArray = getOutputFields( meta ).getFieldNames(); } Set<String> fields = new LinkedHashSet<>( Arrays.asList( fieldArray ) ); return fields; }  @Override Set<String> getOutputResourceFields( TableOutputMeta meta ); @Override Set<ComponentDerivationRecord> getChangeRecords( TableOutputMeta meta ); @Override IMetaverseNode getConnectionNode(); @Override Set<Class<? extends BaseStepMeta>> getSupportedSteps(); @Override String getResourceInputNodeType(); @Override String getResourceOutputNodeType(); @Override boolean isOutput(); @Override boolean isInput(); static final String TRUNCATE_TABLE; }### Answer:
@Test public void testGetOutputResourceFieldsRenamed() throws Exception { String[] tableFields = new String[] { "foo", "foe", "fee" }; when( meta.getFieldDatabase() ).thenReturn( tableFields ); String[] streamFields = new String[] { "field2", "field3", "bogus" }; when( meta.getFieldStream() ).thenReturn( streamFields ); RowMetaInterface rmi = Mockito.mock( RowMetaInterface.class ); String[] outputFields = new String[2]; outputFields[0] = "field2"; outputFields[1] = "field3"; doReturn( rmi ).when( analyzer ).getOutputFields( meta ); when( rmi.getFieldNames() ).thenReturn( outputFields ); when( meta.specifyFields() ).thenReturn( Boolean.FALSE ); Set<String> outputResourceFields = analyzer.getOutputResourceFields( meta ); assertEquals( outputFields.length, outputResourceFields.size() ); for ( String outputField : outputFields ) { assertTrue( outputResourceFields.contains( outputField ) ); } when( meta.specifyFields() ).thenReturn( Boolean.TRUE ); outputResourceFields = analyzer.getOutputResourceFields( meta ); assertEquals( tableFields.length, outputResourceFields.size() ); for ( String tableField : tableFields ) { assertTrue( outputResourceFields.contains( tableField ) ); } }
@Test public void testGetOutputResourceFields() throws Exception { String[] tableFields = new String[3]; tableFields[0] = "field1"; tableFields[1] = "field2"; tableFields[2] = "field3"; when( meta.getFieldDatabase() ).thenReturn( tableFields ); RowMetaInterface rmi = Mockito.mock( RowMetaInterface.class ); String[] outputFields = new String[2]; outputFields[0] = "out-field1"; outputFields[1] = "out-field2"; doReturn( rmi ).when( analyzer ).getOutputFields( meta ); when( rmi.getFieldNames() ).thenReturn( outputFields ); Set<String> outputResourceFields = analyzer.getOutputResourceFields( meta ); assertEquals( outputFields.length, outputResourceFields.size() ); for ( String outputField : outputFields ) { assertTrue( outputResourceFields.contains( outputField ) ); } when( meta.specifyFields() ).thenReturn( Boolean.TRUE ); outputResourceFields = analyzer.getOutputResourceFields( meta ); assertEquals( tableFields.length, outputResourceFields.size() ); for ( String tableField : tableFields ) { assertTrue( outputResourceFields.contains( tableField ) ); } }