Program: 137077
Project: 137077
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(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());
}

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.IBMDB2)).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());
}