Search in sources :

Example 1 with Faq

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

the class CreateFaqViewModelTest method shouldShowSuccessOnCreated.

@Test
public void shouldShowSuccessOnCreated() {
    String successString = "Faq Created";
    Faq faq = createFaqViewModel.getFaq();
    when(faqRepository.createFaq(faq)).thenReturn(Observable.just(faq));
    ContextManager.setSelectedEvent(event);
    InOrder inOrder = Mockito.inOrder(progress, dismiss, success);
    createFaqViewModel.getProgress().observeForever(progress);
    createFaqViewModel.getDismiss().observeForever(dismiss);
    createFaqViewModel.getSuccess().observeForever(success);
    createFaqViewModel.createFaq();
    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) Faq(com.eventyay.organizer.data.faq.Faq) Test(org.junit.Test)

Example 2 with Faq

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

the class CreateFaqViewModelTest method shouldShowErrorOnFailure.

@Test
public void shouldShowErrorOnFailure() {
    Faq faq = createFaqViewModel.getFaq();
    when(faqRepository.createFaq(faq)).thenReturn(Observable.error(new Throwable("Error")));
    ContextManager.setSelectedEvent(event);
    InOrder inOrder = Mockito.inOrder(progress, error);
    createFaqViewModel.getProgress().observeForever(progress);
    createFaqViewModel.getError().observeForever(error);
    createFaqViewModel.createFaq();
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(error).onChanged("Error");
    inOrder.verify(progress).onChanged(false);
    ContextManager.setSelectedEvent(null);
}
Also used : InOrder(org.mockito.InOrder) Faq(com.eventyay.organizer.data.faq.Faq) Test(org.junit.Test)

Example 3 with Faq

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

the class CreateFaqViewModel method createFaq.

public void createFaq() {
    long eventId = ContextManager.getSelectedEvent().getId();
    Event event = new Event();
    event.setId(eventId);
    faq.setEvent(event);
    compositeDisposable.add(faqRepository.createFaq(faq).doOnSubscribe(disposable -> progress.setValue(true)).doFinally(() -> progress.setValue(false)).subscribe(createdFaq -> {
        success.setValue("Faq Created");
        dismiss.call();
    }, throwable -> error.setValue(ErrorUtils.getMessage(throwable).toString())));
}
Also used : 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) Faq(com.eventyay.organizer.data.faq.Faq) ViewModel(androidx.lifecycle.ViewModel) ContextManager(com.eventyay.organizer.common.ContextManager) ErrorUtils(com.eventyay.organizer.utils.ErrorUtils) FaqRepository(com.eventyay.organizer.data.faq.FaqRepository) Event(com.eventyay.organizer.data.event.Event)

Aggregations

Faq (com.eventyay.organizer.data.faq.Faq)3 Test (org.junit.Test)2 InOrder (org.mockito.InOrder)2 LiveData (androidx.lifecycle.LiveData)1 ViewModel (androidx.lifecycle.ViewModel)1 ContextManager (com.eventyay.organizer.common.ContextManager)1 SingleEventLiveData (com.eventyay.organizer.common.livedata.SingleEventLiveData)1 Event (com.eventyay.organizer.data.event.Event)1 FaqRepository (com.eventyay.organizer.data.faq.FaqRepository)1 ErrorUtils (com.eventyay.organizer.utils.ErrorUtils)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Inject (javax.inject.Inject)1