Search in sources :

Example 11 with Event

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);
}
Also used : Completable(io.reactivex.Completable) Event(org.fossasia.openevent.app.data.models.Event) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 12 with 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);
}
Also used : Event(org.fossasia.openevent.app.data.models.Event) Test(org.junit.Test)

Example 13 with Event

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();
}
Also used : Completable(io.reactivex.Completable) Event(org.fossasia.openevent.app.data.models.Event) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 14 with Event

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);
}
Also used : Event(org.fossasia.openevent.app.data.models.Event) Test(org.junit.Test)

Example 15 with Event

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());
}
Also used : Event(org.fossasia.openevent.app.data.models.Event) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

Event (org.fossasia.openevent.app.data.models.Event)24 Test (org.junit.Test)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 ObservableString (org.fossasia.openevent.app.data.models.dto.ObservableString)4 InOrder (org.mockito.InOrder)3 Completable (io.reactivex.Completable)2 TestObserver (io.reactivex.observers.TestObserver)2 Place (com.google.android.gms.location.places.Place)1 ArrayList (java.util.ArrayList)1 Logger (org.fossasia.openevent.app.common.rx.Logger)1 DatabaseRepository (org.fossasia.openevent.app.data.db.DatabaseRepository)1 Attendee (org.fossasia.openevent.app.data.models.Attendee)1 Ticket (org.fossasia.openevent.app.data.models.Ticket)1 TicketRepository (org.fossasia.openevent.app.data.repository.TicketRepository)1