Search in sources :

Example 1 with Event

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

the class EventDashboardPresenterTest method shouldNotToggleEventStateOnError.

@Test
public void shouldNotToggleEventStateOnError() {
    when(eventRepository.updateEvent(any(Event.class))).thenReturn(TestUtil.ERROR_OBSERVABLE);
    // Defined locally as a work around for unexpected failureg
    Event event = Event.builder().id(6L).state(Event.STATE_PUBLISHED).build();
    eventDashboardPresenter.setEvent(event);
    eventDashboardPresenter.toggleState();
    assertNotEquals(event.state, Event.STATE_DRAFT);
}
Also used : Event(com.eventyay.organizer.data.event.Event) Test(org.junit.Test)

Example 2 with Event

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

the class EventDashboardPresenterTest method shouldHideProgressbarOnToggleSuccess.

@Test
public void shouldHideProgressbarOnToggleSuccess() {
    when(eventRepository.updateEvent(any(Event.class))).thenReturn(Observable.just(TOGGLED_EVENT));
    eventDashboardPresenter.setEvent(EVENT);
    eventDashboardPresenter.toggleState();
    InOrder inOrder = Mockito.inOrder(eventDetailView, eventRepository);
    inOrder.verify(eventRepository).updateEvent(any(Event.class));
    inOrder.verify(eventDetailView).showProgress(true);
    inOrder.verify(eventDetailView).showResult(any(Event.class));
    inOrder.verify(eventDetailView).showProgress(false);
}
Also used : InOrder(org.mockito.InOrder) Event(com.eventyay.organizer.data.event.Event) Test(org.junit.Test)

Example 3 with Event

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

the class EventsViewModelTest method shouldRefreshEventsSuccessfully.

@Test
public void shouldRefreshEventsSuccessfully() {
    when(eventRepository.getEvents(true)).thenReturn(Observable.fromIterable(EVENT_LIST));
    InOrder inOrder = Mockito.inOrder(events, eventRepository, progress, success, progress);
    eventsViewModel.getProgress().observeForever(progress);
    eventsViewModel.getSuccess().observeForever(success);
    eventsViewModel.getError().observeForever(error);
    events.onChanged(new ArrayList<Event>());
    eventsViewModel.loadUserEvents(true);
    inOrder.verify(eventRepository).getEvents(true);
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(success).onChanged(true);
    inOrder.verify(progress).onChanged(false);
}
Also used : InOrder(org.mockito.InOrder) Event(com.eventyay.organizer.data.event.Event) Test(org.junit.Test)

Example 4 with Event

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

the class EventsViewModelTest method shouldShowEventError.

@Test
public void shouldShowEventError() {
    String errorString = "Test Error";
    when(eventRepository.getEvents(false)).thenReturn(TestUtil.ERROR_OBSERVABLE);
    InOrder inOrder = Mockito.inOrder(eventRepository, progress, error);
    eventsViewModel.getProgress().observeForever(progress);
    eventsViewModel.getError().observeForever(error);
    events.onChanged(new ArrayList<Event>());
    eventsViewModel.loadUserEvents(false);
    inOrder.verify(eventRepository).getEvents(false);
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(error).onChanged(errorString);
    inOrder.verify(progress).onChanged(false);
}
Also used : InOrder(org.mockito.InOrder) Event(com.eventyay.organizer.data.event.Event) Test(org.junit.Test)

Example 5 with Event

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

the class EventsViewModelTest method shouldLoadEventsSuccessfully.

@Test
public void shouldLoadEventsSuccessfully() {
    when(eventRepository.getEvents(false)).thenReturn(Observable.fromIterable(EVENT_LIST));
    InOrder inOrder = Mockito.inOrder(events, eventRepository, progress, success);
    eventsViewModel.getProgress().observeForever(progress);
    eventsViewModel.getSuccess().observeForever(success);
    eventsViewModel.getError().observeForever(error);
    events.onChanged(new ArrayList<Event>());
    eventsViewModel.loadUserEvents(false);
    inOrder.verify(events).onChanged(new ArrayList<>());
    inOrder.verify(eventRepository).getEvents(false);
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(success).onChanged(true);
    inOrder.verify(progress).onChanged(false);
}
Also used : InOrder(org.mockito.InOrder) Event(com.eventyay.organizer.data.event.Event) 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