Program: 126874
Project: 126874
Buggy source:
/** 
 * Test method for  {@link org.talend.core.model.metadata.builder.database.DqRepositoryViewService#getViews(org.talend.core.model.metadata.builder.connection.Connection,orgomg.cwm.resource.relational.Catalog,java.lang.String,boolean)}.
 */
@Test public void testGetViewsConnectionCatalogStringBoolean(){
  java.sql.Connection sqlConn=null;
  DatabaseMetaData metaData=null;
  String catalogName="String_Node_Str";
  List<TdView> tableList=new ArrayList<TdView>();
  List<TdView> retableList=new ArrayList<TdView>();
  List<TdView> resultList1=null;
  List<TdView> resultList2=null;
  List<TdView> resultList3=null;
  String tablePattern=null;
  boolean loadFromDB=true;
  TdView tableMock=Mockito.mock(TdView.class);
  retableList.add(tableMock);
  ResultSet tables=Mockito.mock(ResultSet.class);
  try {
    Connection dataProvider=Mockito.mock(DatabaseConnection.class);
    Catalog catalog=Mockito.mock(Catalog.class);
    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.getViews(catalog)).thenReturn(tableList);
    MetadataFillFactory metadataMock=Mockito.mock(MetadataFillFactory.class);
    Mockito.when(metadataMock.fillViews(Mockito.eq(catalog),Mockito.eq(metaData),Mockito.anyList(),Mockito.eq(tablePattern),Mockito.eq(DqRepositoryViewService.VIEW_TYPES))).thenReturn(retableList).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.getViews(catalog)).thenReturn(retableList);
    resultList1=DqRepositoryViewService.getViews(dataProvider,catalog,tablePattern,loadFromDB);
    tableList.add(tableMock);
    resultList2=DqRepositoryViewService.getViews(dataProvider,catalog,tablePattern,loadFromDB);
    loadFromDB=false;
    resultList3=DqRepositoryViewService.getViews(dataProvider,catalog,tablePattern,loadFromDB);
    Mockito.verify(metadataMock,Mockito.times(2)).fillViews(Mockito.eq(catalog),Mockito.eq(metaData),Mockito.anyList(),Mockito.eq(tablePattern),Mockito.eq(DqRepositoryViewService.VIEW_TYPES));
    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#getViews(org.talend.core.model.metadata.builder.connection.Connection,orgomg.cwm.resource.relational.Catalog,java.lang.String,boolean)}.
 */
@Test public void testGetViewsConnectionCatalogStringBoolean(){
  java.sql.Connection sqlConn=null;
  DatabaseMetaData metaData=null;
  String catalogName="String_Node_Str";
  List<TdView> tableList=new ArrayList<TdView>();
  List<TdView> retableList=new ArrayList<TdView>();
  List<TdView> resultList1=null;
  List<TdView> resultList2=null;
  List<TdView> resultList3=null;
  String tablePattern=null;
  boolean loadFromDB=true;
  TdView tableMock=Mockito.mock(TdView.class);
  retableList.add(tableMock);
  ResultSet tables=Mockito.mock(ResultSet.class);
  try {
    Connection dataProvider=Mockito.mock(DatabaseConnection.class);
    Catalog catalog=Mockito.mock(Catalog.class);
    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.getViews(catalog)).thenReturn(tableList);
    MetadataFillFactory metadataMock=Mockito.mock(MetadataFillFactory.class);
    Mockito.when(metadataMock.fillViews(Mockito.eq(catalog),Mockito.eq(metaData),Mockito.anyList(),Mockito.eq(tablePattern),Mockito.eq(DqRepositoryViewService.VIEW_TYPES))).thenReturn(retableList).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.getViews(catalog)).thenReturn(retableList);
    resultList1=DqRepositoryViewService.getViews(dataProvider,catalog,tablePattern,loadFromDB);
    tableList.add(tableMock);
    resultList2=DqRepositoryViewService.getViews(dataProvider,catalog,tablePattern,loadFromDB);
    loadFromDB=false;
    resultList3=DqRepositoryViewService.getViews(dataProvider,catalog,tablePattern,loadFromDB);
    Mockito.verify(metadataMock,Mockito.times(2)).fillViews(Mockito.eq(catalog),Mockito.eq(metaData),Mockito.anyList(),Mockito.eq(tablePattern),Mockito.eq(DqRepositoryViewService.VIEW_TYPES));
    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());
  }
}