Search in sources :

Example 1 with Track

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

the class TrackRepositoryTest method shouldSetEventOnCreatedTrack.

@Test
public void shouldSetEventOnCreatedTrack() {
    Track created = mock(Track.class);
    when(repository.isConnected()).thenReturn(true);
    when(trackApi.postTrack(TRACK)).thenReturn(Observable.just(created));
    when(repository.save(eq(Track.class), eq(created))).thenReturn(Completable.complete());
    trackRepository.createTrack(TRACK).subscribe();
    verify(created).setEvent(EVENT);
}
Also used : Track(com.eventyay.organizer.data.tracks.Track) Test(org.junit.Test)

Example 2 with Track

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

the class TrackRepositoryTest method shouldUpdateUpdatedTrack.

@Test
public void shouldUpdateUpdatedTrack() {
    Track updated = mock(Track.class);
    when(repository.isConnected()).thenReturn(true);
    when(trackApi.updateTrack(ID, TRACK)).thenReturn(Observable.just(updated));
    when(repository.update(eq(Track.class), eq(updated))).thenReturn(Completable.complete());
    trackRepository.updateTrack(TRACK).subscribe();
    verify(repository).update(Track.class, updated);
}
Also used : Track(com.eventyay.organizer.data.tracks.Track) Test(org.junit.Test)

Example 3 with Track

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

the class UpdateTrackViewModelTest method shouldShowErrorOnUpdateFailure.

@Test
public void shouldShowErrorOnUpdateFailure() {
    Track track = updateTrackViewModel.getTrack();
    when(trackRepository.updateTrack(track)).thenReturn(Observable.error(new Throwable("Error")));
    ContextManager.setSelectedEvent(event);
    InOrder inOrder = Mockito.inOrder(progress, error);
    updateTrackViewModel.getProgress().observeForever(progress);
    updateTrackViewModel.getError().observeForever(error);
    updateTrackViewModel.updateTrack();
    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 4 with Track

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

the class CreateTrackViewModel method createTrack.

public void createTrack() {
    nullifyEmptyFields(track);
    long eventId = ContextManager.getSelectedEvent().getId();
    Event event = new Event();
    event.setId(eventId);
    track.setEvent(event);
    compositeDisposable.add(trackRepository.createTrack(track).doOnSubscribe(disposable -> progress.setValue(true)).doFinally(() -> progress.setValue(false)).subscribe(createdTrack -> {
        success.setValue("Track Created");
        dismiss.call();
    }, throwable -> error.setValue(ErrorUtils.getMessage(throwable).toString())));
}
Also used : LiveData(androidx.lifecycle.LiveData) SingleEventLiveData(com.eventyay.organizer.common.livedata.SingleEventLiveData) Event(com.eventyay.organizer.data.event.Event) ViewModel(androidx.lifecycle.ViewModel) ContextManager(com.eventyay.organizer.common.ContextManager) Random(java.util.Random) Color(android.graphics.Color) Inject(javax.inject.Inject) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TrackRepository(com.eventyay.organizer.data.tracks.TrackRepository) ErrorUtils(com.eventyay.organizer.utils.ErrorUtils) StringUtils(com.eventyay.organizer.utils.StringUtils) Track(com.eventyay.organizer.data.tracks.Track) Event(com.eventyay.organizer.data.event.Event)

Example 5 with Track

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

the class UpdateTrackViewModel method updateTrack.

public void updateTrack() {
    nullifyEmptyFields(track);
    long eventId = ContextManager.getSelectedEvent().getId();
    Event event = new Event();
    event.setId(eventId);
    track.setEvent(event);
    compositeDisposable.add(trackRepository.updateTrack(track).doOnSubscribe(disposable -> progress.setValue(true)).doFinally(() -> progress.setValue(false)).subscribe(updatedTrack -> {
        success.setValue("Track Updated");
        dismiss.call();
    }, throwable -> error.setValue(ErrorUtils.getMessage(throwable).toString())));
}
Also used : Color(android.graphics.Color) Inject(javax.inject.Inject) LiveData(androidx.lifecycle.LiveData) SingleEventLiveData(com.eventyay.organizer.common.livedata.SingleEventLiveData) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Event(com.eventyay.organizer.data.event.Event) ViewModel(androidx.lifecycle.ViewModel) ContextManager(com.eventyay.organizer.common.ContextManager) TrackRepository(com.eventyay.organizer.data.tracks.TrackRepository) ErrorUtils(com.eventyay.organizer.utils.ErrorUtils) StringUtils(com.eventyay.organizer.utils.StringUtils) Track(com.eventyay.organizer.data.tracks.Track) Event(com.eventyay.organizer.data.event.Event)

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