Program: 141995
Project: 141995
Buggy source:
@Test public void moveEncryptedFixtureFromFsToDbAndBack(){
  HybridFileBackedSqlStorageMock.alwaysPutInDatabase();
  HybridFileBackedSqlStorage<FormInstance> userFixtureStorage=CommCareApplication.instance().getFileBackedUserStorage("String_Node_Str",FormInstance.class);
  FormInstance form=userFixtureStorage.getRecordForValues(new String[]{FormInstance.META_ID},new String[]{"String_Node_Str"});
  File dbDir=userFixtureStorage.getDbDirForTesting();
  int fileCountBefore=dbDir.listFiles().length;
  String newName="String_Node_Str";
  form.setName(newName);
  userFixtureStorage.update(form.getID(),form);
  form=userFixtureStorage.getRecordForValues(new String[]{FormInstance.META_ID},new String[]{"String_Node_Str"});
  Assert.assertEquals(newName,form.getName());
  FormInstance form2=userFixtureStorage.getRecordsForValues(new String[]{FormInstance.META_ID},new String[]{"String_Node_Str"}).firstElement();
  Assert.assertEquals(form2.getName(),form.getName());
  clearOrphanedFiles();
  int fileCountAfter=dbDir.listFiles().length;
  Assert.assertTrue(fileCountBefore - fileCountAfter == 1);
  HybridFileBackedSqlStorageMock.alwaysPutInFilesystem();
  newName="String_Node_Str";
  form.setName(newName);
  userFixtureStorage.update(form.getID(),form);
  form=userFixtureStorage.getRecordForValues(new String[]{FormInstance.META_ID},new String[]{"String_Node_Str"});
  Assert.assertEquals(newName,form.getName());
  fileCountAfter=dbDir.listFiles().length;
  Assert.assertTrue(fileCountBefore == fileCountAfter);
  userFixtureStorage.remove(form.getID());
  fileCountAfter=dbDir.listFiles().length;
  Assert.assertTrue(fileCountBefore - fileCountAfter == 1);
}

Fixed version (ground truth):
@Test public void moveEncryptedFixtureFromFsToDbAndBack(){
  HybridFileBackedSqlStorageMock.alwaysPutInDatabase();
  HybridFileBackedSqlStorage<FormInstance> userFixtureStorage=CommCareApplication.instance().getFileBackedUserStorage(HybridFileBackedSqlStorage.FIXTURE_STORAGE_TABLE_NAME,FormInstance.class);
  FormInstance form=userFixtureStorage.getRecordForValues(new String[]{FormInstance.META_ID},new String[]{"String_Node_Str"});
  File dbDir=userFixtureStorage.getDbDirForTesting();
  int fileCountBefore=dbDir.listFiles().length;
  String newName="String_Node_Str";
  form.setName(newName);
  userFixtureStorage.update(form.getID(),form);
  form=userFixtureStorage.getRecordForValues(new String[]{FormInstance.META_ID},new String[]{"String_Node_Str"});
  Assert.assertEquals(newName,form.getName());
  FormInstance form2=userFixtureStorage.getRecordsForValues(new String[]{FormInstance.META_ID},new String[]{"String_Node_Str"}).firstElement();
  Assert.assertEquals(form2.getName(),form.getName());
  clearOrphanedFiles();
  int fileCountAfter=dbDir.listFiles().length;
  Assert.assertTrue(fileCountBefore - fileCountAfter == 1);
  HybridFileBackedSqlStorageMock.alwaysPutInFilesystem();
  newName="String_Node_Str";
  form.setName(newName);
  userFixtureStorage.update(form.getID(),form);
  form=userFixtureStorage.getRecordForValues(new String[]{FormInstance.META_ID},new String[]{"String_Node_Str"});
  Assert.assertEquals(newName,form.getName());
  fileCountAfter=dbDir.listFiles().length;
  Assert.assertTrue(fileCountBefore == fileCountAfter);
  userFixtureStorage.remove(form.getID());
  fileCountAfter=dbDir.listFiles().length;
  Assert.assertTrue(fileCountBefore - fileCountAfter == 1);
}