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