nus-yam/ex-repair huggingface dataset:
Program: 49341
Project: 49341
Buggy source:
@Test public void testImportRecordSuccessWithFilename() throws IOException, ImporterException {
  Importer importer=mock(Importer.class);
  EventSink es=mock(EventSink.class);
  OwnerResource thisOwnerResource=new OwnerResource(ownerCurator,null,null,null,i18n,es,null,null,null,importer,null,null,null,importRecordCurator,null,null,null,null,null,null,null,contentOverrideValidator,serviceLevelValidator,null,null,null,null);
  MultipartInput input=mock(MultipartInput.class);
  InputPart part=mock(InputPart.class);
  File archive=mock(File.class);
  List<InputPart> parts=new ArrayList<InputPart>();
  parts.add(part);
  MultivaluedMap<String,String> mm=new MultivaluedMapImpl<String,String>();
  List<String> contDis=new ArrayList<String>();
  contDis.add("String_Node_Str");
  mm.put("String_Node_Str",contDis);
  when(input.getParts()).thenReturn(parts);
  when(part.getHeaders()).thenReturn(mm);
  when(part.getBody(any(GenericType.class))).thenReturn(archive);
  when(importer.loadExport(eq(owner),any(File.class),any(ConflictOverrides.class))).thenReturn(new HashMap<String,Object>());
  thisOwnerResource.importManifest(owner.getKey(),new String[]{},input);
  List<ImportRecord> records=importRecordCurator.findRecords(owner);
  ImportRecord ir=records.get(0);
  assertEquals("String_Node_Str",ir.getFileName());
  assertEquals(owner,ir.getOwner());
  assertEquals(ImportRecord.Status.SUCCESS,ir.getStatus());
}

Fixed version (ground truth):
@Test public void testImportRecordSuccessWithFilename() throws IOException, ImporterException {
  Importer importer=mock(Importer.class);
  EventSink es=mock(EventSink.class);
  OwnerResource thisOwnerResource=new OwnerResource(ownerCurator,null,null,null,i18n,es,null,null,null,importer,null,null,null,importRecordCurator,null,null,null,null,null,null,null,contentOverrideValidator,serviceLevelValidator,null,null,null,null,null);
  MultipartInput input=mock(MultipartInput.class);
  InputPart part=mock(InputPart.class);
  File archive=mock(File.class);
  List<InputPart> parts=new ArrayList<InputPart>();
  parts.add(part);
  MultivaluedMap<String,String> mm=new MultivaluedMapImpl<String,String>();
  List<String> contDis=new ArrayList<String>();
  contDis.add("String_Node_Str");
  mm.put("String_Node_Str",contDis);
  when(input.getParts()).thenReturn(parts);
  when(part.getHeaders()).thenReturn(mm);
  when(part.getBody(any(GenericType.class))).thenReturn(archive);
  when(importer.loadExport(eq(owner),any(File.class),any(ConflictOverrides.class))).thenReturn(new HashMap<String,Object>());
  thisOwnerResource.importManifest(owner.getKey(),new String[]{},input);
  List<ImportRecord> records=importRecordCurator.findRecords(owner);
  ImportRecord ir=records.get(0);
  assertEquals("String_Node_Str",ir.getFileName());
  assertEquals(owner,ir.getOwner());
  assertEquals(ImportRecord.Status.SUCCESS,ir.getStatus());
}
Program: 49342
Project: 49342
Buggy source:
@Test public void testCreateUeberCertificateRegenerateWithNoEntitlement(){
  Principal principal=setupPrincipal(owner,Access.ALL);
  Owner owner=TestUtil.createOwner();
  Consumer consumer=TestUtil.createConsumer(owner);
  Entitlement ent=mock(Entitlement.class);
  List<Entitlement> entList=new LinkedList<Entitlement>();
  EntitlementCertificate entCert=mock(EntitlementCertificate.class);
  List<EntitlementCertificate> ecList=Arrays.asList(entCert);
  OwnerCurator oc=mock(OwnerCurator.class);
  ConsumerCurator cc=mock(ConsumerCurator.class);
  EntitlementCurator ec=mock(EntitlementCurator.class);
  CandlepinPoolManager cpm=mock(CandlepinPoolManager.class);
  EntitlementCertificateCurator ecc=mock(EntitlementCertificateCurator.class);
  UeberCertificateGenerator ucg=mock(UeberCertificateGenerator.class);
  OwnerResource resource=new OwnerResource(oc,null,cc,null,i18n,null,null,null,null,null,cpm,null,null,null,null,null,ecc,ec,ucg,null,null,null,null,null,null,null,null);
  try {
    when(oc.lookupByKey(eq("String_Node_Str"))).thenReturn(owner);
    when(cc.findByName(eq(owner),eq(Consumer.UEBER_CERT_CONSUMER))).thenReturn(consumer);
    when(ec.listByConsumer(eq(consumer))).thenReturn(entList);
    when(ucg.generate(eq(owner),eq(principal))).thenReturn(entCert);
  }
 catch (  EntitlementRefusedException ere) {
  }
  EntitlementCertificate result=resource.createUeberCertificate(principal,"String_Node_Str");
  assertEquals(entCert,result);
}

Fixed version (ground truth):
@Test public void testCreateUeberCertificateRegenerateWithNoEntitlement(){
  Principal principal=setupPrincipal(owner,Access.ALL);
  Owner owner=TestUtil.createOwner();
  Consumer consumer=TestUtil.createConsumer(owner);
  Entitlement ent=mock(Entitlement.class);
  List<Entitlement> entList=new LinkedList<Entitlement>();
  EntitlementCertificate entCert=mock(EntitlementCertificate.class);
  List<EntitlementCertificate> ecList=Arrays.asList(entCert);
  OwnerCurator oc=mock(OwnerCurator.class);
  ConsumerCurator cc=mock(ConsumerCurator.class);
  EntitlementCurator ec=mock(EntitlementCurator.class);
  CandlepinPoolManager cpm=mock(CandlepinPoolManager.class);
  EntitlementCertificateCurator ecc=mock(EntitlementCertificateCurator.class);
  UeberCertificateGenerator ucg=mock(UeberCertificateGenerator.class);
  OwnerResource resource=new OwnerResource(oc,null,cc,null,i18n,null,null,null,null,null,cpm,null,null,null,null,null,ecc,ec,ucg,null,null,null,null,null,null,null,null,null);
  try {
    when(oc.lookupByKey(eq("String_Node_Str"))).thenReturn(owner);
    when(cc.findByName(eq(owner),eq(Consumer.UEBER_CERT_CONSUMER))).thenReturn(consumer);
    when(ec.listByConsumer(eq(consumer))).thenReturn(entList);
    when(ucg.generate(eq(owner),eq(principal))).thenReturn(entCert);
  }
 catch (  EntitlementRefusedException ere) {
  }
  EntitlementCertificate result=resource.createUeberCertificate(principal,"String_Node_Str");
  assertEquals(entCert,result);
}
Program: 49343
Project: 49343
Buggy source:
@Test(expected=NotFoundException.class) public void testCreateUeberCertificateInvalidOwner(){
  Principal principal=setupPrincipal(owner,Access.ALL);
  OwnerCurator oc=mock(OwnerCurator.class);
  ConsumerCurator cc=mock(ConsumerCurator.class);
  EntitlementCurator ec=mock(EntitlementCurator.class);
  CandlepinPoolManager cpm=mock(CandlepinPoolManager.class);
  EntitlementCertificateCurator ecc=mock(EntitlementCertificateCurator.class);
  UeberCertificateGenerator ucg=mock(UeberCertificateGenerator.class);
  OwnerResource resource=new OwnerResource(oc,null,cc,null,i18n,null,null,null,null,null,cpm,null,null,null,null,null,ecc,ec,ucg,null,null,null,null,null,null,null,null);
  EntitlementCertificate result=resource.createUeberCertificate(principal,"String_Node_Str");
}

Fixed version (ground truth):
@Test(expected=NotFoundException.class) public void testCreateUeberCertificateInvalidOwner(){
  Principal principal=setupPrincipal(owner,Access.ALL);
  OwnerCurator oc=mock(OwnerCurator.class);
  ConsumerCurator cc=mock(ConsumerCurator.class);
  EntitlementCurator ec=mock(EntitlementCurator.class);
  CandlepinPoolManager cpm=mock(CandlepinPoolManager.class);
  EntitlementCertificateCurator ecc=mock(EntitlementCertificateCurator.class);
  UeberCertificateGenerator ucg=mock(UeberCertificateGenerator.class);
  OwnerResource resource=new OwnerResource(oc,null,cc,null,i18n,null,null,null,null,null,cpm,null,null,null,null,null,ecc,ec,ucg,null,null,null,null,null,null,null,null,null);
  EntitlementCertificate result=resource.createUeberCertificate(principal,"String_Node_Str");
}
Program: 49344
Project: 49344
Buggy source:
@Test(expected=NotFoundException.class) public void getEntitlementsForNonExistantOwner(){
  PageRequest req=new PageRequest();
  req.setPage(1);
  req.setPerPage(10);
  OwnerCurator oc=mock(OwnerCurator.class);
  OwnerResource ownerres=new OwnerResource(oc,null,null,null,i18n,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
  ownerres.ownerEntitlements("String_Node_Str",null,null,null,req);
}

Fixed version (ground truth):
@Test(expected=NotFoundException.class) public void getEntitlementsForNonExistantOwner(){
  PageRequest req=new PageRequest();
  req.setPage(1);
  req.setPerPage(10);
  OwnerCurator oc=mock(OwnerCurator.class);
  OwnerResource ownerres=new OwnerResource(oc,null,null,null,i18n,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);
  ownerres.ownerEntitlements("String_Node_Str",null,null,null,req);
}
Program: 49345
Project: 49345
Buggy source:
@Before public void setUp(){
  owner=ownerCurator.create(new Owner(OWNER_NAME));
  Role ownerAdminRole=createAdminRole(owner);
  roleCurator.create(ownerAdminRole);
  User user=new User("String_Node_Str","String_Node_Str");
  principal=new UserPrincipal("String_Node_Str",new ArrayList<Permission>(permFactory.createPermissions(user,ownerAdminRole.getPermissions())),false);
  setupPrincipal(principal);
  ConsumerType ueberCertType=new ConsumerType(ConsumerTypeEnum.UEBER_CERT);
  consumerTypeCurator.create(ueberCertType);
  or=new OwnerResource(ownerCurator,null,consumerCurator,null,i18n,null,null,null,null,null,poolManager,null,null,null,null,consumerTypeCurator,entCertCurator,entitlementCurator,ueberCertGenerator,null,null,contentOverrideValidator,serviceLevelValidator,null,null,null,null);
}

Fixed version (ground truth):
@Before public void setUp(){
  owner=ownerCurator.create(new Owner(OWNER_NAME));
  Role ownerAdminRole=createAdminRole(owner);
  roleCurator.create(ownerAdminRole);
  User user=new User("String_Node_Str","String_Node_Str");
  principal=new UserPrincipal("String_Node_Str",new ArrayList<Permission>(permFactory.createPermissions(user,ownerAdminRole.getPermissions())),false);
  setupPrincipal(principal);
  ConsumerType ueberCertType=new ConsumerType(ConsumerTypeEnum.UEBER_CERT);
  consumerTypeCurator.create(ueberCertType);
  or=new OwnerResource(ownerCurator,null,consumerCurator,null,i18n,null,null,null,null,null,poolManager,null,null,null,null,consumerTypeCurator,entCertCurator,entitlementCurator,ueberCertGenerator,null,null,contentOverrideValidator,serviceLevelValidator,null,null,null,null,null);
}
Program: 49347
Project: 49347
Buggy source:
void refreshPoolsWithRegeneration(SubscriptionServiceAdapter subAdapter,Owner owner,boolean lazy){
  long start=System.currentTimeMillis();
  log.info("String_Node_Str",owner);
  List<Subscription> subs=subAdapter.getSubscriptions(owner);
  log.debug("String_Node_Str",subs.size());
  SubscriptionReconciler reconciler=new SubscriptionReconciler();
  reconciler.reconcile(owner,subs,poolCurator);
  Set<String> subIds=Util.newSet();
  Set<Content> changedContent=refreshContent(owner,subs);
  Set<Product> changedProducts=refreshProducts(owner,subs);
  List<String> deletedSubs=new LinkedList<String>();
  for (  Subscription sub : subs) {
    String subId=sub.getId();
    subIds.add(subId);
    log.debug("String_Node_Str",sub);
    if (isExpired(sub)) {
      deletedSubs.add(subId);
      log.info("String_Node_Str",sub);
      continue;
    }
    refreshPoolsForSubscription(sub,lazy,changedProducts);
  }
  subIds.removeAll(deletedSubs);
  for (  Pool pool : poolCurator.getPoolsFromBadSubs(owner,subIds)) {
    if (pool.getSourceSubscription() != null && !pool.getType().isDerivedType()) {
      deletePool(pool);
    }
  }
  List<Pool> floatingPools=poolCurator.getOwnersFloatingPools(owner);
  updateFloatingPools(floatingPools,lazy,changedProducts);
  log.info("String_Node_Str",owner.getKey(),System.currentTimeMillis() - start);
}

Fixed version (ground truth):
void refreshPoolsWithRegeneration(SubscriptionServiceAdapter subAdapter,Owner owner,boolean lazy){
  long start=System.currentTimeMillis();
  log.info("String_Node_Str",owner);
  List<Subscription> subs=subAdapter.getSubscriptions(owner);
  log.debug("String_Node_Str",subs.size());
  SubscriptionReconciler reconciler=new SubscriptionReconciler();
  reconciler.reconcile(owner,subs,poolCurator);
  Set<String> subIds=Util.newSet();
  Set<Content> changedContent=refreshContent(owner,subs);
  Set<Product> changedProducts=refreshProducts(owner,subs);
  List<String> deletedSubs=new LinkedList<String>();
  for (  Subscription sub : subs) {
    String subId=sub.getId();
    subIds.add(subId);
    log.debug("String_Node_Str",sub);
    if (isExpired(sub)) {
      deletedSubs.add(subId);
      log.info("String_Node_Str",sub);
      continue;
    }
    refreshPoolsForSubscription(sub,lazy,changedProducts);
  }
  Pool ueberPool=this.findUeberPool(owner);
  String ueberPoolId=ueberPool != null ? ueberPool.getId() : null;
  subIds.removeAll(deletedSubs);
  for (  Pool pool : poolCurator.getPoolsFromBadSubs(owner,subIds)) {
    if (pool.getSourceSubscription() != null && !pool.getType().isDerivedType() && (ueberPoolId == null || !ueberPoolId.equals(pool.getId()))) {
      deletePool(pool);
    }
  }
  List<Pool> floatingPools=poolCurator.getOwnersFloatingPools(owner);
  updateFloatingPools(floatingPools,lazy,changedProducts);
  log.info("String_Node_Str",owner.getKey(),System.currentTimeMillis() - start);
}
Program: 49348
Project: 49348
Buggy source:
/** 
 * Creates an Ueber Entitlement Certificate
 * @return an EntitlementCertificate object
 * @httpcode 400
 * @httpcode 404
 * @httpcode 200
 */
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("String_Node_Str") public EntitlementCertificate createUeberCertificate(@Context Principal principal,@Verify(Owner.class) @PathParam("String_Node_Str") String ownerKey){
  Owner o=findOwner(ownerKey);
  if (o == null) {
    throw new NotFoundException(i18n.tr("String_Node_Str",ownerKey));
  }
  Consumer ueberConsumer=consumerCurator.findByName(o,Consumer.UEBER_CERT_CONSUMER);
  if (ueberConsumer != null) {
    List<Entitlement> ueberEntitlement=entitlementCurator.listByConsumer(ueberConsumer);
    poolManager.regenerateCertificatesOf(ueberEntitlement.get(0),true,false);
    return entitlementCertCurator.listForConsumer(ueberConsumer).get(0);
  }
  try {
    return ueberCertGenerator.generate(o,principal);
  }
 catch (  Exception e) {
    log.error("String_Node_Str" + o.getKey(),e);
    throw new BadRequestException(i18n.tr("String_Node_Str",e));
  }
}

Fixed version (ground truth):
/** 
 * Creates an Ueber Entitlement Certificate
 * @return an EntitlementCertificate object
 * @httpcode 400
 * @httpcode 404
 * @httpcode 200
 */
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("String_Node_Str") public EntitlementCertificate createUeberCertificate(@Context Principal principal,@Verify(Owner.class) @PathParam("String_Node_Str") String ownerKey){
  Owner o=findOwner(ownerKey);
  if (o == null) {
    throw new NotFoundException(i18n.tr("String_Node_Str",ownerKey));
  }
  try {
    Consumer ueberConsumer=consumerCurator.findByName(o,Consumer.UEBER_CERT_CONSUMER);
    if (ueberConsumer != null) {
      List<Entitlement> ueberEntitlements=entitlementCurator.listByConsumer(ueberConsumer);
      if (ueberEntitlements.size() > 0) {
        poolManager.regenerateCertificatesOf(ueberEntitlements.get(0),true,false);
        return entitlementCertCurator.listForConsumer(ueberConsumer).get(0);
      }
    }
    return ueberCertGenerator.generate(o,principal);
  }
 catch (  Exception e) {
    log.error("String_Node_Str" + o.getKey(),e);
    throw new BadRequestException(i18n.tr("String_Node_Str",e));
  }
}
Program: 49349
Project: 49349
Buggy source:
/** 
 * Creates a   {@link JobDetail} that runs this job for the given {@link Owner}.
 * @param owner the owner to refresh
 * @return a {@link JobDetail} that describes the job run
 */
public static JobDetail forOwner(Owner owner,String data,Boolean create,Principal principal){
  JobDataMap map=new JobDataMap();
  map.put(JobStatus.TARGET_TYPE,JobStatus.TargetType.OWNER);
  map.put(JobStatus.TARGET_ID,owner.getKey());
  map.put(CREATE,create);
  map.put(DATA,compress(data));
  map.put(PRINCIPAL,principal);
  JobDetail detail=newJob(HypervisorUpdateJob.class).withIdentity(prefix + Util.generateUUID()).requestRecovery(true).usingJobData(map).storeDurably(true).build();
  return detail;
}

Fixed version (ground truth):
/** 
 * Creates a   {@link JobDetail} that runs this job for the given {@link Owner}.
 * @param owner the owner to refresh
 * @return a {@link JobDetail} that describes the job run
 */
public static JobDetail forOwner(Owner owner,String data,Boolean create,Principal principal){
  JobDataMap map=new JobDataMap();
  map.put(JobStatus.TARGET_TYPE,JobStatus.TargetType.OWNER);
  map.put(JobStatus.TARGET_ID,owner.getKey());
  map.put(JobStatus.OWNER_ID,owner.getKey());
  map.put(CREATE,create);
  map.put(DATA,compress(data));
  map.put(PRINCIPAL,principal);
  JobDetail detail=newJob(HypervisorUpdateJob.class).withIdentity(prefix + Util.generateUUID()).requestRecovery(true).usingJobData(map).storeDurably(true).build();
  return detail;
}
Program: 49350
Project: 49350
Buggy source:
/** 
 * Migrates pool data. Must be called per-org.
 * @param orgid The id of the owner/organization for which to migrate pool data
 */
private void migratePoolData(String orgid) throws DatabaseException, SQLException {
}

Fixed version (ground truth):
/** 
 * Migrates pool data. Must be called per-org.
 * @param orgid The id of the owner/organization for which to migrate pool data
 */
private void migratePoolData(String orgid) throws DatabaseException, SQLException {
  this.logger.info("String_Node_Str" + orgid);
  ResultSet pools=this.executeQuery("String_Node_Str",orgid);
  while (pools.next()) {
    String poolid=pools.getString(1);
    ResultSet sourcesub=this.executeQuery("String_Node_Str" + "String_Node_Str",poolid);
    while (sourcesub.next()) {
      this.executeUpdate("String_Node_Str" + "String_Node_Str" + "String_Node_Str",this.generateUUID(),sourcesub.getString(2),sourcesub.getString(3),poolid,sourcesub.getTimestamp(5),sourcesub.getTimestamp(6));
    }
    sourcesub.close();
  }
  pools.close();
}
Program: 49352
Project: 49352
Buggy source:
/** 
 * Return a list of subscriptions for the given product. We do essentially 2 queries here, so there is room for optimization both in speed and memory usage.
 * @param product product to search for.
 * @return a list of subscriptions
 */
@SuppressWarnings("String_Node_Str") public List<Subscription> listByProduct(Product product){
  Criteria subscriptionCriteria=currentSession().createCriteria(Subscription.class).createAlias("String_Node_Str","String_Node_Str",CriteriaSpecification.LEFT_JOIN).add(Restrictions.or(Restrictions.eq("String_Node_Str",product),Restrictions.eq("String_Node_Str",product.getId())));
  List<Subscription> subs=subscriptionCriteria.list();
  if (subs == null) {
    return new LinkedList<Subscription>();
  }
  return subs;
}

Fixed version (ground truth):
/** 
 * Return a list of subscriptions for the given product. We do essentially 2 queries here, so there is room for optimization both in speed and memory usage.
 * @param product product to search for.
 * @return a list of subscriptions
 */
@SuppressWarnings("String_Node_Str") public List<Subscription> listByProduct(Product product){
  String hql="String_Node_Str" + "String_Node_Str";
  Query query=currentSession().createQuery(hql);
  query.setParameter("String_Node_Str",product.getId());
  List<Subscription> subs=query.list();
  if (subs == null) {
    return new LinkedList<Subscription>();
  }
  return subs;
}
Program: 49353
Project: 49353
Buggy source:
@Test public void testLookupSubscriptionByProductMixedMainAndProvidedProduct(){
  Owner owner=createOwner();
  Product product=TestUtil.createProduct();
  Product product2=TestUtil.createProduct();
  Product product3=TestUtil.createProduct();
  productCurator.create(product);
  productCurator.create(product2);
  productCurator.create(product3);
  Set<Product> providedProducts=new HashSet<Product>();
  providedProducts.add(product);
  Subscription sub=TestUtil.createSubscription(owner,product2,providedProducts);
  adapter.createSubscription(sub);
  Set<Product> providedProducts2=new HashSet<Product>();
  providedProducts2.add(product3);
  Subscription sub2=TestUtil.createSubscription(owner,product,providedProducts2);
  adapter.createSubscription(sub2);
  List<Subscription> results=adapter.getSubscriptions(product);
  assertEquals(2,results.size());
  assertTrue(results.contains(sub));
  assertTrue(results.contains(sub2));
}

Fixed version (ground truth):
@Test public void testLookupSubscriptionByProductMixedMainAndProvidedProduct(){
  Owner owner=createOwner();
  Product product=TestUtil.createProduct();
  Product product2=TestUtil.createProduct();
  Product product3=TestUtil.createProduct();
  Product product4=TestUtil.createProduct();
  Product product5=TestUtil.createProduct();
  productCurator.create(product);
  productCurator.create(product2);
  productCurator.create(product3);
  productCurator.create(product4);
  productCurator.create(product5);
  Set<Product> providedProducts=new HashSet<Product>();
  providedProducts.add(product);
  providedProducts.add(product4);
  providedProducts.add(product5);
  Subscription sub=TestUtil.createSubscription(owner,product2,providedProducts);
  adapter.createSubscription(sub);
  Set<Product> providedProducts2=new HashSet<Product>();
  providedProducts2.add(product3);
  providedProducts2.add(product5);
  Subscription sub2=TestUtil.createSubscription(owner,product,providedProducts2);
  adapter.createSubscription(sub2);
  subCurator.evict(sub);
  subCurator.evict(sub2);
  List<Subscription> results=adapter.getSubscriptions(product);
  assertEquals(2,results.size());
  assertTrue(results.get(0).getId().equals(sub.getId()) || results.get(0).getId().equals(sub2.getId()));
  assertTrue(results.get(1).getId().equals(sub.getId()) || results.get(1).getId().equals(sub2.getId()));
  if (results.get(0).getId().equals(sub.getId())) {
    sub=results.get(0);
    sub2=results.get(1);
  }
 else {
    sub2=results.get(0);
    sub=results.get(1);
  }
  assertEquals(3,sub.getProvidedProducts().size());
  assertEquals(2,sub2.getProvidedProducts().size());
}
Program: 49355
Project: 49355
Buggy source:
public Set<Product> getChangedProducts(Owner o,Set<Product> allProducts){
  Set<Product> changedProducts=Util.newSet();
  log.debug("String_Node_Str",allProducts.size());
  for (  Product incoming : allProducts) {
    Product existing=prodCurator.lookupById(o,incoming.getId());
    if (existing == null) {
      log.info("String_Node_Str",o.getKey(),incoming.getId());
      incoming.setOwner(o);
      prodCurator.create(incoming);
    }
 else {
      if (hasProductChanged(existing,incoming)) {
        log.info("String_Node_Str",o.getKey(),incoming.getId());
        prodCurator.createOrUpdate(incoming);
        changedProducts.add(incoming);
      }
    }
  }
  return changedProducts;
}

Fixed version (ground truth):
public Set<Product> getChangedProducts(Owner o,Set<Product> allProducts){
  Set<Product> changedProducts=Util.newSet();
  log.debug("String_Node_Str",allProducts.size());
  for (  Product incoming : allProducts) {
    log.debug("String_Node_Str",incoming.getOwner(),o);
    Product existing=prodCurator.lookupById(o,incoming.getId());
    if (existing == null) {
      log.info("String_Node_Str",o.getKey(),incoming.getId());
      incoming.setOwner(o);
      prodCurator.create(incoming);
    }
 else {
      if (hasProductChanged(existing,incoming)) {
        log.info("String_Node_Str",o.getKey(),incoming.getId());
        prodCurator.createOrUpdate(incoming);
        changedProducts.add(incoming);
      }
    }
  }
  return changedProducts;
}
Program: 49356
Project: 49356
Buggy source:
Set<Product> refreshProducts(Owner o,List<Subscription> subs){
  Set<Product> allProducts=Util.newSet();
  for (  Subscription sub : subs) {
    allProducts.add(sub.getProduct());
    allProducts.addAll(sub.getProvidedProducts());
  }
  return getChangedProducts(o,allProducts);
}

Fixed version (ground truth):
Set<Product> refreshProducts(Owner o,List<Subscription> subs){
  Set<Product> allProducts=Util.newSet();
  for (  Subscription sub : subs) {
    log.debug("String_Node_Str",sub.getOwner());
    allProducts.add(sub.getProduct());
    allProducts.addAll(sub.getProvidedProducts());
    allProducts.add(sub.getDerivedProduct());
    allProducts.addAll(sub.getDerivedProvidedProducts());
  }
  return getChangedProducts(o,allProducts);
}
Program: 49357
Project: 49357
Buggy source:
void refreshPoolsWithRegeneration(SubscriptionServiceAdapter subAdapter,Owner owner,boolean lazy){
  log.info("String_Node_Str" + owner.getKey());
  List<Subscription> subs=subAdapter.getSubscriptions(owner);
  log.debug("String_Node_Str" + subs.size() + "String_Node_Str");
  SubscriptionReconciler reconciler=new SubscriptionReconciler();
  reconciler.reconcile(owner,subs,poolCurator);
  Set<String> subIds=Util.newSet();
  Set<Product> changedProducts=refreshProducts(owner,subs);
  List<String> deletedSubs=new LinkedList<String>();
  for (  Subscription sub : subs) {
    String subId=sub.getId();
    subIds.add(subId);
    if (isExpired(sub)) {
      deletedSubs.add(subId);
      log.info("String_Node_Str" + sub);
      continue;
    }
    refreshPoolsForSubscription(sub,lazy,changedProducts);
  }
  subIds.removeAll(deletedSubs);
  for (  Pool p : poolCurator.getPoolsFromBadSubs(owner,subIds)) {
    if (p.getType() == PoolType.NORMAL || p.getType() == PoolType.BONUS) {
      deletePool(p);
    }
  }
  List<Pool> floatingPools=poolCurator.getOwnersFloatingPools(owner);
  updateFloatingPools(subAdapter,floatingPools,lazy,changedProducts);
}

Fixed version (ground truth):
void refreshPoolsWithRegeneration(SubscriptionServiceAdapter subAdapter,Owner owner,boolean lazy){
  log.info("String_Node_Str",owner);
  List<Subscription> subs=subAdapter.getSubscriptions(owner);
  log.debug("String_Node_Str" + subs.size() + "String_Node_Str");
  SubscriptionReconciler reconciler=new SubscriptionReconciler();
  reconciler.reconcile(owner,subs,poolCurator);
  Set<String> subIds=Util.newSet();
  Set<Product> changedProducts=refreshProducts(owner,subs);
  List<String> deletedSubs=new LinkedList<String>();
  for (  Subscription sub : subs) {
    String subId=sub.getId();
    subIds.add(subId);
    if (isExpired(sub)) {
      deletedSubs.add(subId);
      log.info("String_Node_Str" + sub);
      continue;
    }
    refreshPoolsForSubscription(sub,lazy,changedProducts);
  }
  subIds.removeAll(deletedSubs);
  for (  Pool p : poolCurator.getPoolsFromBadSubs(owner,subIds)) {
    if (p.getType() == PoolType.NORMAL || p.getType() == PoolType.BONUS) {
      deletePool(p);
    }
  }
  List<Pool> floatingPools=poolCurator.getOwnersFloatingPools(owner);
  updateFloatingPools(subAdapter,floatingPools,lazy,changedProducts);
}
Program: 49360
Project: 49360
Buggy source:
public List<Subscription> importEntitlements(Owner owner,Set<Product> products,File[] entitlements,ConsumerDto consumer,Meta meta) throws IOException, SyncDataFormatException {
  EntitlementImporter importer=new EntitlementImporter(csCurator,cdnCurator,i18n);
  Map<String,Product> productsById=new HashMap<String,Product>();
  for (  Product product : products) {
    productsById.put(product.getId(),product);
  }
  List<Subscription> subscriptionsToImport=new ArrayList<Subscription>();
  for (  File entitlement : entitlements) {
    Reader reader=null;
    try {
      log.debug("String_Node_Str" + entitlement.getName());
      reader=new FileReader(entitlement);
      subscriptionsToImport.add(importer.importObject(mapper,reader,owner,productsById,consumer,meta));
    }
  finally {
      if (reader != null) {
        reader.close();
      }
    }
  }
  return subscriptionsToImport;
}

Fixed version (ground truth):
public List<Subscription> importEntitlements(Owner owner,Set<Product> products,File[] entitlements,ConsumerDto consumer,Meta meta) throws IOException, SyncDataFormatException {
  log.debug("String_Node_Str",owner);
  EntitlementImporter importer=new EntitlementImporter(csCurator,cdnCurator,i18n);
  Map<String,Product> productsById=new HashMap<String,Product>();
  for (  Product product : products) {
    log.debug("String_Node_Str",owner.getKey());
    productsById.put(product.getId(),product);
  }
  List<Subscription> subscriptionsToImport=new ArrayList<Subscription>();
  for (  File entitlement : entitlements) {
    Reader reader=null;
    try {
      log.debug("String_Node_Str" + entitlement.getName());
      reader=new FileReader(entitlement);
      subscriptionsToImport.add(importer.importObject(mapper,reader,owner,productsById,consumer,meta));
    }
  finally {
      if (reader != null) {
        reader.close();
      }
    }
  }
  return subscriptionsToImport;
}
Program: 49361
Project: 49361
Buggy source:
public Product createObject(ObjectMapper mapper,Reader reader) throws IOException {
  final Product importedProduct=mapper.readValue(reader,Product.class);
  for (  ProductAttribute a : importedProduct.getAttributes()) {
    a.setId(null);
  }
  importedProduct.setMultiplier(1L);
  return importedProduct;
}

Fixed version (ground truth):
public Product createObject(ObjectMapper mapper,Reader reader) throws IOException {
  final Product importedProduct=mapper.readValue(reader,Product.class);
  importedProduct.setUuid(null);
  for (  ProductAttribute a : importedProduct.getAttributes()) {
    a.setId(null);
  }
  importedProduct.setOwner(null);
  importedProduct.setMultiplier(1L);
  return importedProduct;
}
Program: 49362
Project: 49362
Buggy source:
/** 
 * Migrates pool data. Must be called per-org.
 * @param orgid The id of the owner/organization for which to migrate pool data
 */
private void migratePoolData(String orgid) throws DatabaseException, SQLException {
  this.logger.info("String_Node_Str" + orgid);
  ResultSet pools=this.executeQuery("String_Node_Str",orgid);
  while (pools.next()) {
    String poolid=pools.getString(1);
    ResultSet branding=this.executeQuery("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str",orgid,poolid);
    while (branding.next()) {
      String brandingid=branding.getString(1);
      String brandinguuid=this.generateUUID();
      this.logger.info(String.format("String_Node_Str" + "String_Node_Str",brandingid,brandinguuid,orgid,branding.getString(7)));
      this.executeUpdate("String_Node_Str" + "String_Node_Str",brandinguuid,branding.getDate(2),branding.getDate(3),branding.getString(4),branding.getString(5),branding.getString(6));
      this.executeUpdate("String_Node_Str" + "String_Node_Str",poolid,brandinguuid);
    }
    branding.close();
  }
  pools.close();
}

Fixed version (ground truth):
/** 
 * Migrates pool data. Must be called per-org.
 * @param orgid The id of the owner/organization for which to migrate pool data
 */
private void migratePoolData(String orgid) throws DatabaseException, SQLException {
  this.logger.info("String_Node_Str" + orgid);
  ResultSet pools=this.executeQuery("String_Node_Str",orgid);
  while (pools.next()) {
    String poolid=pools.getString(1);
    ResultSet branding=this.executeQuery("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str",orgid,poolid);
    while (branding.next()) {
      String brandingid=branding.getString(1);
      String brandinguuid=Util.generateDbUUID();
      this.logger.info(String.format("String_Node_Str" + "String_Node_Str",brandingid,brandinguuid,orgid,branding.getString(7)));
      this.executeUpdate("String_Node_Str" + "String_Node_Str",brandinguuid,branding.getDate(2),branding.getDate(3),branding.getString(4),branding.getString(5),branding.getString(6));
      this.executeUpdate("String_Node_Str" + "String_Node_Str",poolid,brandinguuid);
    }
    branding.close();
  }
  pools.close();
}
Program: 49366
Project: 49366
Buggy source:
@Before public void init() throws Exception {
  o=new Owner("String_Node_Str","String_Node_Str");
  product=TestUtil.createProduct(o);
  pool=TestUtil.createPool(o,product);
  when(mockConfig.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
  when(eventFactory.getEventBuilder(any(Target.class),any(Type.class))).thenReturn(eventBuilder);
  when(eventBuilder.setNewEntity(any(AbstractHibernateObject.class))).thenReturn(eventBuilder);
  when(eventBuilder.setOldEntity(any(AbstractHibernateObject.class))).thenReturn(eventBuilder);
  this.principal=TestUtil.createOwnerPrincipal();
  this.manager=spy(new CandlepinPoolManager(mockPoolCurator,mockSubAdapter,mockProductCurator,entCertAdapterMock,mockEventSink,eventFactory,mockConfig,enforcerMock,poolRulesMock,entitlementCurator,consumerCuratorMock,certCuratorMock,complianceRules,autobindRules,activationKeyRules,productCuratorMock));
  when(entCertAdapterMock.generateEntitlementCert(any(Entitlement.class),any(Product.class))).thenReturn(new EntitlementCertificate());
  dummyComplianceStatus=new ComplianceStatus(new Date());
  when(complianceRules.getStatus(any(Consumer.class),any(Date.class))).thenReturn(dummyComplianceStatus);
}

Fixed version (ground truth):
@Before public void init() throws Exception {
  o=new Owner("String_Node_Str","String_Node_Str");
  product=TestUtil.createProduct(o);
  pool=TestUtil.createPool(o,product);
  when(mockConfig.getInt(eq(ConfigProperties.PRODUCT_CACHE_MAX))).thenReturn(100);
  when(eventFactory.getEventBuilder(any(Target.class),any(Type.class))).thenReturn(eventBuilder);
  when(eventBuilder.setNewEntity(any(AbstractHibernateObject.class))).thenReturn(eventBuilder);
  when(eventBuilder.setOldEntity(any(AbstractHibernateObject.class))).thenReturn(eventBuilder);
  this.principal=TestUtil.createOwnerPrincipal();
  this.manager=spy(new CandlepinPoolManager(mockPoolCurator,mockSubAdapter,mockProductCurator,entCertAdapterMock,mockEventSink,eventFactory,mockConfig,enforcerMock,poolRulesMock,entitlementCurator,consumerCuratorMock,certCuratorMock,complianceRules,autobindRules,activationKeyRules,productCuratorMock,contentCuratorMock));
  when(entCertAdapterMock.generateEntitlementCert(any(Entitlement.class),any(Product.class))).thenReturn(new EntitlementCertificate());
  dummyComplianceStatus=new ComplianceStatus(new Date());
  when(complianceRules.getStatus(any(Consumer.class),any(Date.class))).thenReturn(dummyComplianceStatus);
}
Program: 49367
Project: 49367
Buggy source:
@Test(expected=RuntimeException.class) public void testExceptionFromCertGen() throws Exception {
  Consumer consumer=createConsumer();
  Entitlement e=Mockito.mock(Entitlement.class);
  Pool p=Mockito.mock(Pool.class);
  Subscription s=Mockito.mock(Subscription.class);
  when(e.getPool()).thenReturn(p);
  when(p.getSubscriptionId()).thenReturn("String_Node_Str");
  when(mockedConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
  when(mockedEntitlementCurator.find(eq("String_Node_Str"))).thenReturn(e);
  when(mockedSubscriptionServiceAdapter.getSubscription(eq("String_Node_Str"))).thenReturn(s);
  when(mockedEntitlementCertServiceAdapter.generateEntitlementCert(any(Entitlement.class),any(Product.class))).thenThrow(new IOException());
  CandlepinPoolManager poolManager=new CandlepinPoolManager(null,mockedSubscriptionServiceAdapter,null,mockedEntitlementCertServiceAdapter,null,null,new CandlepinCommonTestConfig(),null,null,mockedEntitlementCurator,mockedConsumerCurator,null,null,null,mockedActivationKeyRules,null);
  ConsumerResource consumerResource=new ConsumerResource(mockedConsumerCurator,null,null,null,mockedEntitlementCurator,null,mockedEntitlementCertServiceAdapter,null,null,null,null,null,null,null,poolManager,null,null,null,null,null,null,null,null,new CandlepinCommonTestConfig(),null,null,null,consumerBindUtil);
  consumerResource.regenerateEntitlementCertificates(consumer.getUuid(),"String_Node_Str",false);
}

Fixed version (ground truth):
@Test(expected=RuntimeException.class) public void testExceptionFromCertGen() throws Exception {
  Consumer consumer=createConsumer();
  Entitlement e=Mockito.mock(Entitlement.class);
  Pool p=Mockito.mock(Pool.class);
  Subscription s=Mockito.mock(Subscription.class);
  when(e.getPool()).thenReturn(p);
  when(p.getSubscriptionId()).thenReturn("String_Node_Str");
  when(mockedConsumerCurator.verifyAndLookupConsumer(consumer.getUuid())).thenReturn(consumer);
  when(mockedEntitlementCurator.find(eq("String_Node_Str"))).thenReturn(e);
  when(mockedSubscriptionServiceAdapter.getSubscription(eq("String_Node_Str"))).thenReturn(s);
  when(mockedEntitlementCertServiceAdapter.generateEntitlementCert(any(Entitlement.class),any(Product.class))).thenThrow(new IOException());
  CandlepinPoolManager poolManager=new CandlepinPoolManager(null,mockedSubscriptionServiceAdapter,null,mockedEntitlementCertServiceAdapter,null,null,new CandlepinCommonTestConfig(),null,null,mockedEntitlementCurator,mockedConsumerCurator,null,null,null,mockedActivationKeyRules,null,null);
  ConsumerResource consumerResource=new ConsumerResource(mockedConsumerCurator,null,null,null,mockedEntitlementCurator,null,mockedEntitlementCertServiceAdapter,null,null,null,null,null,null,null,poolManager,null,null,null,null,null,null,null,null,new CandlepinCommonTestConfig(),null,null,null,consumerBindUtil);
  consumerResource.regenerateEntitlementCertificates(consumer.getUuid(),"String_Node_Str",false);
}
Program: 49368
Project: 49368
Buggy source:
@Test public void testNewProductCreated() throws Exception {
  Product product=TestUtil.createProduct(owner);
  String json=getJsonForProduct(product);
  Reader reader=new StringReader(json);
  Product created=importer.createObject(mapper,reader);
  Set<Product> storeThese=new HashSet<Product>();
  storeThese.add(created);
  when(productCuratorMock.lookupById(product.getOwner(),product.getId())).thenReturn(null);
  importer.store(storeThese,owner);
}

Fixed version (ground truth):
@Test public void testNewProductCreated() throws Exception {
  Product product=TestUtil.createProduct(owner);
  String json=getJsonForProduct(product);
  Reader reader=new StringReader(json);
  Product created=importer.createObject(mapper,reader,owner);
  Set<Product> storeThese=new HashSet<Product>();
  storeThese.add(created);
}
Program: 49369
Project: 49369
Buggy source:
@Test public void testVendorSetToUnknown() throws Exception {
  Product product=TestUtil.createProduct(owner);
  addNoVendorContentTo(product);
  String json=getJsonForProduct(product);
  Reader reader=new StringReader(json);
  Product created=importer.createObject(mapper,reader);
  Content c=created.getProductContent().iterator().next().getContent();
  Set<Product> storeThese=new HashSet<Product>();
  storeThese.add(created);
  importer.store(storeThese,owner);
  verify(contentCuratorMock).createOrUpdate(c);
  assertEquals("String_Node_Str",c.getVendor());
}

Fixed version (ground truth):
@Test public void testVendorSetToUnknown() throws Exception {
  Product product=TestUtil.createProduct(owner);
  addNoVendorContentTo(product);
  String json=getJsonForProduct(product);
  Reader reader=new StringReader(json);
  Product created=importer.createObject(mapper,reader,owner);
  Content c=created.getProductContent().iterator().next().getContent();
  Set<Product> storeThese=new HashSet<Product>();
  storeThese.add(created);
  assertEquals("String_Node_Str",c.getVendor());
}
Program: 49370
Project: 49370
Buggy source:
@Test public void testExistingProductUpdated() throws Exception {
  Product product=TestUtil.createProduct(owner);
  String json=getJsonForProduct(product);
  Reader reader=new StringReader(json);
  Product created=importer.createObject(mapper,reader);
  String newProductName="String_Node_Str";
  created.setName(newProductName);
  Set<Product> storeThese=new HashSet<Product>();
  storeThese.add(created);
  when(productCuratorMock.lookupById(product.getOwner(),product.getId())).thenReturn(product);
  importer.store(storeThese,owner);
}

Fixed version (ground truth):
@Test public void testExistingProductUpdated() throws Exception {
  Product product=TestUtil.createProduct(owner);
  String json=getJsonForProduct(product);
  Reader reader=new StringReader(json);
  Product created=importer.createObject(mapper,reader,owner);
  String newProductName="String_Node_Str";
  created.setName(newProductName);
  Set<Product> storeThese=new HashSet<Product>();
  storeThese.add(created);
  when(productCuratorMock.lookupById(product.getOwner(),product.getId())).thenReturn(product);
}
Program: 49371
Project: 49371
Buggy source:
@Test public void testContentCreated() throws Exception {
  Product product=TestUtil.createProduct(owner);
  addContentTo(product);
  String json=getJsonForProduct(product);
  Reader reader=new StringReader(json);
  Product created=importer.createObject(mapper,reader);
  Content c=created.getProductContent().iterator().next().getContent();
  Set<Product> storeThese=new HashSet<Product>();
  storeThese.add(created);
  importer.store(storeThese,owner);
  verify(contentCuratorMock).createOrUpdate(c);
  assertEquals(new Long(1),c.getMetadataExpire());
}

Fixed version (ground truth):
@Test public void testContentCreated() throws Exception {
  Product product=TestUtil.createProduct(owner);
  addContentTo(product);
  String json=getJsonForProduct(product);
  Reader reader=new StringReader(json);
  Product created=importer.createObject(mapper,reader,owner);
  Content c=created.getProductContent().iterator().next().getContent();
  Set<Product> storeThese=new HashSet<Product>();
  storeThese.add(created);
  assertEquals(new Long(1),c.getMetadataExpire());
}
Program: 49372
Project: 49372
Buggy source:
@Test public void testExistingProductContentAdded() throws Exception {
  Owner owner=new Owner("String_Node_Str");
  Product oldProduct=TestUtil.createProduct("String_Node_Str","String_Node_Str",owner);
  Product newProduct=TestUtil.createProduct("String_Node_Str","String_Node_Str",owner);
  addContentTo(newProduct);
  Content c=newProduct.getProductContent().iterator().next().getContent();
  when(productCuratorMock.find(oldProduct.getUuid())).thenReturn(oldProduct);
  Set<Product> storeThese=new HashSet<Product>();
  storeThese.add(newProduct);
  importer.store(storeThese,owner);
}

Fixed version (ground truth):
@Test public void testExistingProductContentAdded() throws Exception {
  Owner owner=new Owner("String_Node_Str");
  Product oldProduct=TestUtil.createProduct("String_Node_Str","String_Node_Str",owner);
  Product newProduct=TestUtil.createProduct("String_Node_Str","String_Node_Str",owner);
  addContentTo(newProduct);
  Content c=newProduct.getProductContent().iterator().next().getContent();
  when(productCuratorMock.find(oldProduct.getUuid())).thenReturn(oldProduct);
  Set<Product> storeThese=new HashSet<Product>();
  storeThese.add(newProduct);
}
Program: 49373
Project: 49373
Buggy source:
@Test public void testCreateObject() throws Exception {
  Product product=TestUtil.createProduct(owner);
  String json=getJsonForProduct(product);
  Reader reader=new StringReader(json);
  Product created=importer.createObject(mapper,reader);
  assertEquals(product.getUuid(),created.getUuid());
  assertEquals(product.getName(),created.getName());
  assertEquals(product.getAttributes(),created.getAttributes());
}

Fixed version (ground truth):
@Test public void testCreateObject() throws Exception {
  Product product=TestUtil.createProduct(owner);
  String json=getJsonForProduct(product);
  Reader reader=new StringReader(json);
  Product created=importer.createObject(mapper,reader,owner);
  assertEquals(product.getUuid(),created.getUuid());
  assertEquals(product.getName(),created.getName());
  assertEquals(product.getAttributes(),created.getAttributes());
}
Program: 49374
Project: 49374
Buggy source:
@JsonIgnore public Set<ProvidedProduct> getDerivedProvidedProductDtos(){
  return this.providedProductDtos;
}

Fixed version (ground truth):
@JsonProperty("String_Node_Str") public Set<ProvidedProduct> getDerivedProvidedProductDtos(){
  Set<ProvidedProduct> prods=new HashSet<ProvidedProduct>();
  if (this.derivedProvidedProductDtos != null) {
    prods.addAll(this.derivedProvidedProductDtos);
  }
  for (  Product p : getDerivedProvidedProducts()) {
    prods.add(new ProvidedProduct(p));
  }
  return prods;
}
Program: 49375
Project: 49375
Buggy source:
@JsonProperty("String_Node_Str") public Set<ProvidedProduct> getProvidedProductDtos(){
  Set<ProvidedProduct> prods=new HashSet<ProvidedProduct>();
  for (  Product p : getProvidedProducts()) {
    prods.add(new ProvidedProduct(p));
  }
  return prods;
}

Fixed version (ground truth):
@JsonProperty("String_Node_Str") public Set<ProvidedProduct> getProvidedProductDtos(){
  Set<ProvidedProduct> prods=new HashSet<ProvidedProduct>();
  if (this.providedProductDtos != null) {
    prods.addAll(this.providedProductDtos);
  }
  for (  Product p : getProvidedProducts()) {
    prods.add(new ProvidedProduct(p));
  }
  return prods;
}
Program: 49377
Project: 49377
Buggy source:
@Test public void getUpstreamCertSimple(){
  Entitlement e=TestUtil.createEntitlement();
  e.setId("String_Node_Str");
  when(entitlementCurator.find(eq(e.getId()))).thenReturn(e);
  String expected="String_Node_Str";
  when(subResource.getSubCertAsPem(eq(e.getPool().getSubscriptionId()))).thenReturn(expected);
  String result=entResource.getUpstreamCert(e.getId());
  assertEquals(expected,result);
}

Fixed version (ground truth):
@Test public void getUpstreamCertSimple(){
  Entitlement e=TestUtil.createEntitlement();
  e.setId("String_Node_Str");
  EntitlementCertificate entitlementCert=new EntitlementCertificate();
  entitlementCert.setCert("String_Node_Str");
  entitlementCert.setKey("String_Node_Str");
  Set<EntitlementCertificate> certs=new HashSet<EntitlementCertificate>();
  certs.add(entitlementCert);
  e.setCertificates(certs);
  when(entitlementCurator.find(eq(e.getId()))).thenReturn(e);
  String expected="String_Node_Str";
  String result=entResource.getUpstreamCert(e.getId());
  assertEquals(expected,result);
}
Program: 49378
Project: 49378
Buggy source:
@Test public void getUpstreamCertStackSubPool(){
  Entitlement parentEnt=TestUtil.createEntitlement();
  parentEnt.setId("String_Node_Str");
  when(entitlementCurator.findUpstreamEntitlementForStack(consumer,"String_Node_Str")).thenReturn(parentEnt);
  String expected="String_Node_Str";
  when(subResource.getSubCertAsPem(eq(parentEnt.getPool().getSubscriptionId()))).thenReturn(expected);
  Entitlement e=TestUtil.createEntitlement();
  e.setId("String_Node_Str");
  e.getPool().setSourceStack(new SourceStack(consumer,"String_Node_Str"));
  when(entitlementCurator.find(eq(e.getId()))).thenReturn(e);
  String result=entResource.getUpstreamCert(e.getId());
  assertEquals(expected,result);
}

Fixed version (ground truth):
@Test public void getUpstreamCertStackSubPool(){
  Entitlement parentEnt=TestUtil.createEntitlement();
  parentEnt.setId("String_Node_Str");
  EntitlementCertificate entitlementCert=new EntitlementCertificate();
  entitlementCert.setCert("String_Node_Str");
  entitlementCert.setKey("String_Node_Str");
  Set<EntitlementCertificate> certs=new HashSet<EntitlementCertificate>();
  certs.add(entitlementCert);
  parentEnt.setCertificates(certs);
  when(entitlementCurator.findUpstreamEntitlementForStack(consumer,"String_Node_Str")).thenReturn(parentEnt);
  String expected="String_Node_Str";
  Entitlement e=TestUtil.createEntitlement();
  e.setId("String_Node_Str");
  e.getPool().setSourceStack(new SourceStack(consumer,"String_Node_Str"));
  when(entitlementCurator.find(eq(e.getId()))).thenReturn(e);
  String result=entResource.getUpstreamCert(e.getId());
  assertEquals(expected,result);
}