Search in sources :

Example 6 with Track

use of com.eventyay.organizer.data.tracks.Track 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 7 with Track

use of com.eventyay.organizer.data.tracks.Track 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 8 with Track

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

the class CreateTrackViewModelTest method shouldShowErrorOnFailure.

@Test
public void shouldShowErrorOnFailure() {
    Track track = createTrackViewModel.getTrack();
    track.setDescription(null);
    when(trackRepository.createTrack(track)).thenReturn(Observable.error(new Throwable("Error")));
    ContextManager.setSelectedEvent(event);
    InOrder inOrder = Mockito.inOrder(progress, error);
    createTrackViewModel.getProgress().observeForever(progress);
    createTrackViewModel.getError().observeForever(error);
    createTrackViewModel.createTrack();
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(error).onChanged("Error");
    inOrder.verify(progress).onChanged(false);
    ContextManager.setSelectedEvent(null);
}
Also used : InOrder(org.mockito.InOrder) Track(com.eventyay.organizer.data.tracks.Track) Test(org.junit.Test)

Example 9 with Track

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

the class CreateTrackViewModelTest method shouldShowSuccessOnCreated.

@Test
public void shouldShowSuccessOnCreated() {
    String successString = "Track Created";
    Track track = createTrackViewModel.getTrack();
    when(trackRepository.createTrack(track)).thenReturn(Observable.just(track));
    ContextManager.setSelectedEvent(event);
    InOrder inOrder = Mockito.inOrder(progress, dismiss, success);
    createTrackViewModel.getProgress().observeForever(progress);
    createTrackViewModel.getDismiss().observeForever(dismiss);
    createTrackViewModel.getSuccess().observeForever(success);
    createTrackViewModel.createTrack();
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(success).onChanged(successString);
    inOrder.verify(dismiss).onChanged(null);
    inOrder.verify(progress).onChanged(false);
    ContextManager.setSelectedEvent(null);
}
Also used : InOrder(org.mockito.InOrder) Track(com.eventyay.organizer.data.tracks.Track) Test(org.junit.Test)

Example 10 with Track

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

the class TracksPresenterTest method testProgressbarOnSwipeRefreshNoItem.

@Test
public void testProgressbarOnSwipeRefreshNoItem() {
    List<Track> emptyList = new ArrayList<>();
    when(trackRepository.getTracks(ID, true)).thenReturn(Observable.fromIterable(emptyList));
    tracksPresenter.loadTracks(true);
    InOrder inOrder = Mockito.inOrder(tracksView);
    inOrder.verify(tracksView).showProgress(true);
    inOrder.verify(tracksView).onRefreshComplete(true);
    inOrder.verify(tracksView).showProgress(false);
}
Also used : InOrder(org.mockito.InOrder) ArrayList(java.util.ArrayList) Track(com.eventyay.organizer.data.tracks.Track) Test(org.junit.Test)

Aggregations

Track (com.eventyay.organizer.data.tracks.Track)12 Test (org.junit.Test)8 InOrder (org.mockito.InOrder)5 LiveData (androidx.lifecycle.LiveData)4 ViewModel (androidx.lifecycle.ViewModel)4 SingleEventLiveData (com.eventyay.organizer.common.livedata.SingleEventLiveData)4 Event (com.eventyay.organizer.data.event.Event)4 ErrorUtils (com.eventyay.organizer.utils.ErrorUtils)4 StringUtils (com.eventyay.organizer.utils.StringUtils)4 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)4 Inject (javax.inject.Inject)4 Color (android.graphics.Color)2 ContextManager (com.eventyay.organizer.common.ContextManager)2 Session (com.eventyay.organizer.data.session.Session)2 SessionRepository (com.eventyay.organizer.data.session.SessionRepository)2 TrackRepository (com.eventyay.organizer.data.tracks.TrackRepository)2 DateUtils (com.eventyay.organizer.utils.DateUtils)2 LocalDateTime (org.threeten.bp.LocalDateTime)2 ZonedDateTime (org.threeten.bp.ZonedDateTime)2 DateTimeParseException (org.threeten.bp.format.DateTimeParseException)2