Search in sources :

Example 1 with Session

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

the class CreateSessionViewModelTest method shouldShowSuccessOnCreated.

@Test
public void shouldShowSuccessOnCreated() {
    Session session = createSessionViewModel.getSession();
    String isoDateNow = DateUtils.formatDateToIso(LocalDateTime.now());
    String isoDateThen = DateUtils.formatDateToIso(LocalDateTime.MAX);
    session.setStartsAt(isoDateNow);
    session.setEndsAt(isoDateThen);
    when(sessionRepository.createSession(createSessionViewModel.getSession())).thenReturn(Observable.just(SESSION));
    InOrder inOrder = Mockito.inOrder(progress, success, dismiss);
    createSessionViewModel.getProgress().observeForever(progress);
    createSessionViewModel.getSuccess().observeForever(success);
    createSessionViewModel.getDismiss().observeForever(dismiss);
    createSessionViewModel.createSession(TRACK_ID, EVENT_ID);
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(success).onChanged(anyString());
    inOrder.verify(dismiss).onChanged(null);
    inOrder.verify(progress).onChanged(false);
}
Also used : InOrder(org.mockito.InOrder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Session(com.eventyay.organizer.data.session.Session) Test(org.junit.Test)

Example 2 with Session

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

the class CreateSessionViewModelTest method shouldShowErrorOnUpdateFailure.

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

Example 3 with Session

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

the class CreateSessionViewModelTest method shouldNullifyEmptyFields.

@Test
public void shouldNullifyEmptyFields() {
    Session session = createSessionViewModel.getSession();
    when(sessionRepository.createSession(session)).thenReturn(Observable.just(session));
    session.setSlidesUrl("");
    session.setAudioUrl("");
    session.setVideoUrl("");
    session.setSignupUrl("");
    String isoDateNow = DateUtils.formatDateToIso(LocalDateTime.now());
    String isoDateMax = DateUtils.formatDateToIso(LocalDateTime.MAX);
    session.setStartsAt(isoDateNow);
    session.setEndsAt(isoDateMax);
    createSessionViewModel.createSession(TRACK_ID, EVENT_ID);
    assertNull(session.getSlidesUrl());
    assertNull(session.getAudioUrl());
    assertNull(session.getVideoUrl());
    assertNull(session.getSignupUrl());
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Session(com.eventyay.organizer.data.session.Session) Test(org.junit.Test)

Example 4 with Session

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

the class CreateSessionViewModelTest method shouldShowErrorOnFailure.

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

Example 5 with Session

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

the class CreateSessionViewModelTest method shouldRejectWrongDates.

@Test
public void shouldRejectWrongDates() {
    Session session = createSessionViewModel.getSession();
    String isoDate = DateUtils.formatDateToIso(LocalDateTime.now());
    session.setStartsAt(isoDate);
    session.setEndsAt(isoDate);
    InOrder inOrder = Mockito.inOrder(sessionRepository, error);
    createSessionViewModel.getError().observeForever(error);
    createSessionViewModel.createSession(TRACK_ID, EVENT_ID);
    inOrder.verify(error).onChanged(anyString());
    inOrder.verify(sessionRepository, never()).createSession(any());
}
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