Search in sources :

Example 1 with Sponsor

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

the class CreateSponsorViewModelTest method shouldShowErrorOnUpdateFailure.

@Test
public void shouldShowErrorOnUpdateFailure() {
    Sponsor sponsor = createSponsorViewModel.getSponsor();
    when(sponsorRepository.updateSponsor(sponsor)).thenReturn(Observable.error(new Throwable("Error")));
    ContextManager.setSelectedEvent(event);
    InOrder inOrder = Mockito.inOrder(progress, error);
    createSponsorViewModel.getProgress().observeForever(progress);
    createSponsorViewModel.getError().observeForever(error);
    createSponsorViewModel.updateSponsor();
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(error).onChanged("Error");
    inOrder.verify(progress).onChanged(false);
    ContextManager.setSelectedEvent(null);
}
Also used : InOrder(org.mockito.InOrder) Sponsor(com.eventyay.organizer.data.sponsor.Sponsor) Test(org.junit.Test)

Example 2 with Sponsor

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

the class CreateSponsorViewModelTest method shouldShowSuccessOnCreated.

@Test
public void shouldShowSuccessOnCreated() {
    String successString = "Sponsor Created";
    Sponsor sponsor = createSponsorViewModel.getSponsor();
    when(sponsorRepository.createSponsor(sponsor)).thenReturn(Observable.just(sponsor));
    ContextManager.setSelectedEvent(event);
    InOrder inOrder = Mockito.inOrder(progress, dismiss, success);
    createSponsorViewModel.getProgress().observeForever(progress);
    createSponsorViewModel.getDismiss().observeForever(dismiss);
    createSponsorViewModel.getSuccess().observeForever(success);
    createSponsorViewModel.createSponsor();
    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) Sponsor(com.eventyay.organizer.data.sponsor.Sponsor) Test(org.junit.Test)

Example 3 with Sponsor

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

the class CreateSponsorViewModelTest method shouldShowErrorOnFailure.

@Test
public void shouldShowErrorOnFailure() {
    Sponsor sponsor = createSponsorViewModel.getSponsor();
    when(sponsorRepository.createSponsor(sponsor)).thenReturn(Observable.error(new Throwable("Error")));
    ContextManager.setSelectedEvent(event);
    InOrder inOrder = Mockito.inOrder(progress, error);
    createSponsorViewModel.getProgress().observeForever(progress);
    createSponsorViewModel.getError().observeForever(error);
    createSponsorViewModel.createSponsor();
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(error).onChanged("Error");
    inOrder.verify(progress).onChanged(false);
    ContextManager.setSelectedEvent(null);
}
Also used : InOrder(org.mockito.InOrder) Sponsor(com.eventyay.organizer.data.sponsor.Sponsor) Test(org.junit.Test)

Example 4 with Sponsor

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

the class SponsorsPresenterTest method shouldDeleteSponsorsSuccessfully.

@Test
public void shouldDeleteSponsorsSuccessfully() {
    for (Sponsor sponsor : sponsorsPresenter.getSponsors()) {
        sponsorsPresenter.getSelectedSponsors().get(sponsor.getId()).set(true);
    }
    for (Long sponsorId : sponsorsPresenter.getSelectedSponsors().keySet()) {
        when(sponsorRepository.deleteSponsor(sponsorId)).thenReturn(Completable.complete());
    }
    sponsorsPresenter.deleteSelectedSponsors();
    InOrder inOrder = Mockito.inOrder(sponsorsView);
    inOrder.verify(sponsorsView).showProgress(true);
    inOrder.verify(sponsorsView).showMessage(SPONSORS_DELETED_SUCCESSFULLY);
    inOrder.verify(sponsorsView).showProgress(false);
    assertEquals(sponsorsPresenter.getSelectedSponsors().size(), 0);
}
Also used : InOrder(org.mockito.InOrder) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Sponsor(com.eventyay.organizer.data.sponsor.Sponsor) Test(org.junit.Test)

Example 5 with Sponsor

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

the class CreateSponsorViewModel method createSponsor.

public void createSponsor() {
    long eventId = ContextManager.getSelectedEvent().getId();
    Event event = new Event();
    event.setId(eventId);
    sponsor.setEvent(event);
    nullifyEmptyFields(sponsor);
    compositeDisposable.add(sponsorRepository.createSponsor(sponsor).doOnSubscribe(disposable -> progress.setValue(true)).doFinally(() -> progress.setValue(false)).subscribe(createdSponsor -> {
        success.setValue("Sponsor 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) Sponsor(com.eventyay.organizer.data.sponsor.Sponsor) ViewModel(androidx.lifecycle.ViewModel) ContextManager(com.eventyay.organizer.common.ContextManager) SponsorRepository(com.eventyay.organizer.data.sponsor.SponsorRepository) Logger(com.eventyay.organizer.common.rx.Logger) Inject(javax.inject.Inject) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) ErrorUtils(com.eventyay.organizer.utils.ErrorUtils) StringUtils(com.eventyay.organizer.utils.StringUtils) VisibleForTesting(androidx.annotation.VisibleForTesting) Event(com.eventyay.organizer.data.event.Event)

Aggregations

Sponsor (com.eventyay.organizer.data.sponsor.Sponsor)11 Test (org.junit.Test)9 InOrder (org.mockito.InOrder)6 VisibleForTesting (androidx.annotation.VisibleForTesting)2 LiveData (androidx.lifecycle.LiveData)2 ViewModel (androidx.lifecycle.ViewModel)2 ContextManager (com.eventyay.organizer.common.ContextManager)2 SingleEventLiveData (com.eventyay.organizer.common.livedata.SingleEventLiveData)2 Logger (com.eventyay.organizer.common.rx.Logger)2 Event (com.eventyay.organizer.data.event.Event)2 SponsorRepository (com.eventyay.organizer.data.sponsor.SponsorRepository)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 ArrayList (java.util.ArrayList)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1