Program: 137346
Project: 137346
Buggy source:
@Test public void testGetRefreshedDataProviderForDB2() throws SQLException {
  DatabaseConnection dbProvider=ConnectionFactory.eINSTANCE.createDatabaseConnection();
  setJDBDB2Connection(dbProvider);
  List<Catalog> catalogPackageFilter=new ArrayList<Catalog>();
  List<orgomg.cwm.objectmodel.core.Package> schemaPackageFilter=new ArrayList<orgomg.cwm.objectmodel.core.Package>();
  DatabaseMetaData mockDatabaseMetaData=Mockito.mock(DatabaseMetaData.class);
  Mockito.when(mockDatabaseMetaData.supportsCatalogsInIndexDefinitions()).thenReturn(true);
  Mockito.when(mockDatabaseMetaData.supportsSchemasInIndexDefinitions()).thenReturn(true);
  TypedReturnCode<java.sql.Connection> returnCode=new TypedReturnCode<java.sql.Connection>(true);
  java.sql.Connection mockSqlConn=Mockito.mock(java.sql.Connection.class);
  Mockito.when(mockSqlConn.getMetaData()).thenReturn(mockDatabaseMetaData);
  returnCode.setObject(mockSqlConn);
  List<String> schenaNames=new ArrayList<String>();
  List<String> packageFilter=MetadataConnectionUtils.getPackageFilter(dbProvider,mockDatabaseMetaData,false);
  boolean haveFilter=false;
  if (packageFilter.size() > 0) {
    schenaNames.addAll(packageFilter);
    haveFilter=true;
  }
 else {
    schenaNames.add("String_Node_Str");
    schenaNames.add("String_Node_Str");
    schenaNames.add("String_Node_Str");
  }
  ResultSet mockSchemaResults=Mockito.mock(ResultSet.class);
  if (haveFilter) {
    Mockito.when(mockSchemaResults.next()).thenReturn(true,false);
  }
 else {
    Mockito.when(mockSchemaResults.next()).thenReturn(true,true,true,false);
  }
  Mockito.when(mockSchemaResults.getString(MetaDataConstants.TABLE_SCHEM.name())).thenReturn("String_Node_Str","String_Node_Str","String_Node_Str");
  ResultSet mockCatalogResults=Mockito.mock(ResultSet.class);
  Mockito.when(mockCatalogResults.next()).thenReturn(false);
  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);
  Mockito.when(extract.createDB2ForZosFakeDatabaseMetaData(mockSqlConn)).thenReturn(mockDatabaseMetaData);
  Mockito.when(extract.getDatabaseMetaData(mockSqlConn,dbProvider)).thenCallRealMethod();
  Mockito.when(extract.getDatabaseMetaData(mockSqlConn,dbProvider,false)).thenCallRealMethod();
  Mockito.when(extract.getDatabaseMetaData(mockSqlConn,EDatabaseTypeName.IBMDB2.getXmlName(),false,"String_Node_Str")).thenCallRealMethod();
  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();
  Mockito.when(ConnectionHelper.addSchemas((Collection<Schema>)Mockito.any(),(Connection)Mockito.any())).thenCallRealMethod();
  Mockito.when(ConnectionHelper.addPackages((Collection<Schema>)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())).thenCallRealMethod();
  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<Schema> scheams=SchemaHelper.getSchemas(dbProvider.getDataPackage());
  assertTrue(scheams.size() == schenaNames.size());
  for (int index=0; index < schenaNames.size(); index++) {
    assertTrue(schenaNames.get(index).equalsIgnoreCase(scheams.get(index).getName()));
  }
}

Fixed version (ground truth):
@Test public void testGetRefreshedDataProviderForDB2() throws SQLException {
  DatabaseConnection dbProvider=ConnectionFactory.eINSTANCE.createDatabaseConnection();
  setJDBDB2Connection(dbProvider);
  List<Catalog> catalogPackageFilter=new ArrayList<Catalog>();
  List<orgomg.cwm.objectmodel.core.Package> schemaPackageFilter=new ArrayList<orgomg.cwm.objectmodel.core.Package>();
  DatabaseMetaData mockDatabaseMetaData=Mockito.mock(DatabaseMetaData.class);
  Mockito.when(mockDatabaseMetaData.supportsCatalogsInIndexDefinitions()).thenReturn(true);
  Mockito.when(mockDatabaseMetaData.supportsSchemasInIndexDefinitions()).thenReturn(true);
  TypedReturnCode<java.sql.Connection> returnCode=new TypedReturnCode<java.sql.Connection>(true);
  java.sql.Connection mockSqlConn=Mockito.mock(java.sql.Connection.class);
  Mockito.when(mockSqlConn.getMetaData()).thenReturn(mockDatabaseMetaData);
  returnCode.setObject(mockSqlConn);
  List<String> schenaNames=new ArrayList<String>();
  List<String> packageFilter=MetadataConnectionUtils.getPackageFilter(dbProvider,mockDatabaseMetaData,false);
  boolean haveFilter=false;
  if (packageFilter.size() > 0) {
    schenaNames.addAll(packageFilter);
    haveFilter=true;
  }
 else {
    schenaNames.add("String_Node_Str");
    schenaNames.add("String_Node_Str");
    schenaNames.add("String_Node_Str");
  }
  ResultSet mockSchemaResults=Mockito.mock(ResultSet.class);
  if (haveFilter) {
    Mockito.when(mockSchemaResults.next()).thenReturn(true,false);
  }
 else {
    Mockito.when(mockSchemaResults.next()).thenReturn(true,true,true,false);
  }
  Mockito.when(mockSchemaResults.getString(MetaDataConstants.TABLE_SCHEM.name())).thenReturn("String_Node_Str","String_Node_Str","String_Node_Str");
  ResultSet mockCatalogResults=Mockito.mock(ResultSet.class);
  Mockito.when(mockCatalogResults.next()).thenReturn(false);
  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);
  Mockito.when(extract.createDB2ForZosFakeDatabaseMetaData(mockSqlConn)).thenReturn(mockDatabaseMetaData);
  Mockito.when(extract.getDatabaseMetaData(mockSqlConn,dbProvider)).thenCallRealMethod();
  Mockito.when(extract.getDatabaseMetaData(mockSqlConn,dbProvider,false)).thenCallRealMethod();
  Mockito.when(extract.getDatabaseMetaData(mockSqlConn,EDatabaseTypeName.IBMDB2.getXmlName(),false,"String_Node_Str")).thenCallRealMethod();
  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();
  Mockito.when(ConnectionHelper.addSchemas((Collection<Schema>)Mockito.any(),(Connection)Mockito.any())).thenCallRealMethod();
  Mockito.when(ConnectionHelper.addPackages((Collection<Schema>)Mockito.any(),(Connection)Mockito.any())).thenCallRealMethod();
  MetadataFillFactory mockMetadataFillFactory=Mockito.mock(MetadataFillFactory.class);
  PowerMockito.mockStatic(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(null);
  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());
}