RemoteData extends AirshipComponent { @WorkerThread void onNewData(@NonNull final Set<RemoteDataPayload> payloads, final @Nullable String lastModified, final @NonNull JsonMap metadata) { backgroundHandler.post(new Runnable() { @Override public void run() { if (!dataStore.deletePayloads()) { Logger.error("Unable to delete existing payload data"); return; } if (!dataStore.savePayloads(payloads)) { Logger.error("Unable to save remote data payloads"); } preferenceDataStore.put(LAST_REFRESH_METADATA, metadata); preferenceDataStore.put(LAST_MODIFIED_KEY, lastModified); payloadUpdates.onNext(payloads); } }); } RemoteData(@NonNull Context context, @NonNull PreferenceDataStore preferenceDataStore,
                      @NonNull AirshipConfigOptions configOptions, @NonNull ActivityMonitor activityMonitor,
                      @NonNull PushManager pushManager, @NonNull LocaleManager localeManager); @VisibleForTesting  RemoteData(@NonNull Context context, @NonNull PreferenceDataStore preferenceDataStore,
               @NonNull AirshipConfigOptions configOptions, @NonNull ActivityMonitor activityMonitor,
               @NonNull JobDispatcher dispatcher, @NonNull LocaleManager localeManager,
               @NonNull PushManager pushManager, @NonNull Clock clock); @WorkerThread @JobInfo.JobResult @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) int onPerformJob(@NonNull UAirship airship, @NonNull JobInfo jobInfo); void setForegroundRefreshInterval(long milliseconds); long getForegroundRefreshInterval(); void refresh(); @NonNull Observable<RemoteDataPayload> payloadsForType(final @NonNull String type); @NonNull Observable<Collection<RemoteDataPayload>> payloadsForTypes(@NonNull String... types); @NonNull Observable<Collection<RemoteDataPayload>> payloadsForTypes(@NonNull final Collection<String> types); boolean isMetadataCurrent(@NonNull JsonMap jsonMap); boolean isLastMetadataCurrent(); @NonNull JsonMap getLastMetadata();  }
@Test public void testHandleRefreshResponse() { final Set<RemoteDataPayload> subscribedPayloads = new HashSet<>(); remoteData.payloadUpdates.subscribe(new Subscriber<Set<RemoteDataPayload>>() { @Override public void onNext(@NonNull Set<RemoteDataPayload> payloads) { subscribedPayloads.addAll(payloads); } }); remoteData.onNewData(asSet(payload, otherPayload), "lastModified", JsonMap.EMPTY_MAP); runLooperTasks(); Assert.assertEquals(asSet(payload, otherPayload), subscribedPayloads); Assert.assertEquals(remoteData.dataStore.getPayloads(), asSet(payload, otherPayload)); subscribedPayloads.clear(); remoteData.onNewData(asSet(otherPayload), "lastModified", JsonMap.EMPTY_MAP); runLooperTasks(); Assert.assertEquals(asSet(otherPayload), subscribedPayloads); Assert.assertEquals(remoteData.dataStore.getPayloads(), asSet(otherPayload)); }