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);
}
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);
}
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);
}
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);
}
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())));
}
Aggregations