Search in sources :

Example 31 with Event

use of com.eventyay.organizer.data.event.Event in project open-event-orga-app by fossasia.

the class FragmentInstanceTest method setUpMockEvent.

private void setUpMockEvent() {
    Event event = new Event();
    event.timezone = "UTC";
    event.endsAt = "2018-12-14T23:59:59.123456+00:00";
    ContextManager.setSelectedEvent(event);
}
Also used : Event(com.eventyay.organizer.data.event.Event)

Example 32 with Event

use of com.eventyay.organizer.data.event.Event in project open-event-orga-app by fossasia.

the class AuthHolderTest method shouldClearSelectedEventOnLogout.

@Test
public void shouldClearSelectedEventOnLogout() {
    ContextManager.setSelectedEvent(new Event());
    authHolder.logout();
    verify(preferenceModel).setLong(MainActivity.EVENT_KEY, -1);
    assertNull(ContextManager.getSelectedEvent());
}
Also used : Event(com.eventyay.organizer.data.event.Event) Test(org.junit.Test)

Example 33 with Event

use of com.eventyay.organizer.data.event.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(repository.isConnected()).thenReturn(true);
    when(authHolder.getIdentity()).thenReturn(344);
    when(repository.getAllItems(eq(Event.class))).thenReturn(Observable.empty()).thenReturn(Observable.fromIterable(EVENTS));
    when(repository.syncSave(eq(Event.class), eq(EVENTS), any(), any())).thenReturn(completable);
    when(eventApi.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(eventApi).getEvents(344L);
    verify(repository).syncSave(eq(Event.class), eq(EVENTS), any(), any());
    testObserver.assertSubscribed();
}
Also used : Completable(io.reactivex.Completable) Event(com.eventyay.organizer.data.event.Event) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 34 with Event

use of com.eventyay.organizer.data.event.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(repository.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(repository).getItems(eq(Event.class), refEq(Event_Table.id.eq(id)));
    verifyZeroInteractions(eventApi);
}
Also used : Event(com.eventyay.organizer.data.event.Event) Test(org.junit.Test)

Example 35 with Event

use of com.eventyay.organizer.data.event.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(repository.isConnected()).thenReturn(true);
    when(repository.getItems(eq(Event.class), refEq(Event_Table.id.eq(id)))).thenReturn(Observable.empty()).thenReturn(Observable.just(event));
    when(repository.save(Event.class, event)).thenReturn(completable);
    when(eventApi.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(eventApi).getEvent(id);
    verify(repository).save(Event.class, event);
}
Also used : Completable(io.reactivex.Completable) Event(com.eventyay.organizer.data.event.Event) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Aggregations

Event (com.eventyay.organizer.data.event.Event)36 LiveData (androidx.lifecycle.LiveData)15 ViewModel (androidx.lifecycle.ViewModel)15 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)15 Inject (javax.inject.Inject)15 ErrorUtils (com.eventyay.organizer.utils.ErrorUtils)14 Test (org.junit.Test)14 SingleEventLiveData (com.eventyay.organizer.common.livedata.SingleEventLiveData)13 ContextManager (com.eventyay.organizer.common.ContextManager)10 StringUtils (com.eventyay.organizer.utils.StringUtils)8 DateUtils (com.eventyay.organizer.utils.DateUtils)5 LocalDateTime (org.threeten.bp.LocalDateTime)5 ZonedDateTime (org.threeten.bp.ZonedDateTime)5 DateTimeParseException (org.threeten.bp.format.DateTimeParseException)5 VisibleForTesting (androidx.annotation.VisibleForTesting)4 MutableLiveData (androidx.lifecycle.MutableLiveData)4 Track (com.eventyay.organizer.data.tracks.Track)4 InOrder (org.mockito.InOrder)4 Logger (com.eventyay.organizer.common.rx.Logger)3 Ticket (com.eventyay.organizer.data.ticket.Ticket)3