@Test public void get_whenBothCachesAreEmpty_isEmpty() { when(storageClient.read(FetchEligibleCampaignsResponse.parser())) .thenReturn(Maybe.error(new FileNotFoundException())); TestSubscriber<FetchEligibleCampaignsResponse> subscriber = campaignCacheClient.get().toFlowable().test(); subscriber.assertNoValues(); }
public Maybe<FetchEligibleCampaignsResponse> get() { Maybe<FetchEligibleCampaignsResponse> readFromCache = Maybe.fromCallable(() -> cachedResponse); Maybe<FetchEligibleCampaignsResponse> readFromStorage = storageClient .read(FetchEligibleCampaignsResponse.parser()) .doOnSuccess(response -> cachedResponse = response); return readFromCache .switchIfEmpty(readFromStorage) .filter(this::isResponseValid) .doOnError(s -> cachedResponse = null); }
CampaignCacheClient { public Maybe<FetchEligibleCampaignsResponse> get() { Maybe<FetchEligibleCampaignsResponse> readFromCache = Maybe.fromCallable(() -> cachedResponse); Maybe<FetchEligibleCampaignsResponse> readFromStorage = storageClient .read(FetchEligibleCampaignsResponse.parser()) .doOnSuccess(response -> cachedResponse = response); return readFromCache .switchIfEmpty(readFromStorage) .filter(this::isResponseValid) .doOnError(s -> cachedResponse = null); } }
CampaignCacheClient { public Maybe<FetchEligibleCampaignsResponse> get() { Maybe<FetchEligibleCampaignsResponse> readFromCache = Maybe.fromCallable(() -> cachedResponse); Maybe<FetchEligibleCampaignsResponse> readFromStorage = storageClient .read(FetchEligibleCampaignsResponse.parser()) .doOnSuccess(response -> cachedResponse = response); return readFromCache .switchIfEmpty(readFromStorage) .filter(this::isResponseValid) .doOnError(s -> cachedResponse = null); } @Inject  CampaignCacheClient(
      @CampaignCache ProtoStorageClient storageClient, Application application, Clock clock); }
CampaignCacheClient { public Maybe<FetchEligibleCampaignsResponse> get() { Maybe<FetchEligibleCampaignsResponse> readFromCache = Maybe.fromCallable(() -> cachedResponse); Maybe<FetchEligibleCampaignsResponse> readFromStorage = storageClient .read(FetchEligibleCampaignsResponse.parser()) .doOnSuccess(response -> cachedResponse = response); return readFromCache .switchIfEmpty(readFromStorage) .filter(this::isResponseValid) .doOnError(s -> cachedResponse = null); } @Inject  CampaignCacheClient(
      @CampaignCache ProtoStorageClient storageClient, Application application, Clock clock); Completable put(FetchEligibleCampaignsResponse fetchEligibleCampaignsResponse); Maybe<FetchEligibleCampaignsResponse> get(); }
CampaignCacheClient { public Maybe<FetchEligibleCampaignsResponse> get() { Maybe<FetchEligibleCampaignsResponse> readFromCache = Maybe.fromCallable(() -> cachedResponse); Maybe<FetchEligibleCampaignsResponse> readFromStorage = storageClient .read(FetchEligibleCampaignsResponse.parser()) .doOnSuccess(response -> cachedResponse = response); return readFromCache .switchIfEmpty(readFromStorage) .filter(this::isResponseValid) .doOnError(s -> cachedResponse = null); } @Inject  CampaignCacheClient(
      @CampaignCache ProtoStorageClient storageClient, Application application, Clock clock); Completable put(FetchEligibleCampaignsResponse fetchEligibleCampaignsResponse); Maybe<FetchEligibleCampaignsResponse> get();  }