Program: 126873
Project: 126873
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.Catalog,java.lang.String,boolean)}.
 */
@Test public void testGetTablesConnectionCatalogStringBoolean(){
  java.sql.Connection sqlConn=null;
  DatabaseMetaData metaData=null;
  String catalogName="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);
    Mockito.when(catalog.getName()).thenReturn(catalogName);
    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(catalog)).thenReturn(tableList);
    MetadataFillFactory metadataMock=Mockito.mock(MetadataFillFactory.class);
    Mockito.when(metadataMock.fillTables((orgomg.cwm.objectmodel.core.Package)Mockito.eq(catalog),Mockito.eq(metaData),Mockito.anyList(),Mockito.eq(tablePattern),(String[])Mockito.any())).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(CatalogHelper.class);
    Mockito.when(CatalogHelper.getTables(catalog)).thenReturn(retableList);
    resultList1=DqRepositoryViewService.getTables(dataProvider,catalog,tablePattern,loadFromDB);
    tableList.add(tableMock);
    resultList2=DqRepositoryViewService.getTables(dataProvider,catalog,tablePattern,loadFromDB);
    loadFromDB=false;
    resultList3=DqRepositoryViewService.getTables(dataProvider,catalog,tablePattern,loadFromDB);
    Mockito.verify(catalog,Mockito.times(2)).getName();
    Mockito.verify(metadataMock,Mockito.times(2)).fillTables((orgomg.cwm.objectmodel.core.Package)Mockito.eq(catalog),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,catalog,sqlConn,metaData,metadataMock);
    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.Catalog,java.lang.String,boolean)}.
 */
@Test public void testGetTablesConnectionCatalogStringBoolean(){
  java.sql.Connection sqlConn=null;
  DatabaseMetaData metaData=null;
  String catalogName="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);
    Mockito.when(catalog.getName()).thenReturn(catalogName);
    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(catalog)).thenReturn(tableList);
    MetadataFillFactory metadataMock=Mockito.mock(MetadataFillFactory.class);
    Mockito.when(metadataMock.fillTables((orgomg.cwm.objectmodel.core.Package)Mockito.eq(catalog),Mockito.eq(metaData),Mockito.anyList(),Mockito.eq(tablePattern),(String[])Mockito.any())).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(CatalogHelper.class);
    Mockito.when(CatalogHelper.getTables(catalog)).thenReturn(retableList);
    resultList1=DqRepositoryViewService.getTables(dataProvider,catalog,tablePattern,loadFromDB);
    tableList.add(tableMock);
    resultList2=DqRepositoryViewService.getTables(dataProvider,catalog,tablePattern,loadFromDB);
    loadFromDB=false;
    resultList3=DqRepositoryViewService.getTables(dataProvider,catalog,tablePattern,loadFromDB);
    Mockito.verify(catalog,Mockito.times(2)).getName();
    Mockito.verify(metadataMock,Mockito.times(2)).fillTables((orgomg.cwm.objectmodel.core.Package)Mockito.eq(catalog),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,catalog,sqlConn,metaData,metadataMock);
    assertTrue(resultList1.size() == 1);
    assertTrue(resultList2.size() == 1);
    assertTrue(resultList3.size() == 1);
  }
 catch (  Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
}