Program: 81204
Project: 81204
Buggy source:
/** 
 * Test that persist success is not called until finish is called.
 * @throws IOException
 * @throws SerializeException
 */
@Test public void testPersistSuccessNotCalledMoreThanOnce() throws IOException, SerializeException {
  File file=createRandomFile();
  HandlerThread handlerThread=new HandlerThread(createRandomString());
  handlerThread.start();
  Looper looper=handlerThread.getLooper();
  ShadowLooper shadowLooper=Shadows.shadowOf(looper);
  Handler handler=new Handler(looper);
  SizeBatchingStrategy strategy=mock(SizeBatchingStrategy.class);
  SerializationStrategy serializationStrategy=new GsonSerializationStrategy();
  BatchManager.registerBuiltInTypes(serializationStrategy);
  serializationStrategy.build();
  PersistedBatchCallback persistedBatchCallback=mock(PersistedBatchCallback.class);
  PersistedBatchReadyListener persistedBatchReadyListener=new PersistedBatchReadyListener(file,serializationStrategy,handler,persistedBatchCallback);
  SizeBatchingStrategy.SizeBatch<Data> firstBatch=new SizeBatchingStrategy.SizeBatch<>(Utils.fakeCollection(5),5);
  persistedBatchReadyListener.onReady(strategy,firstBatch);
  SizeBatchingStrategy.SizeBatch<Data> subsequentBatch=new SizeBatchingStrategy.SizeBatch<>(Utils.fakeCollection(5),5);
  persistedBatchReadyListener.onReady(strategy,subsequentBatch);
  subsequentBatch=new SizeBatchingStrategy.SizeBatch<>(Utils.fakeCollection(5),5);
  persistedBatchReadyListener.onReady(strategy,subsequentBatch);
  subsequentBatch=new SizeBatchingStrategy.SizeBatch<>(Utils.fakeCollection(5),5);
  persistedBatchReadyListener.onReady(strategy,subsequentBatch);
  subsequentBatch=new SizeBatchingStrategy.SizeBatch<>(Utils.fakeCollection(5),5);
  persistedBatchReadyListener.onReady(strategy,subsequentBatch);
  shadowLooper.runToEndOfTasks();
  verify(persistedBatchCallback,times(1)).onPersistSuccess(firstBatch);
  persistedBatchReadyListener.finish(firstBatch);
  shadowLooper.runToEndOfTasks();
  verify(persistedBatchCallback,times(2)).onPersistSuccess(firstBatch);
  persistedBatchReadyListener.finish(firstBatch);
  shadowLooper.runToEndOfTasks();
  verify(persistedBatchCallback,times(3)).onPersistSuccess(firstBatch);
}

Fixed version (ground truth):
/** 
 * Test that persist success is not called until finish is called.
 * @throws IOException
 * @throws SerializeException
 */
@Test public void testPersistSuccessNotCalledMoreThanOnce() throws IOException, SerializeException {
  File file=createRandomFile();
  HandlerThread handlerThread=new HandlerThread(createRandomString());
  handlerThread.start();
  Looper looper=handlerThread.getLooper();
  ShadowLooper shadowLooper=Shadows.shadowOf(looper);
  Handler handler=new Handler(looper);
  SizeBatchingStrategy strategy=mock(SizeBatchingStrategy.class);
  SerializationStrategy serializationStrategy=new GsonSerializationStrategy();
  BatchManager.registerBuiltInTypes(serializationStrategy);
  serializationStrategy.build();
  PersistedBatchCallback persistedBatchCallback=mock(PersistedBatchCallback.class);
  PersistedBatchReadyListener persistedBatchReadyListener=new PersistedBatchReadyListener(file,serializationStrategy,handler,persistedBatchCallback);
  SizeBatchingStrategy.SizeBatch<Data> firstBatch=new SizeBatchingStrategy.SizeBatch<>(Utils.fakeCollection(5),5);
  persistedBatchReadyListener.onReady(strategy,firstBatch);
  SizeBatchingStrategy.SizeBatch<Data> secondBatch=new SizeBatchingStrategy.SizeBatch<>(Utils.fakeCollection(5),5);
  persistedBatchReadyListener.onReady(strategy,secondBatch);
  SizeBatchingStrategy.SizeBatch<Data> thirdBatch=new SizeBatchingStrategy.SizeBatch<>(Utils.fakeCollection(5),5);
  persistedBatchReadyListener.onReady(strategy,thirdBatch);
  SizeBatchingStrategy.SizeBatch<Data> fourthBatch=new SizeBatchingStrategy.SizeBatch<>(Utils.fakeCollection(5),5);
  persistedBatchReadyListener.onReady(strategy,fourthBatch);
  shadowLooper.runToEndOfTasks();
  verify(persistedBatchCallback,times(1)).onPersistSuccess(firstBatch);
  persistedBatchReadyListener.finish(firstBatch);
  shadowLooper.runToEndOfTasks();
  verify(persistedBatchCallback,times(1)).onPersistSuccess(secondBatch);
  persistedBatchReadyListener.finish(secondBatch);
  shadowLooper.runToEndOfTasks();
  verify(persistedBatchCallback,times(1)).onPersistSuccess(thirdBatch);
  verifyNoMoreInteractions(persistedBatchCallback);
}