@Override public void onDataSetChanged(IEventRepo repo) { Timber.d("startLoadingData"); Observable<IEvent> events = repo.getEventsSubscribedOnProperScheduler(); Timber.i("archive"); events.subscribe( new EventRepoSerializerToFileDecorator(repoAccessor, new EventRepoSerializer(clock))); Timber.i("set next alarm on %s at %d", alarmGenerator, clock.hour()); alarmGenerator.generate(repo.getEventsSubscribedOnProperScheduler(), clock.now(), clock.hour()); }
@Before public void setUp() { today = new LocalDate(2015, Date.FEBRUARY, 8); when(clock.now()).thenReturn(today); Scheduler s = Schedulers.immediate(); sut = new SortedEventsLoader(repo, s, clock); }
@Test public void secondLoadRepoIsNotCachedIfDateChanges() { when(repo.getModificationId()).thenReturn("modif id"); List<IEvent> events = Arrays.asList(mock(IEvent.class)); when(clock.now()).thenReturn(today); when(repo.getEventsSubscribedOnProperScheduler()).thenReturn(Observable.from(events)); sut.loadEvents(false, callback); verify(callback).onEventsLoadingStarted("modif id"); verify(callback).onEventsLoadingFinished(events, "modif id"); reset(callback, repo); when(clock.now()).thenReturn(today.plusDays(1)); when(repo.getModificationId()).thenReturn("modif id"); when(repo.getEventsSubscribedOnProperScheduler()).thenReturn(Observable.from(events)); sut.loadEvents(false, callback); verify(callback).onEventsLoadingStarted("modif id"); verify(callback).onEventsLoadingFinished(events, "modif id"); verify(repo).getEventsSubscribedOnProperScheduler(); }