Program: 137581
Project: 137581
Buggy source:
@Test public void testGetRefreshedDataProvider() throws SQLException {
  DatabaseConnection dbProvider=ConnectionFactory.eINSTANCE.createDatabaseConnection();
  setJDBCMysqlConnection(dbProvider);
  List<Catalog> catalogPackageFilter=new ArrayList<Catalog>();
  List<orgomg.cwm.objectmodel.core.Package> schemaPackageFilter=new ArrayList<orgomg.cwm.objectmodel.core.Package>();
  TypedReturnCode<java.sql.Connection> returnCode=new TypedReturnCode<java.sql.Connection>(true);
  java.sql.Connection mockSqlConn=Mockito.mock(java.sql.Connection.class);
  returnCode.setObject(mockSqlConn);
  DatabaseMetaData mockDatabaseMetaData=Mockito.mock(DatabaseMetaData.class);
  Mockito.when(mockDatabaseMetaData.supportsCatalogsInIndexDefinitions()).thenReturn(true);
  List<String> catalogNames=new ArrayList<String>();
  List<String> packageFilter=MetadataConnectionUtils.getPackageFilter(dbProvider,mockDatabaseMetaData,true);
  boolean haveFilter=false;
  if (packageFilter.size() > 0) {
    catalogNames.addAll(packageFilter);
    haveFilter=true;
  }
 else {
    catalogNames.add("String_Node_Str");
    catalogNames.add("String_Node_Str");
    catalogNames.add("String_Node_Str");
  }
  ResultSet mockCatalogResults=Mockito.mock(ResultSet.class);
  if (haveFilter) {
    Mockito.when(mockCatalogResults.next()).thenReturn(true,false);
  }
 else {
    Mockito.when(mockCatalogResults.next()).thenReturn(true,true,true,false);
  }
  Mockito.when(mockCatalogResults.getString(MetaDataConstants.TABLE_CAT.name())).thenReturn("String_Node_Str","String_Node_Str","String_Node_Str");
  ResultSet mockSchemaResults=Mockito.mock(ResultSet.class);
  Mockito.when(mockSchemaResults.next()).thenReturn(false);
  Mockito.when(mockDatabaseMetaData.getDatabaseProductName()).thenReturn(EDatabaseTypeName.MYSQL.getProduct());
  Mockito.when(mockDatabaseMetaData.getCatalogs()).thenReturn(mockCatalogResults);
  Mockito.when(mockDatabaseMetaData.getDriverName()).thenReturn("String_Node_Str");
  Mockito.when(mockDatabaseMetaData.getSchemas()).thenReturn(mockSchemaResults);
  CoreRuntimePlugin instanceMock=Mockito.mock(CoreRuntimePlugin.class);
  PowerMockito.mockStatic(CoreRuntimePlugin.class);
  Mockito.when(CoreRuntimePlugin.getInstance()).thenReturn(instanceMock);
  Mockito.when(instanceMock.getRepositoryService()).thenReturn(null);
  PowerMockito.mock(ExtractMetaDataUtils.class);
  Mockito.when(ExtractMetaDataUtils.getInstance().getConnectionMetadata(mockSqlConn)).thenReturn(mockDatabaseMetaData);
  PowerMockito.mockStatic(ConnectionHelper.class);
  Set<MetadataTable> result=new HashSet<MetadataTable>();
  Mockito.when(ConnectionHelper.getTables(dbProvider)).thenReturn(result);
  Mockito.when(ConnectionHelper.addCatalogs((Collection<Catalog>)Mockito.any(),(Connection)Mockito.any())).thenCallRealMethod();
  Mockito.when(ConnectionHelper.addPackages((Collection<Catalog>)Mockito.any(),(Connection)Mockito.any())).thenCallRealMethod();
  MetadataFillFactory mockMetadataFillFactory=Mockito.mock(MetadataFillFactory.class);
  PowerMockito.mockStatic(MetadataFillFactory.class);
  Mockito.when(MetadataFillFactory.getDBInstance()).thenReturn(mockMetadataFillFactory);
  Mockito.when(MetadataFillFactory.getDBInstance()).thenReturn(mockMetadataFillFactory);
  Mockito.when(MetadataFillFactory.getDBInstance()).thenCallRealMethod();
  Mockito.when(MetadataFillFactory.getDBInstance()).thenReturn(mockMetadataFillFactory);
  Mockito.when(mockMetadataFillFactory.createConnection((IMetadataConnection)Mockito.any())).thenReturn(returnCode);
  Mockito.when(mockMetadataFillFactory.fillUIConnParams((IMetadataConnection)Mockito.any(),(Connection)Mockito.isNull())).thenReturn(dbProvider);
  Mockito.when(mockMetadataFillFactory.fillCatalogs((Connection)Mockito.any(),(DatabaseMetaData)Mockito.any(),Mockito.anyList())).thenCallRealMethod();
  Mockito.when(mockMetadataFillFactory.fillSchemas((Connection)Mockito.any(),(DatabaseMetaData)Mockito.any(),Mockito.anyList())).thenReturn(schemaPackageFilter);
  List<Schema> schemaList=new ArrayList<Schema>();
  Mockito.when(mockMetadataFillFactory.fillSchemaToCatalog((Connection)Mockito.any(),(DatabaseMetaData)Mockito.any(),(Catalog)Mockito.any(),(List<String>)Mockito.any())).thenReturn(schemaList);
  DQStructureComparer.getRefreshedDataProvider(dbProvider);
  List<Catalog> catalogs=CatalogHelper.getCatalogs(dbProvider.getDataPackage());
  assertTrue(catalogs.size() == catalogNames.size());
  for (int index=0; index < catalogNames.size(); index++) {
    assertTrue(catalogNames.get(index).equalsIgnoreCase(catalogs.get(index).getName()));
  }
}

Fixed version (ground truth):
@Test public void testGetRefreshedDataProvider() throws SQLException {
  DatabaseConnection dbProvider=ConnectionFactory.eINSTANCE.createDatabaseConnection();
  setJDBCMysqlConnection(dbProvider);
  List<Catalog> catalogPackageFilter=new ArrayList<Catalog>();
  List<orgomg.cwm.objectmodel.core.Package> schemaPackageFilter=new ArrayList<orgomg.cwm.objectmodel.core.Package>();
  TypedReturnCode<java.sql.Connection> returnCode=new TypedReturnCode<java.sql.Connection>(true);
  java.sql.Connection mockSqlConn=Mockito.mock(java.sql.Connection.class);
  returnCode.setObject(mockSqlConn);
  DatabaseMetaData mockDatabaseMetaData=Mockito.mock(DatabaseMetaData.class);
  Mockito.when(mockDatabaseMetaData.supportsCatalogsInIndexDefinitions()).thenReturn(true);
  List<String> catalogNames=new ArrayList<String>();
  List<String> packageFilter=MetadataConnectionUtils.getPackageFilter(dbProvider,mockDatabaseMetaData,true);
  boolean haveFilter=false;
  if (packageFilter.size() > 0) {
    catalogNames.addAll(packageFilter);
    haveFilter=true;
  }
 else {
    catalogNames.add("String_Node_Str");
    catalogNames.add("String_Node_Str");
    catalogNames.add("String_Node_Str");
  }
  ResultSet mockCatalogResults=Mockito.mock(ResultSet.class);
  if (haveFilter) {
    Mockito.when(mockCatalogResults.next()).thenReturn(true,false);
  }
 else {
    Mockito.when(mockCatalogResults.next()).thenReturn(true,true,true,false);
  }
  Mockito.when(mockCatalogResults.getString(MetaDataConstants.TABLE_CAT.name())).thenReturn("String_Node_Str","String_Node_Str","String_Node_Str");
  ResultSet mockSchemaResults=Mockito.mock(ResultSet.class);
  Mockito.when(mockSchemaResults.next()).thenReturn(false);
  Mockito.when(mockDatabaseMetaData.getDatabaseProductName()).thenReturn(EDatabaseTypeName.MYSQL.getProduct());
  Mockito.when(mockDatabaseMetaData.getCatalogs()).thenReturn(mockCatalogResults);
  Mockito.when(mockDatabaseMetaData.getDriverName()).thenReturn("String_Node_Str");
  Mockito.when(mockDatabaseMetaData.getSchemas()).thenReturn(mockSchemaResults);
  CoreRuntimePlugin instanceMock=Mockito.mock(CoreRuntimePlugin.class);
  PowerMockito.mockStatic(CoreRuntimePlugin.class);
  Mockito.when(CoreRuntimePlugin.getInstance()).thenReturn(instanceMock);
  Mockito.when(instanceMock.getRepositoryService()).thenReturn(null);
  PowerMockito.mockStatic(ExtractMetaDataUtils.class);
  ExtractMetaDataUtils extract=Mockito.mock(ExtractMetaDataUtils.class);
  Mockito.when(ExtractMetaDataUtils.getInstance()).thenReturn(extract);
  Mockito.when(extract.getConnectionMetadata(mockSqlConn)).thenReturn(mockDatabaseMetaData);
  PowerMockito.mockStatic(ConnectionHelper.class);
  Set<MetadataTable> result=new HashSet<MetadataTable>();
  Mockito.when(ConnectionHelper.getTables(dbProvider)).thenReturn(result);
  Mockito.when(ConnectionHelper.addCatalogs((Collection<Catalog>)Mockito.any(),(Connection)Mockito.any())).thenCallRealMethod();
  Mockito.when(ConnectionHelper.addPackages((Collection<Catalog>)Mockito.any(),(Connection)Mockito.any())).thenCallRealMethod();
  MetadataFillFactory mockMetadataFillFactory=Mockito.mock(MetadataFillFactory.class);
  PowerMockito.mockStatic(MetadataFillFactory.class);
  Mockito.when(MetadataFillFactory.getDBInstance()).thenReturn(mockMetadataFillFactory);
  Mockito.when(MetadataFillFactory.getDBInstance()).thenReturn(mockMetadataFillFactory);
  Mockito.when(MetadataFillFactory.getDBInstance()).thenCallRealMethod();
  Mockito.when(MetadataFillFactory.getDBInstance()).thenReturn(mockMetadataFillFactory);
  Mockito.when(mockMetadataFillFactory.createConnection((IMetadataConnection)Mockito.any())).thenReturn(returnCode);
  Mockito.when(mockMetadataFillFactory.fillUIConnParams((IMetadataConnection)Mockito.any(),(Connection)Mockito.isNull())).thenReturn(dbProvider);
  Mockito.when(mockMetadataFillFactory.fillCatalogs((Connection)Mockito.any(),(DatabaseMetaData)Mockito.any(),Mockito.anyList())).thenCallRealMethod();
  Mockito.when(mockMetadataFillFactory.fillSchemas((Connection)Mockito.any(),(DatabaseMetaData)Mockito.any(),Mockito.anyList())).thenReturn(schemaPackageFilter);
  List<Schema> schemaList=new ArrayList<Schema>();
  Mockito.when(mockMetadataFillFactory.fillSchemaToCatalog((Connection)Mockito.any(),(DatabaseMetaData)Mockito.any(),(Catalog)Mockito.any(),(List<String>)Mockito.any())).thenReturn(schemaList);
  DQStructureComparer.getRefreshedDataProvider(dbProvider);
  List<Catalog> catalogs=CatalogHelper.getCatalogs(dbProvider.getDataPackage());
  assertTrue(catalogs.size() == catalogNames.size());
  for (int index=0; index < catalogNames.size(); index++) {
    assertTrue(catalogNames.get(index).equalsIgnoreCase(catalogs.get(index).getName()));
  }
}