Program: 127325
Project: 127325
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.Schema,java.lang.String,boolean)}.
 */
@Test public void testGetViewsConnectionSchemaStringBoolean(){
  java.sql.Connection sqlConn=null;
  DatabaseMetaData metaData=null;
  String schemaName="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);
    Schema schema=Mockito.mock(Schema.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);
    Mockito.when(ExtractMetaDataUtils.getDatabaseMetaData(sqlConn,(DatabaseConnection)dataProvider,false)).thenReturn(metaData);
    PowerMockito.mockStatic(PackageHelper.class);
    Mockito.when(PackageHelper.getViews(schema)).thenReturn(tableList);
    MetadataFillFactory metadataMock=Mockito.mock(MetadataFillFactory.class);
    Mockito.when(metadataMock.fillViews(Mockito.eq(schema),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(SchemaHelper.class);
    Mockito.when(SchemaHelper.getViews(schema)).thenReturn(retableList);
    PowerMockito.mockStatic(CatalogHelper.class);
    Mockito.when(CatalogHelper.getParentCatalog(schema)).thenReturn(catalog);
    resultList1=DqRepositoryViewService.getViews(dataProvider,schema,tablePattern,loadFromDB);
    tableList.add(tableMock);
    resultList2=DqRepositoryViewService.getViews(dataProvider,schema,tablePattern,loadFromDB);
    loadFromDB=false;
    resultList3=DqRepositoryViewService.getViews(dataProvider,schema,tablePattern,loadFromDB);
    Mockito.verify(metadataMock,Mockito.times(2)).fillViews(Mockito.eq(schema),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,schema,sqlConn,metaData,metadataMock,catalog);
    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.Schema,java.lang.String,boolean)}.
 */
@Test public void testGetViewsConnectionSchemaStringBoolean(){
  java.sql.Connection sqlConn=null;
  DatabaseMetaData metaData=null;
  String schemaName="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);
    Schema schema=Mockito.mock(Schema.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);
    Mockito.when(ExtractMetaDataUtils.getInstance().getDatabaseMetaData(sqlConn,(DatabaseConnection)dataProvider,false)).thenReturn(metaData);
    PowerMockito.mockStatic(PackageHelper.class);
    Mockito.when(PackageHelper.getViews(schema)).thenReturn(tableList);
    MetadataFillFactory metadataMock=Mockito.mock(MetadataFillFactory.class);
    Mockito.when(metadataMock.fillViews(Mockito.eq(schema),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(SchemaHelper.class);
    Mockito.when(SchemaHelper.getViews(schema)).thenReturn(retableList);
    PowerMockito.mockStatic(CatalogHelper.class);
    Mockito.when(CatalogHelper.getParentCatalog(schema)).thenReturn(catalog);
    resultList1=DqRepositoryViewService.getViews(dataProvider,schema,tablePattern,loadFromDB);
    tableList.add(tableMock);
    resultList2=DqRepositoryViewService.getViews(dataProvider,schema,tablePattern,loadFromDB);
    loadFromDB=false;
    resultList3=DqRepositoryViewService.getViews(dataProvider,schema,tablePattern,loadFromDB);
    Mockito.verify(metadataMock,Mockito.times(2)).fillViews(Mockito.eq(schema),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,schema,sqlConn,metaData,metadataMock,catalog);
    assertTrue(resultList1.size() == 1);
    assertTrue(resultList2.size() == 1);
    assertTrue(resultList3.size() == 1);
  }
 catch (  Exception e) {
    e.printStackTrace();
    fail(e.getMessage());
  }
}