Program: 126875
Project: 126875
Buggy source:
/** 
 * Test method for  {@link org.talend.core.model.metadata.builder.database.DqRepositoryViewService#getTables(org.talend.core.model.metadata.builder.connection.Connection,orgomg.cwm.resource.relational.Schema,java.lang.String,boolean)}.
 */
@Test public void testGetTablesConnectionSchemaStringBoolean(){
  java.sql.Connection sqlConn=null;
  DatabaseMetaData metaData=null;
  String schemaName="String_Node_Str";
  List<TdTable> tableList=new ArrayList<TdTable>();
  List<TdTable> retableList=new ArrayList<TdTable>();
  List<TdTable> resultList1=null;
  List<TdTable> resultList2=null;
  List<TdTable> resultList3=null;
  String tablePattern=null;
  boolean loadFromDB=true;
  TdTable tableMock=Mockito.mock(TdTable.class);
  retableList.add(tableMock);
  ResultSet tables=Mockito.mock(ResultSet.class);
  try {
    Connection dataProvider=Mockito.mock(DatabaseConnection.class);
    Catalog catalog=Mockito.mock(Catalog.class);
    Schema schema=Mockito.mock(Schema.class);
    TypedReturnCode<java.sql.Connection> reConn=new TypedReturnCode<java.sql.Connection>();
    sqlConn=Mockito.mock(java.sql.Connection.class);
    reConn.setOk(true);
    reConn.setObject(sqlConn);
    ReturnCode rc=new ReturnCode(true);
    metaData=Mockito.mock(DatabaseMetaData.class);
    PowerMockito.mockStatic(MetadataConnectionUtils.class);
    Mockito.when(MetadataConnectionUtils.checkConnection((DatabaseConnection)dataProvider)).thenReturn(reConn);
    PowerMockito.mockStatic(ExtractMetaDataUtils.class);
    ExtractMetaDataUtils extract=Mockito.mock(ExtractMetaDataUtils.class);
    Mockito.when(ExtractMetaDataUtils.getInstance()).thenReturn(extract);
    Mockito.when(extract.getDatabaseMetaData(sqlConn,(DatabaseConnection)dataProvider,false)).thenReturn(metaData);
    PowerMockito.mockStatic(PackageHelper.class);
    Mockito.when(PackageHelper.getTables(schema)).thenReturn(tableList);
    MetadataFillFactory metadataMock=Mockito.mock(MetadataFillFactory.class);
    Mockito.when(metadataMock.fillTables((orgomg.cwm.objectmodel.core.Package)Mockito.eq(schema),Mockito.eq(metaData),Mockito.anyList(),Mockito.eq(tablePattern),(String[])Mockito.any())).thenReturn(retableList).thenReturn(retableList);
    PowerMockito.mockStatic(MetadataFillFactory.class);
    Mockito.when(MetadataFillFactory.getDBInstance()).thenReturn(metadataMock);
    PowerMockito.mockStatic(ConnectionUtils.class);
    Mockito.when(ConnectionUtils.closeConnection(sqlConn)).thenReturn(rc);
    PowerMockito.mockStatic(SchemaHelper.class);
    Mockito.when(SchemaHelper.getTables(schema)).thenReturn(retableList);
    PowerMockito.mockStatic(CatalogHelper.class);
    Mockito.when(CatalogHelper.getParentCatalog(schema)).thenReturn(catalog);
    resultList1=DqRepositoryViewService.getTables(dataProvider,schema,tablePattern,loadFromDB);
    tableList.add(tableMock);
    resultList2=DqRepositoryViewService.getTables(dataProvider,schema,tablePattern,loadFromDB);
    loadFromDB=false;
    resultList3=DqRepositoryViewService.getTables(dataProvider,schema,tablePattern,loadFromDB);
    Mockito.verify(metadataMock,Mockito.times(2)).fillTables((orgomg.cwm.objectmodel.core.Package)Mockito.eq(schema),Mockito.eq(metaData),Mockito.anyList(),Mockito.eq(tablePattern),(String[])Mockito.any());
    Mockito.verify(metadataMock).setLinked(true);
    Mockito.verify(metadataMock).setLinked(false);
    Mockito.verifyZeroInteractions(tableMock,tables,dataProvider,schema,sqlConn,metaData,metadataMock,catalog);
    assertTrue(resultList1.size() == 1);
    assertTrue(resultList2.size() == 1);
    assertTrue(resultList3.size() == 1);
  }
 catch (  Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
}

Fixed version (ground truth):
/** 
 * Test method for  {@link org.talend.core.model.metadata.builder.database.DqRepositoryViewService#getTables(org.talend.core.model.metadata.builder.connection.Connection,orgomg.cwm.resource.relational.Schema,java.lang.String,boolean)}.
 */
@Test public void testGetTablesConnectionSchemaStringBoolean(){
  java.sql.Connection sqlConn=null;
  DatabaseMetaData metaData=null;
  String schemaName="String_Node_Str";
  List<TdTable> tableList=new ArrayList<TdTable>();
  List<TdTable> retableList=new ArrayList<TdTable>();
  List<TdTable> resultList1=null;
  List<TdTable> resultList2=null;
  List<TdTable> resultList3=null;
  String tablePattern=null;
  boolean loadFromDB=true;
  TdTable tableMock=Mockito.mock(TdTable.class);
  retableList.add(tableMock);
  ResultSet tables=Mockito.mock(ResultSet.class);
  try {
    Connection dataProvider=Mockito.mock(DatabaseConnection.class);
    Catalog catalog=Mockito.mock(Catalog.class);
    Schema schema=Mockito.mock(Schema.class);
    TypedReturnCode<java.sql.Connection> reConn=new TypedReturnCode<java.sql.Connection>();
    sqlConn=Mockito.mock(java.sql.Connection.class);
    reConn.setOk(true);
    reConn.setObject(sqlConn);
    ReturnCode rc=new ReturnCode(true);
    metaData=Mockito.mock(DatabaseMetaData.class);
    PowerMockito.mockStatic(MetadataConnectionUtils.class);
    Mockito.when(MetadataConnectionUtils.createConnection((DatabaseConnection)dataProvider)).thenReturn(reConn);
    PowerMockito.mockStatic(ExtractMetaDataUtils.class);
    ExtractMetaDataUtils extract=Mockito.mock(ExtractMetaDataUtils.class);
    Mockito.when(ExtractMetaDataUtils.getInstance()).thenReturn(extract);
    Mockito.when(extract.getDatabaseMetaData(sqlConn,(DatabaseConnection)dataProvider,false)).thenReturn(metaData);
    PowerMockito.mockStatic(PackageHelper.class);
    Mockito.when(PackageHelper.getTables(schema)).thenReturn(tableList);
    MetadataFillFactory metadataMock=Mockito.mock(MetadataFillFactory.class);
    Mockito.when(metadataMock.fillTables((orgomg.cwm.objectmodel.core.Package)Mockito.eq(schema),Mockito.eq(metaData),Mockito.anyList(),Mockito.eq(tablePattern),(String[])Mockito.any())).thenReturn(retableList).thenReturn(retableList);
    PowerMockito.mockStatic(MetadataFillFactory.class);
    Mockito.when(MetadataFillFactory.getDBInstance()).thenReturn(metadataMock);
    PowerMockito.mockStatic(ConnectionUtils.class);
    Mockito.when(ConnectionUtils.closeConnection(sqlConn)).thenReturn(rc);
    PowerMockito.mockStatic(SchemaHelper.class);
    Mockito.when(SchemaHelper.getTables(schema)).thenReturn(retableList);
    PowerMockito.mockStatic(CatalogHelper.class);
    Mockito.when(CatalogHelper.getParentCatalog(schema)).thenReturn(catalog);
    resultList1=DqRepositoryViewService.getTables(dataProvider,schema,tablePattern,loadFromDB);
    tableList.add(tableMock);
    resultList2=DqRepositoryViewService.getTables(dataProvider,schema,tablePattern,loadFromDB);
    loadFromDB=false;
    resultList3=DqRepositoryViewService.getTables(dataProvider,schema,tablePattern,loadFromDB);
    Mockito.verify(metadataMock,Mockito.times(2)).fillTables((orgomg.cwm.objectmodel.core.Package)Mockito.eq(schema),Mockito.eq(metaData),Mockito.anyList(),Mockito.eq(tablePattern),(String[])Mockito.any());
    Mockito.verify(metadataMock).setLinked(true);
    Mockito.verify(metadataMock).setLinked(false);
    Mockito.verifyZeroInteractions(tableMock,tables,dataProvider,schema,sqlConn,metaData,metadataMock,catalog);
    assertTrue(resultList1.size() == 1);
    assertTrue(resultList2.size() == 1);
    assertTrue(resultList3.size() == 1);
  }
 catch (  Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
}