Program: 137347
Project: 137347
Buggy source:
@Test public void testGetRefreshedDataProvider() throws Exception {
  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);
  ExtractMetaDataUtils extract=SingletonUtil.spySingleton(ExtractMetaDataUtils.class);
  PowerMockito.mockStatic(ExtractMetaDataUtils.class);
  Mockito.when(ExtractMetaDataUtils.getInstance()).thenReturn(extract);
  Mockito.when(extract.getConnectionMetadata(mockSqlConn)).thenReturn(mockDatabaseMetaData);
  Mockito.when(extract.getDatabaseMetaData(mockSqlConn,dbProvider)).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 Exception {
  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);
  ExtractMetaDataUtils extract=SingletonUtil.spySingleton(ExtractMetaDataUtils.class);
  PowerMockito.mockStatic(ExtractMetaDataUtils.class);
  Mockito.when(ExtractMetaDataUtils.getInstance()).thenReturn(extract);
  Mockito.when(extract.getConnectionMetadata(mockSqlConn)).thenReturn(mockDatabaseMetaData);
  Mockito.when(extract.getDatabaseMetaData(mockSqlConn,dbProvider)).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();
  PowerMockito.mockStatic(MetadataFillFactory.class);
  MetadataFillFactory mockMetadataFillFactory=Mockito.mock(MetadataFillFactory.class);
  Mockito.when(MetadataFillFactory.getDBInstance(EDatabaseTypeName.MYSQL)).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())).thenReturn(null);
  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);
  TypedReturnCode<Connection> refreshedDataProvider=DQStructureComparer.getRefreshedDataProvider(dbProvider);
  Assert.assertEquals(true,refreshedDataProvider.isOk());
  Assert.assertNotNull(refreshedDataProvider.getObject());
}