Program: 152445
Project: 152445
Buggy source:
public void testPhotoStoreCleanup() throws IOException {
  SynchronousContactsProvider2 provider=(SynchronousContactsProvider2)mActor.provider;
  provider.cleanupPhotoStore();
  long rawContactId1=createRawContactWithName();
  long contactId1=queryContactId(rawContactId1);
  long dataId1=ContentUris.parseId(insertPhoto(rawContactId1,R.drawable.earth_normal));
  long photoFileId1=getStoredLongValue(ContentUris.withAppendedId(Data.CONTENT_URI,dataId1),Photo.PHOTO_FILE_ID);
  long rawContactId2=createRawContactWithName();
  long contactId2=queryContactId(rawContactId2);
  long dataId2=ContentUris.parseId(insertPhoto(rawContactId2,R.drawable.earth_normal));
  long photoFileId2=getStoredLongValue(ContentUris.withAppendedId(Data.CONTENT_URI,dataId2),Photo.PHOTO_FILE_ID);
  ContentValues values=new ContentValues();
  values.put(Data.RAW_CONTACT_ID,rawContactId2);
  values.put(Data.MIMETYPE,Photo.CONTENT_ITEM_TYPE);
  values.put(Photo.PHOTO,loadPhotoFromResource(R.drawable.earth_huge,PhotoSize.ORIGINAL));
  assertEquals(1,mResolver.update(Data.CONTENT_URI,values,Data._ID + "String_Node_Str",new String[]{String.valueOf(dataId2)}));
  long replacementPhotoFileId=getStoredLongValue(ContentUris.withAppendedId(Data.CONTENT_URI,dataId2),Photo.PHOTO_FILE_ID);
  long bogusFileId=1234567;
  long rawContactId3=createRawContactWithName();
  long contactId3=queryContactId(rawContactId3);
  values.clear();
  values.put(Data.RAW_CONTACT_ID,rawContactId3);
  values.put(Data.MIMETYPE,Photo.CONTENT_ITEM_TYPE);
  values.put(Photo.PHOTO,loadPhotoFromResource(R.drawable.earth_normal,PhotoSize.THUMBNAIL));
  values.put(Photo.PHOTO_FILE_ID,bogusFileId);
  values.put(DataRowHandlerForPhoto.SKIP_PROCESSING_KEY,true);
  mResolver.insert(Data.CONTENT_URI,values);
  PhotoStore photoStore=provider.getPhotoStore();
  long bogusPhotoId=photoStore.insert(new PhotoProcessor(loadPhotoFromResource(R.drawable.earth_huge,PhotoSize.ORIGINAL),256,96));
  provider.cleanupPhotoStore();
  assertEquals(photoFileId1,(long)getStoredLongValue(ContentUris.withAppendedId(Contacts.CONTENT_URI,contactId1),Contacts.PHOTO_FILE_ID));
  assertEquals(replacementPhotoFileId,(long)getStoredLongValue(ContentUris.withAppendedId(Contacts.CONTENT_URI,contactId2),Contacts.PHOTO_FILE_ID));
  assertNull(photoStore.get(photoFileId2));
  assertNull(getStoredValue(ContentUris.withAppendedId(Contacts.CONTENT_URI,contactId3),Contacts.PHOTO_FILE_ID));
  assertNull(photoStore.get(bogusPhotoId));
}

Fixed version (ground truth):
public void testPhotoStoreCleanup() throws IOException {
  SynchronousContactsProvider2 provider=(SynchronousContactsProvider2)mActor.provider;
  PhotoStore photoStore=provider.getPhotoStore();
  provider.cleanupPhotoStore();
  long rawContactId1=createRawContactWithName();
  long contactId1=queryContactId(rawContactId1);
  long dataId1=ContentUris.parseId(insertPhoto(rawContactId1,R.drawable.earth_normal));
  long photoFileId1=getStoredLongValue(ContentUris.withAppendedId(Data.CONTENT_URI,dataId1),Photo.PHOTO_FILE_ID);
  long rawContactId2=createRawContactWithName();
  long contactId2=queryContactId(rawContactId2);
  long dataId2=ContentUris.parseId(insertPhoto(rawContactId2,R.drawable.earth_normal));
  long photoFileId2=getStoredLongValue(ContentUris.withAppendedId(Data.CONTENT_URI,dataId2),Photo.PHOTO_FILE_ID);
  ContentValues values=new ContentValues();
  values.put(Data.RAW_CONTACT_ID,rawContactId2);
  values.put(Data.MIMETYPE,Photo.CONTENT_ITEM_TYPE);
  values.put(Photo.PHOTO,loadPhotoFromResource(R.drawable.earth_huge,PhotoSize.ORIGINAL));
  assertEquals(1,mResolver.update(Data.CONTENT_URI,values,Data._ID + "String_Node_Str",new String[]{String.valueOf(dataId2)}));
  long replacementPhotoFileId=getStoredLongValue(ContentUris.withAppendedId(Data.CONTENT_URI,dataId2),Photo.PHOTO_FILE_ID);
  long bogusFileId=1234567;
  long rawContactId3=createRawContactWithName();
  long contactId3=queryContactId(rawContactId3);
  values.clear();
  values.put(Data.RAW_CONTACT_ID,rawContactId3);
  values.put(Data.MIMETYPE,Photo.CONTENT_ITEM_TYPE);
  values.put(Photo.PHOTO,loadPhotoFromResource(R.drawable.earth_normal,PhotoSize.THUMBNAIL));
  values.put(Photo.PHOTO_FILE_ID,bogusFileId);
  values.put(DataRowHandlerForPhoto.SKIP_PROCESSING_KEY,true);
  mResolver.insert(Data.CONTENT_URI,values);
  Account socialAccount=new Account("String_Node_Str","String_Node_Str");
  long rawContactId4=createRawContactWithName(socialAccount);
  Uri streamItemUri=insertStreamItem(rawContactId4,buildGenericStreamItemValues(),socialAccount);
  long streamItemId=ContentUris.parseId(streamItemUri);
  Uri streamItemPhotoUri=insertStreamItemPhoto(streamItemId,buildGenericStreamItemPhotoValues(0),socialAccount);
  long streamItemPhotoFileId=getStoredLongValue(streamItemPhotoUri,StreamItemPhotos.PHOTO_FILE_ID);
  photoStore.remove(streamItemPhotoFileId);
  long bogusPhotoId=photoStore.insert(new PhotoProcessor(loadPhotoFromResource(R.drawable.earth_huge,PhotoSize.ORIGINAL),256,96));
  provider.cleanupPhotoStore();
  assertEquals(photoFileId1,(long)getStoredLongValue(ContentUris.withAppendedId(Contacts.CONTENT_URI,contactId1),Contacts.PHOTO_FILE_ID));
  assertEquals(replacementPhotoFileId,(long)getStoredLongValue(ContentUris.withAppendedId(Contacts.CONTENT_URI,contactId2),Contacts.PHOTO_FILE_ID));
  assertNull(photoStore.get(photoFileId2));
  assertNull(getStoredValue(ContentUris.withAppendedId(Contacts.CONTENT_URI,contactId3),Contacts.PHOTO_FILE_ID));
  assertNull(photoStore.get(bogusPhotoId));
  assertStoredValues(Uri.withAppendedPath(ContentUris.withAppendedId(StreamItems.CONTENT_URI,streamItemId),StreamItems.StreamItemPhotos.CONTENT_DIRECTORY),new ContentValues[0]);
}