use of org.fossasia.openevent.app.data.models.Event in project open-event-orga-app by fossasia.
the class EventRepositoryTest method shouldSaveEventInCache.
@Test
public void shouldSaveEventInCache() {
long id = 23L;
Event event = new Event();
TestObserver testObserver = TestObserver.create();
Completable completable = Completable.complete().doOnSubscribe(testObserver::onSubscribe);
when(utilModel.isConnected()).thenReturn(true);
when(databaseRepository.getItems(eq(Event.class), refEq(Event_Table.id.eq(id)))).thenReturn(Observable.empty()).thenReturn(Observable.just(event));
when(databaseRepository.save(Event.class, event)).thenReturn(completable);
when(eventService.getEvent(id)).thenReturn(Observable.just(event));
// No force reload ensures use of cache
Observable<Event> userObservable = eventRepository.getEvent(23, false);
userObservable.test().assertSubscribed().assertValue(event);
testObserver.assertSubscribed();
// Verify loads from network
verify(eventService).getEvent(id);
verify(databaseRepository).save(Event.class, event);
}
use of org.fossasia.openevent.app.data.models.Event in project open-event-orga-app by fossasia.
the class EventRepositoryTest method shouldFetchEventOnForceReload.
@Test
public void shouldFetchEventOnForceReload() {
long id = 45L;
Event event = new Event();
when(databaseRepository.save(Event.class, event)).thenReturn(Completable.complete());
when(databaseRepository.getItems(eq(Event.class), refEq(Event_Table.id.eq(id)))).thenReturn(Observable.just(event));
when(utilModel.isConnected()).thenReturn(true);
when(eventService.getEvent(id)).thenReturn(Observable.just(event));
// Force reload ensures no use of cache
Observable<Event> userObservable = eventRepository.getEvent(id, true);
userObservable.test().assertValue(event);
// Verify loads from network
verify(eventService).getEvent(id);
}
use of org.fossasia.openevent.app.data.models.Event in project open-event-orga-app by fossasia.
the class EventRepositoryTest method shouldSaveEventsInCache.
@Test
public void shouldSaveEventsInCache() {
TestObserver testObserver = TestObserver.create();
Completable completable = Completable.complete().doOnSubscribe(testObserver::onSubscribe);
when(utilModel.isConnected()).thenReturn(true);
when(utilModel.getToken()).thenReturn(TOKEN);
when(databaseRepository.getAllItems(eq(Event.class))).thenReturn(Observable.empty()).thenReturn(Observable.fromIterable(EVENTS));
when(databaseRepository.saveList(Event.class, EVENTS)).thenReturn(completable);
when(databaseRepository.deleteAll(Event.class)).thenReturn(completable);
when(eventService.getEvents(344L)).thenReturn(Observable.just(EVENTS));
// No force reload ensures use of cache
Observable<Event> eventObservable = eventRepository.getEvents(false);
eventObservable.toList().test().assertValue(EVENTS);
// Verify loads from network
verify(utilModel).getToken();
verify(eventService).getEvents(344L);
testObserver.assertSubscribed();
}
use of org.fossasia.openevent.app.data.models.Event in project open-event-orga-app by fossasia.
the class EventRepositoryTest method shouldLoadEventFromCache.
@Test
public void shouldLoadEventFromCache() {
long id = 45L;
Event event = new Event();
when(databaseRepository.getItems(eq(Event.class), refEq(Event_Table.id.eq(id)))).thenReturn(Observable.just(event));
// No force reload ensures use of cache
Observable<Event> eventObservable = eventRepository.getEvent(id, false);
eventObservable.test();
verify(databaseRepository).getItems(eq(Event.class), refEq(Event_Table.id.eq(id)));
verifyZeroInteractions(eventService);
}
use of org.fossasia.openevent.app.data.models.Event in project open-event-orga-app by fossasia.
the class CreateEventPresenterTest method shouldRejectEndAfterStartDates.
@Test
public void shouldRejectEndAfterStartDates() {
Event event = createEventPresenter.getEvent();
String isoDate = DateUtils.formatDateToIso(LocalDateTime.now());
event.getStartsAt().set(isoDate);
event.getEndsAt().set(isoDate);
createEventPresenter.createEvent();
verify(createEventView).showError("End time should be after start time");
verify(eventRepository, never()).createEvent(any());
}
Aggregations