@Test public void whenThereAreUpdatedFormsOnServer_sendsUpdatesToNotifier() throws Exception { ServerFormDetails updatedForm = new ServerFormDetails("", "", "", "", "", "", "", false, true); ServerFormDetails oldForm = new ServerFormDetails("", "", "", "", "", "", "", false, false); when(serverFormsDetailsFetcher.fetchFormDetails()).thenReturn(asList( updatedForm, oldForm )); AutoUpdateTaskSpec taskSpec = new AutoUpdateTaskSpec(); Supplier<Boolean> task = taskSpec.getTask(ApplicationProvider.getApplicationContext()); task.get(); verify(notifier).onUpdatesAvailable(asList(updatedForm)); }
@NotNull @Override public Supplier<Boolean> getTask(@NotNull Context context) { DaggerUtils.getComponent(context).inject(this); return () -> { try { List<ServerFormDetails> serverForms = serverFormsDetailsFetcher.fetchFormDetails(); List<ServerFormDetails> updatedForms = serverForms.stream().filter(ServerFormDetails::isUpdated).collect(Collectors.toList()); if (!updatedForms.isEmpty()) { if (preferencesProvider.getGeneralSharedPreferences().getBoolean(KEY_AUTOMATIC_UPDATE, false)) { changeLock.withLock(acquiredLock -> { if (acquiredLock) { final HashMap<ServerFormDetails, String> result = multiFormDownloader.downloadForms(updatedForms, null); notifier.onUpdatesDownloaded(result); } return null; }); } else { notifier.onUpdatesAvailable(updatedForms); } } return true; } catch (FormApiException e) { return true; } }; }
AutoUpdateTaskSpec implements TaskSpec { @NotNull @Override public Supplier<Boolean> getTask(@NotNull Context context) { DaggerUtils.getComponent(context).inject(this); return () -> { try { List<ServerFormDetails> serverForms = serverFormsDetailsFetcher.fetchFormDetails(); List<ServerFormDetails> updatedForms = serverForms.stream().filter(ServerFormDetails::isUpdated).collect(Collectors.toList()); if (!updatedForms.isEmpty()) { if (preferencesProvider.getGeneralSharedPreferences().getBoolean(KEY_AUTOMATIC_UPDATE, false)) { changeLock.withLock(acquiredLock -> { if (acquiredLock) { final HashMap<ServerFormDetails, String> result = multiFormDownloader.downloadForms(updatedForms, null); notifier.onUpdatesDownloaded(result); } return null; }); } else { notifier.onUpdatesAvailable(updatedForms); } } return true; } catch (FormApiException e) { return true; } }; } }
AutoUpdateTaskSpec implements TaskSpec { @NotNull @Override public Supplier<Boolean> getTask(@NotNull Context context) { DaggerUtils.getComponent(context).inject(this); return () -> { try { List<ServerFormDetails> serverForms = serverFormsDetailsFetcher.fetchFormDetails(); List<ServerFormDetails> updatedForms = serverForms.stream().filter(ServerFormDetails::isUpdated).collect(Collectors.toList()); if (!updatedForms.isEmpty()) { if (preferencesProvider.getGeneralSharedPreferences().getBoolean(KEY_AUTOMATIC_UPDATE, false)) { changeLock.withLock(acquiredLock -> { if (acquiredLock) { final HashMap<ServerFormDetails, String> result = multiFormDownloader.downloadForms(updatedForms, null); notifier.onUpdatesDownloaded(result); } return null; }); } else { notifier.onUpdatesAvailable(updatedForms); } } return true; } catch (FormApiException e) { return true; } }; }  }
AutoUpdateTaskSpec implements TaskSpec { @NotNull @Override public Supplier<Boolean> getTask(@NotNull Context context) { DaggerUtils.getComponent(context).inject(this); return () -> { try { List<ServerFormDetails> serverForms = serverFormsDetailsFetcher.fetchFormDetails(); List<ServerFormDetails> updatedForms = serverForms.stream().filter(ServerFormDetails::isUpdated).collect(Collectors.toList()); if (!updatedForms.isEmpty()) { if (preferencesProvider.getGeneralSharedPreferences().getBoolean(KEY_AUTOMATIC_UPDATE, false)) { changeLock.withLock(acquiredLock -> { if (acquiredLock) { final HashMap<ServerFormDetails, String> result = multiFormDownloader.downloadForms(updatedForms, null); notifier.onUpdatesDownloaded(result); } return null; }); } else { notifier.onUpdatesAvailable(updatedForms); } } return true; } catch (FormApiException e) { return true; } }; }  @NotNull @Override Supplier<Boolean> getTask(@NotNull Context context); @NotNull @Override Class<? extends WorkerAdapter> getWorkManagerAdapter(); }
AutoUpdateTaskSpec implements TaskSpec { @NotNull @Override public Supplier<Boolean> getTask(@NotNull Context context) { DaggerUtils.getComponent(context).inject(this); return () -> { try { List<ServerFormDetails> serverForms = serverFormsDetailsFetcher.fetchFormDetails(); List<ServerFormDetails> updatedForms = serverForms.stream().filter(ServerFormDetails::isUpdated).collect(Collectors.toList()); if (!updatedForms.isEmpty()) { if (preferencesProvider.getGeneralSharedPreferences().getBoolean(KEY_AUTOMATIC_UPDATE, false)) { changeLock.withLock(acquiredLock -> { if (acquiredLock) { final HashMap<ServerFormDetails, String> result = multiFormDownloader.downloadForms(updatedForms, null); notifier.onUpdatesDownloaded(result); } return null; }); } else { notifier.onUpdatesAvailable(updatedForms); } } return true; } catch (FormApiException e) { return true; } }; }  @NotNull @Override Supplier<Boolean> getTask(@NotNull Context context); @NotNull @Override Class<? extends WorkerAdapter> getWorkManagerAdapter();  }