@Test public void setsRepositoryToSyncing_runsSync_thenSetsRepositoryToNotSyncingAndNotifies() throws Exception { InOrder inOrder = inOrder(syncStatusRepository, serverFormsSynchronizer); SyncFormsTaskSpec taskSpec = new SyncFormsTaskSpec(); Supplier<Boolean> task = taskSpec.getTask(ApplicationProvider.getApplicationContext()); task.get(); inOrder.verify(syncStatusRepository).startSync(); inOrder.verify(serverFormsSynchronizer).synchronize(); inOrder.verify(syncStatusRepository).finishSync(null); verify(notifier).onSync(null); }
@NotNull @Override public Supplier<Boolean> getTask(@NotNull Context context) { DaggerUtils.getComponent(context).inject(this); return () -> { changeLock.withLock((Function<Boolean, Void>) acquiredLock -> { if (acquiredLock) { syncStatusRepository.startSync(); try { serverFormsSynchronizer.synchronize(); syncStatusRepository.finishSync(null); notifier.onSync(null); analytics.logEvent(AnalyticsEvents.MATCH_EXACTLY_SYNC_COMPLETED, "Success"); } catch (FormApiException e) { syncStatusRepository.finishSync(e); notifier.onSync(e); analytics.logEvent(AnalyticsEvents.MATCH_EXACTLY_SYNC_COMPLETED, e.getType().toString()); } } return null; }); return true; }; }
SyncFormsTaskSpec implements TaskSpec { @NotNull @Override public Supplier<Boolean> getTask(@NotNull Context context) { DaggerUtils.getComponent(context).inject(this); return () -> { changeLock.withLock((Function<Boolean, Void>) acquiredLock -> { if (acquiredLock) { syncStatusRepository.startSync(); try { serverFormsSynchronizer.synchronize(); syncStatusRepository.finishSync(null); notifier.onSync(null); analytics.logEvent(AnalyticsEvents.MATCH_EXACTLY_SYNC_COMPLETED, "Success"); } catch (FormApiException e) { syncStatusRepository.finishSync(e); notifier.onSync(e); analytics.logEvent(AnalyticsEvents.MATCH_EXACTLY_SYNC_COMPLETED, e.getType().toString()); } } return null; }); return true; }; } }
SyncFormsTaskSpec implements TaskSpec { @NotNull @Override public Supplier<Boolean> getTask(@NotNull Context context) { DaggerUtils.getComponent(context).inject(this); return () -> { changeLock.withLock((Function<Boolean, Void>) acquiredLock -> { if (acquiredLock) { syncStatusRepository.startSync(); try { serverFormsSynchronizer.synchronize(); syncStatusRepository.finishSync(null); notifier.onSync(null); analytics.logEvent(AnalyticsEvents.MATCH_EXACTLY_SYNC_COMPLETED, "Success"); } catch (FormApiException e) { syncStatusRepository.finishSync(e); notifier.onSync(e); analytics.logEvent(AnalyticsEvents.MATCH_EXACTLY_SYNC_COMPLETED, e.getType().toString()); } } return null; }); return true; }; }  }
SyncFormsTaskSpec implements TaskSpec { @NotNull @Override public Supplier<Boolean> getTask(@NotNull Context context) { DaggerUtils.getComponent(context).inject(this); return () -> { changeLock.withLock((Function<Boolean, Void>) acquiredLock -> { if (acquiredLock) { syncStatusRepository.startSync(); try { serverFormsSynchronizer.synchronize(); syncStatusRepository.finishSync(null); notifier.onSync(null); analytics.logEvent(AnalyticsEvents.MATCH_EXACTLY_SYNC_COMPLETED, "Success"); } catch (FormApiException e) { syncStatusRepository.finishSync(e); notifier.onSync(e); analytics.logEvent(AnalyticsEvents.MATCH_EXACTLY_SYNC_COMPLETED, e.getType().toString()); } } return null; }); return true; }; }  @NotNull @Override Supplier<Boolean> getTask(@NotNull Context context); @NotNull @Override Class<? extends WorkerAdapter> getWorkManagerAdapter(); }
SyncFormsTaskSpec implements TaskSpec { @NotNull @Override public Supplier<Boolean> getTask(@NotNull Context context) { DaggerUtils.getComponent(context).inject(this); return () -> { changeLock.withLock((Function<Boolean, Void>) acquiredLock -> { if (acquiredLock) { syncStatusRepository.startSync(); try { serverFormsSynchronizer.synchronize(); syncStatusRepository.finishSync(null); notifier.onSync(null); analytics.logEvent(AnalyticsEvents.MATCH_EXACTLY_SYNC_COMPLETED, "Success"); } catch (FormApiException e) { syncStatusRepository.finishSync(e); notifier.onSync(e); analytics.logEvent(AnalyticsEvents.MATCH_EXACTLY_SYNC_COMPLETED, e.getType().toString()); } } return null; }); return true; }; }  @NotNull @Override Supplier<Boolean> getTask(@NotNull Context context); @NotNull @Override Class<? extends WorkerAdapter> getWorkManagerAdapter();  }