Search in sources :

Example 6 with Sponsor

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

the class SponsorRepositoryTest method shouldUpdateUpdatedSponsor.

@Test
public void shouldUpdateUpdatedSponsor() {
    Sponsor updated = mock(Sponsor.class);
    when(repository.isConnected()).thenReturn(true);
    when(sponsorApi.updateSponsor(ID, SPONSOR)).thenReturn(Observable.just(updated));
    when(repository.update(eq(Sponsor.class), eq(updated))).thenReturn(Completable.complete());
    sponsorRepository.updateSponsor(SPONSOR).subscribe();
    verify(repository).update(Sponsor.class, updated);
}
Also used : Sponsor(com.eventyay.organizer.data.sponsor.Sponsor) Test(org.junit.Test)

Example 7 with Sponsor

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

the class SponsorRepositoryTest method shouldSaveCreatedSponsor.

@Test
public void shouldSaveCreatedSponsor() {
    Sponsor created = mock(Sponsor.class);
    when(repository.isConnected()).thenReturn(true);
    when(sponsorApi.postSponsor(SPONSOR)).thenReturn(Observable.just(created));
    when(repository.save(eq(Sponsor.class), eq(created))).thenReturn(Completable.complete());
    sponsorRepository.createSponsor(SPONSOR).subscribe();
    verify(repository).save(Sponsor.class, created);
}
Also used : Sponsor(com.eventyay.organizer.data.sponsor.Sponsor) Test(org.junit.Test)

Example 8 with Sponsor

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

the class CreateSponsorViewModel method updateSponsor.

public void updateSponsor() {
    nullifyEmptyFields(sponsor);
    long eventId = ContextManager.getSelectedEvent().getId();
    Event event = new Event();
    event.setId(eventId);
    sponsor.setEvent(event);
    compositeDisposable.add(sponsorRepository.updateSponsor(sponsor).doOnSubscribe(disposable -> progress.setValue(true)).doFinally(() -> progress.setValue(false)).subscribe(updatedSponsor -> {
        success.setValue("Sponsor Updated");
        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)

Example 9 with Sponsor

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

the class SponsorsPresenterTest method testProgressbarOnSwipeRefreshNoItem.

@Test
public void testProgressbarOnSwipeRefreshNoItem() {
    List<Sponsor> emptyList = new ArrayList<>();
    when(sponsorRepository.getSponsors(ID, true)).thenReturn(Observable.fromIterable(emptyList));
    sponsorsPresenter.loadSponsors(true);
    InOrder inOrder = Mockito.inOrder(sponsorsView);
    inOrder.verify(sponsorsView).showProgress(true);
    inOrder.verify(sponsorsView).onRefreshComplete(true);
    inOrder.verify(sponsorsView).showProgress(false);
}
Also used : InOrder(org.mockito.InOrder) ArrayList(java.util.ArrayList) Sponsor(com.eventyay.organizer.data.sponsor.Sponsor) Test(org.junit.Test)

Example 10 with Sponsor

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

the class CreateSponsorViewModelTest method shouldShowSuccessOnUpdate.

@Test
public void shouldShowSuccessOnUpdate() {
    String successString = "Sponsor Updated";
    Sponsor sponsor = createSponsorViewModel.getSponsor();
    when(sponsorRepository.updateSponsor(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.updateSponsor();
    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)

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