### Question:
ImpressionStorageClient { public Single<Boolean> isImpressed(CampaignProto.ThickContent content) { String campaignId = content.getPayloadCase().equals(CampaignProto.ThickContent.PayloadCase.VANILLA_PAYLOAD) ? content.getVanillaPayload().getCampaignId() : content.getExperimentalPayload().getCampaignId(); return getAllImpressions() .map(CampaignImpressionList::getAlreadySeenCampaignsList) .flatMapObservable(Observable::fromIterable) .map(CampaignImpression::getCampaignId) .contains(campaignId); } @Inject  ImpressionStorageClient(@ImpressionStore ProtoStorageClient storageClient); Completable storeImpression(CampaignImpression impression); Maybe<CampaignImpressionList> getAllImpressions(); Single<Boolean> isImpressed(CampaignProto.ThickContent content); Completable clearImpressions(FetchEligibleCampaignsResponse response);  }### Answer:
@Test public void isImpressed_ifCampaignImpressed_isTrue() { TestSubscriber<Boolean> subscriber = impressionStorageClient.isImpressed(vanillaCampaign).toFlowable().test(); assertThat(subscriber.getEvents().get(0)).containsExactly(true); }
@Test public void isImpressed_ifCampaignNotImpressed_isFalse() { TestSubscriber<Boolean> subscriber = impressionStorageClient .isImpressed( ThickContent.newBuilder() .setVanillaPayload( CampaignProto.VanillaCampaignPayload.newBuilder().setCampaignId("WALRUS")) .build()) .toFlowable() .test(); assertThat(subscriber.getEvents().get(0)).containsExactly(false); }
@Test public void isImpressed_ifExperimentImpressed_isTrue() { when(storageClient.read(any(CampaignImpressionsParser.class))) .thenReturn(Maybe.fromCallable(() -> experimentImpressionList)); TestSubscriber<Boolean> subscriber = impressionStorageClient.isImpressed(experimentalCampaign).toFlowable().test(); assertThat(subscriber.getEvents().get(0)).containsExactly(true); }
@Test public void isImpressed_ifExperimentNotImpressed_isFalse() { TestSubscriber<Boolean> subscriber = impressionStorageClient.isImpressed(experimentalCampaign).toFlowable().test(); assertThat(subscriber.getEvents().get(0)).containsExactly(false); }
@Test public void isImpressed_ifNoCampaigns_isFalse() { when(storageClient.read(any(CampaignImpressionsParser.class))).thenReturn(Maybe.empty()); TestSubscriber<Boolean> subscriber = impressionStorageClient.isImpressed(vanillaCampaign).toFlowable().test(); assertThat(subscriber.getEvents().get(0)).containsExactly(false); }
@Test public void isImpressed_onError_notifiesError() { when(storageClient.read(any(CampaignImpressionsParser.class))) .thenReturn(Maybe.error(new IOException())); TestSubscriber<Boolean> subscriber = impressionStorageClient.isImpressed(vanillaCampaign).toFlowable().test(); subscriber.assertError(IOException.class); }