@Test public void testAddToBatch() { SerializationStrategy<Data, Batch<Data>> serializationStrategy = mock(SerializationStrategy.class); PersistenceStrategy<Data> persistenceStrategy = mock(PersistenceStrategy.class); OnBatchReadyListener<Data, Batch<Data>> onBatchReadyListener = mock(OnBatchReadyListener.class); Context context = RuntimeEnvironment.application; HandlerThread handlerThread = new HandlerThread("test"); handlerThread.start(); Looper looper = handlerThread.getLooper(); ShadowLooper shadowLooper = Shadows.shadowOf(looper); Handler handler = new Handler(looper); BaseBatchingStrategy<Data, Batch<Data>> sizeBatchingStrategy = new SizeBatchingStrategy(5, persistenceStrategy); BatchManager batchController = new BatchManager.Builder<>() .setSerializationStrategy(serializationStrategy) .setBatchingStrategy(sizeBatchingStrategy) .setHandler(handler) .setOnBatchReadyListener(onBatchReadyListener) .build(context); ArrayList<Data> fakeCollection = Utils.fakeCollection(5); when(persistenceStrategy.getData()).thenReturn(fakeCollection); when(persistenceStrategy.getDataSize()).thenReturn(fakeCollection.size()); batchController.addToBatch(fakeCollection); shadowLooper.runToEndOfTasks(); verify(onBatchReadyListener, times(1)).onReady(eq(sizeBatchingStrategy), any(Batch.class)); }
@Override public void addToBatch(final Collection<E> dataCollection) { handler.post(new Runnable() { @Override public void run() { assignEventIds(dataCollection); if (batchingStrategy.isInitialized()) { batchingStrategy.onDataPushed(dataCollection); batchingStrategy.flush(false); } else { throw new IllegalAccessError("BatchingStrategy is not initialized"); } } }); }
BatchManager implements BatchController<E, T> { @Override public void addToBatch(final Collection<E> dataCollection) { handler.post(new Runnable() { @Override public void run() { assignEventIds(dataCollection); if (batchingStrategy.isInitialized()) { batchingStrategy.onDataPushed(dataCollection); batchingStrategy.flush(false); } else { throw new IllegalAccessError("BatchingStrategy is not initialized"); } } }); } }
BatchManager implements BatchController<E, T> { @Override public void addToBatch(final Collection<E> dataCollection) { handler.post(new Runnable() { @Override public void run() { assignEventIds(dataCollection); if (batchingStrategy.isInitialized()) { batchingStrategy.onDataPushed(dataCollection); batchingStrategy.flush(false); } else { throw new IllegalAccessError("BatchingStrategy is not initialized"); } } }); } protected  BatchManager(Builder builder, final Context context); }
BatchManager implements BatchController<E, T> { @Override public void addToBatch(final Collection<E> dataCollection) { handler.post(new Runnable() { @Override public void run() { assignEventIds(dataCollection); if (batchingStrategy.isInitialized()) { batchingStrategy.onDataPushed(dataCollection); batchingStrategy.flush(false); } else { throw new IllegalAccessError("BatchingStrategy is not initialized"); } } }); } protected  BatchManager(Builder builder, final Context context); @Override void addToBatch(final Collection<E> dataCollection); @Override Handler getHandler(); @Override SerializationStrategy<E, T> getSerializationStrategy(); @Override void flush(final boolean forced); void initialize(BatchController<E, T> batchController, Context context,
                           OnBatchReadyListener<E, T> onBatchReadyListener, Handler handler); }
BatchManager implements BatchController<E, T> { @Override public void addToBatch(final Collection<E> dataCollection) { handler.post(new Runnable() { @Override public void run() { assignEventIds(dataCollection); if (batchingStrategy.isInitialized()) { batchingStrategy.onDataPushed(dataCollection); batchingStrategy.flush(false); } else { throw new IllegalAccessError("BatchingStrategy is not initialized"); } } }); } protected  BatchManager(Builder builder, final Context context); @Override void addToBatch(final Collection<E> dataCollection); @Override Handler getHandler(); @Override SerializationStrategy<E, T> getSerializationStrategy(); @Override void flush(final boolean forced); void initialize(BatchController<E, T> batchController, Context context,
                           OnBatchReadyListener<E, T> onBatchReadyListener, Handler handler);  }