@Test public void whenGetLatestThenReturnNetwork() { TestObserver<String> testObserver = TestObserver.create(); when(networkDataSource.getAndUpdate(parameter, cacheDataSource)).thenReturn(Maybe.just(NETWORK_DATA)); sut.getLatest(parameter) .subscribe(testObserver); testObserver.assertResult(NETWORK_STRING); verify(networkDataSource).getAndUpdate(parameter, cacheDataSource); verifyZeroInteractions(cacheDataSource); }
@NotNull @Override public Single<M> getLatest(P params) { return networkDataSource.getAndUpdate(params, cacheDataSource) .map(TimeStampedData::getModel) .toSingle(); }
SingleLevelCacheRepository extends BaseRepository<M, P> implements Repository<M, P> { @NotNull @Override public Single<M> getLatest(P params) { return networkDataSource.getAndUpdate(params, cacheDataSource) .map(TimeStampedData::getModel) .toSingle(); } }
SingleLevelCacheRepository extends BaseRepository<M, P> implements Repository<M, P> { @NotNull @Override public Single<M> getLatest(P params) { return networkDataSource.getAndUpdate(params, cacheDataSource) .map(TimeStampedData::getModel) .toSingle(); } SingleLevelCacheRepository(@NotNull DataSource<M, P> networkDataSource, @NotNull MemoryCacheDataSource<M, P> cacheDataSource); }
SingleLevelCacheRepository extends BaseRepository<M, P> implements Repository<M, P> { @NotNull @Override public Single<M> getLatest(P params) { return networkDataSource.getAndUpdate(params, cacheDataSource) .map(TimeStampedData::getModel) .toSingle(); } SingleLevelCacheRepository(@NotNull DataSource<M, P> networkDataSource, @NotNull MemoryCacheDataSource<M, P> cacheDataSource); @NotNull @Override Single<M> get(P params); @NotNull @Override Single<M> getLatest(P params); @SuppressWarnings("WeakerAccess") void setCacheValidity(Long newCacheValidity); void invalidateCache(); }
SingleLevelCacheRepository extends BaseRepository<M, P> implements Repository<M, P> { @NotNull @Override public Single<M> getLatest(P params) { return networkDataSource.getAndUpdate(params, cacheDataSource) .map(TimeStampedData::getModel) .toSingle(); } SingleLevelCacheRepository(@NotNull DataSource<M, P> networkDataSource, @NotNull MemoryCacheDataSource<M, P> cacheDataSource); @NotNull @Override Single<M> get(P params); @NotNull @Override Single<M> getLatest(P params); @SuppressWarnings("WeakerAccess") void setCacheValidity(Long newCacheValidity); void invalidateCache();  }