Search in sources :

Example 6 with Session

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

the class SessionsPresenterTest method shouldDeleteSessionsSuccessfully.

@Test
public void shouldDeleteSessionsSuccessfully() {
    for (Session session : sessionsPresenter.getSessions()) {
        sessionsPresenter.getSelectedSessions().get(session.getId()).set(true);
    }
    for (Long sessionId : sessionsPresenter.getSelectedSessions().keySet()) {
        when(sessionRepository.deleteSession(sessionId)).thenReturn(Completable.complete());
    }
    sessionsPresenter.deleteSelectedSessions();
    InOrder inOrder = Mockito.inOrder(sessionsView);
    inOrder.verify(sessionsView).showProgress(true);
    inOrder.verify(sessionsView).showMessage(SESSION_DELETION_SUCCESS);
    inOrder.verify(sessionsView).showProgress(false);
    assertEquals(sessionsPresenter.getSelectedSessions().size(), 0);
}
Also used : InOrder(org.mockito.InOrder) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Session(com.eventyay.organizer.data.session.Session) Test(org.junit.Test)

Example 7 with Session

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

the class CreateSessionViewModel method updateSession.

// Method called for updating an session
public void updateSession(long trackId, long eventId) {
    Track track = new Track();
    Event event = new Event();
    track.setId(trackId);
    event.setId(eventId);
    session.setTrack(track);
    session.setEvent(event);
    nullifyEmptyFields(session);
    compositeDisposable.add(sessionRepository.updateSession(session).doOnSubscribe(disposable -> progress.setValue(true)).doFinally(() -> progress.setValue(false)).subscribe(updatedSession -> {
        success.setValue("Session Updated Successfully");
        dismiss.call();
    }, throwable -> error.setValue(ErrorUtils.getMessage(throwable).toString())));
}
Also used : DateUtils(com.eventyay.organizer.utils.DateUtils) LiveData(androidx.lifecycle.LiveData) SingleEventLiveData(com.eventyay.organizer.common.livedata.SingleEventLiveData) Event(com.eventyay.organizer.data.event.Event) ViewModel(androidx.lifecycle.ViewModel) ZonedDateTime(org.threeten.bp.ZonedDateTime) Inject(javax.inject.Inject) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) SessionRepository(com.eventyay.organizer.data.session.SessionRepository) LocalDateTime(org.threeten.bp.LocalDateTime) ErrorUtils(com.eventyay.organizer.utils.ErrorUtils) StringUtils(com.eventyay.organizer.utils.StringUtils) Track(com.eventyay.organizer.data.tracks.Track) Session(com.eventyay.organizer.data.session.Session) DateTimeParseException(org.threeten.bp.format.DateTimeParseException) Event(com.eventyay.organizer.data.event.Event) Track(com.eventyay.organizer.data.tracks.Track)

Example 8 with Session

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

the class CreateSessionViewModel method createSession.

public void createSession(long trackId, long eventId) {
    if (!verify())
        return;
    Track track = new Track();
    Event event = new Event();
    track.setId(trackId);
    event.setId(eventId);
    session.setTrack(track);
    session.setEvent(event);
    nullifyEmptyFields(session);
    compositeDisposable.add(sessionRepository.createSession(session).doOnSubscribe(disposable -> progress.setValue(true)).doFinally(() -> progress.setValue(false)).subscribe(createdSession -> {
        success.setValue("Session Created");
        dismiss.call();
    }, throwable -> error.setValue(ErrorUtils.getMessage(throwable).toString())));
}
Also used : DateUtils(com.eventyay.organizer.utils.DateUtils) LiveData(androidx.lifecycle.LiveData) SingleEventLiveData(com.eventyay.organizer.common.livedata.SingleEventLiveData) Event(com.eventyay.organizer.data.event.Event) ViewModel(androidx.lifecycle.ViewModel) ZonedDateTime(org.threeten.bp.ZonedDateTime) Inject(javax.inject.Inject) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) SessionRepository(com.eventyay.organizer.data.session.SessionRepository) LocalDateTime(org.threeten.bp.LocalDateTime) ErrorUtils(com.eventyay.organizer.utils.ErrorUtils) StringUtils(com.eventyay.organizer.utils.StringUtils) Track(com.eventyay.organizer.data.tracks.Track) Session(com.eventyay.organizer.data.session.Session) DateTimeParseException(org.threeten.bp.format.DateTimeParseException) Event(com.eventyay.organizer.data.event.Event) Track(com.eventyay.organizer.data.tracks.Track)

Example 9 with Session

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

the class SessionsPresenterTest method testProgressbarOnSwipeRefreshNoItem.

@Test
public void testProgressbarOnSwipeRefreshNoItem() {
    List<Session> emptyList = new ArrayList<>();
    when(sessionRepository.getSessions(ID, true)).thenReturn(Observable.fromIterable(emptyList));
    sessionsPresenter.loadSessions(true);
    InOrder inOrder = Mockito.inOrder(sessionsView);
    inOrder.verify(sessionsView).showProgress(true);
    inOrder.verify(sessionsView).onRefreshComplete(true);
    inOrder.verify(sessionsView).showProgress(false);
}
Also used : InOrder(org.mockito.InOrder) ArrayList(java.util.ArrayList) Session(com.eventyay.organizer.data.session.Session) Test(org.junit.Test)

Example 10 with Session

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

the class CreateSessionViewModelTest method shouldAcceptCorrectDates.

@Test
public void shouldAcceptCorrectDates() {
    Session session = createSessionViewModel.getSession();
    when(sessionRepository.createSession(session)).thenReturn(Observable.empty());
    String isoDateNow = DateUtils.formatDateToIso(LocalDateTime.now());
    String isoDateThen = DateUtils.formatDateToIso(LocalDateTime.MAX);
    session.setStartsAt(isoDateNow);
    session.setEndsAt(isoDateThen);
    InOrder inOrder = Mockito.inOrder(sessionRepository, error);
    createSessionViewModel.getError().observeForever(error);
    createSessionViewModel.createSession(TRACK_ID, EVENT_ID);
    inOrder.verify(error, never()).onChanged(anyString());
    inOrder.verify(sessionRepository).createSession(session);
}
Also used : InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Session(com.eventyay.organizer.data.session.Session) Test(org.junit.Test)

Aggregations

Session (com.eventyay.organizer.data.session.Session)12 Test (org.junit.Test)10 InOrder (org.mockito.InOrder)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 LiveData (androidx.lifecycle.LiveData)2 ViewModel (androidx.lifecycle.ViewModel)2 SingleEventLiveData (com.eventyay.organizer.common.livedata.SingleEventLiveData)2 Event (com.eventyay.organizer.data.event.Event)2 SessionRepository (com.eventyay.organizer.data.session.SessionRepository)2 Track (com.eventyay.organizer.data.tracks.Track)2 DateUtils (com.eventyay.organizer.utils.DateUtils)2 ErrorUtils (com.eventyay.organizer.utils.ErrorUtils)2 StringUtils (com.eventyay.organizer.utils.StringUtils)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 Inject (javax.inject.Inject)2 LocalDateTime (org.threeten.bp.LocalDateTime)2 ZonedDateTime (org.threeten.bp.ZonedDateTime)2 DateTimeParseException (org.threeten.bp.format.DateTimeParseException)2 ArrayList (java.util.ArrayList)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1