DataProviderCache { public List<Speaker> getSpeakers() { if (speakersFetchedTime != null && speakersFetchedTime.plusMinutes(CACHE_DURATION_MN).isAfter(LocalDateTime.now())) { Timber.d("Get speakers from cache"); return speakers; } return null; }  List<Session> getSessions(); void saveSessions(List<Session> sessions); List<Speaker> getSpeakers(); void saveSpeakers(List<Speaker> speakers);  }
@Test public void should_return_speakers_when_cache_time_is_still_active() { cache.speakersFetchedTime = LocalDateTime.now(); cache.speakers = speakers; List<Speaker> result = cache.getSpeakers(); assertThat(result).isEqualTo(speakers); }
@Test public void should_return_null_speakers_when_cache_has_expired() { cache.speakersFetchedTime = LocalDateTime.now().minusYears(1); cache.speakers = speakers; List<Speaker> result = cache.getSpeakers(); assertThat(result).isNull(); }