### Question:
TableInputExternalResourceConsumer extends BaseStepExternalResourceConsumer<TableInput, TableInputMeta> { @Override public Collection<IExternalResourceInfo> getResourcesFromMeta( TableInputMeta meta, IAnalysisContext context ) { Set<IExternalResourceInfo> resources = new HashSet<IExternalResourceInfo>(); DatabaseMeta dbMeta = meta.getDatabaseMeta(); if ( dbMeta != null ) { IExternalResourceInfo databaseResource = ExternalResourceInfoFactory.createDatabaseResource( dbMeta, true ); String query = context.equals( DictionaryConst.CONTEXT_RUNTIME ) ? meta.getParentStepMeta().getParentTransMeta().environmentSubstitute( meta.getSQL() ) : meta.getSQL(); databaseResource.getAttributes().put( DictionaryConst.PROPERTY_QUERY, query ); resources.add( databaseResource ); } return resources; }  @Override Class<TableInputMeta> getMetaClass(); @Override Collection<IExternalResourceInfo> getResourcesFromMeta( TableInputMeta meta, IAnalysisContext context );  }### Answer:
@Test public void testGetResourcesFromMeta() throws Exception { when( meta.getSQL() ).thenReturn( "select * from table" ); when( meta.getDatabaseMeta() ).thenReturn( dbMeta ); Collection<IExternalResourceInfo> resourceInfos = consumer.getResourcesFromMeta( meta, context ); assertNotNull( resourceInfos ); assertEquals( 1, resourceInfos.size() ); IExternalResourceInfo info = resourceInfos.iterator().next(); assertEquals( "select * from table", info.getAttributes().get( DictionaryConst.PROPERTY_QUERY ) ); }
@Test public void testGetResourcesFromMeta_nullDbMeta() throws Exception { when( meta.getDatabaseMeta() ).thenReturn( null ); Collection<IExternalResourceInfo> resourceInfos = consumer.getResourcesFromMeta( meta, context ); assertNotNull( resourceInfos ); assertEquals( 0, resourceInfos.size() ); }