Search in sources :

Example 1 with Copyright

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

the class CreateCopyrightViewModelTest method shouldShowErrorOnInvalidYear.

@Test
public void shouldShowErrorOnInvalidYear() {
    Copyright copyright = createCopyrightViewModel.getCopyright();
    copyright.setYear("25");
    InOrder inOrder = Mockito.inOrder(error);
    createCopyrightViewModel.getError().observeForever(error);
    createCopyrightViewModel.createCopyright();
    inOrder.verify(error).onChanged("Please Enter a Valid Year");
}
Also used : Copyright(com.eventyay.organizer.data.copyright.Copyright) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 2 with Copyright

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

the class UpdateCopyrightViewModelTest method shouldShowErrorOnInvalidYear.

@Test
public void shouldShowErrorOnInvalidYear() {
    Copyright copyright = updateCopyrightViewModel.getCopyright();
    copyright.setYear("25");
    InOrder inOrder = Mockito.inOrder(error);
    updateCopyrightViewModel.getError().observeForever(error);
    updateCopyrightViewModel.updateCopyright();
    inOrder.verify(error).onChanged("Please Enter a Valid Year");
}
Also used : Copyright(com.eventyay.organizer.data.copyright.Copyright) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 3 with Copyright

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

the class UpdateCopyrightViewModelTest method shouldAcceptCorrectYear.

@Test
public void shouldAcceptCorrectYear() {
    ContextManager.setSelectedEvent(event);
    Copyright copyright = updateCopyrightViewModel.getCopyright();
    copyright.setYear("2018");
    when(copyrightRepository.updateCopyright(copyright)).thenReturn(Observable.just(copyright));
    InOrder inOrder = Mockito.inOrder(success);
    updateCopyrightViewModel.getSuccess().observeForever(success);
    updateCopyrightViewModel.updateCopyright();
    inOrder.verify(success).onChanged(anyString());
    ContextManager.setSelectedEvent(null);
}
Also used : Copyright(com.eventyay.organizer.data.copyright.Copyright) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 4 with Copyright

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

the class UpdateCopyrightViewModelTest method shouldShowErrorOnFailure.

@Test
public void shouldShowErrorOnFailure() {
    ContextManager.setSelectedEvent(event);
    Copyright copyright = updateCopyrightViewModel.getCopyright();
    when(copyrightRepository.updateCopyright(copyright)).thenReturn(Observable.error(new Throwable("Error")));
    updateCopyrightViewModel.updateCopyright();
    updateCopyrightViewModel.getProgress().observeForever(progress);
    updateCopyrightViewModel.getError().observeForever(error);
    InOrder inOrder = Mockito.inOrder(progress, error);
    updateCopyrightViewModel.updateCopyright();
    inOrder.verify(progress).onChanged(true);
    inOrder.verify(error).onChanged("Error");
    inOrder.verify(progress).onChanged(false);
    ContextManager.setSelectedEvent(null);
}
Also used : Copyright(com.eventyay.organizer.data.copyright.Copyright) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 5 with Copyright

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

the class CreateCopyrightViewModel method createCopyright.

public void createCopyright() {
    nullifyEmptyFields(copyright);
    if (!verifyYear(copyright))
        return;
    long eventId = ContextManager.getSelectedEvent().getId();
    Event event = new Event();
    event.setId(eventId);
    copyright.setEvent(event);
    compositeDisposable.add(copyrightRepository.createCopyright(copyright).doOnSubscribe(disposable -> progress.setValue(true)).doFinally(() -> progress.setValue(false)).subscribe(createdTicket -> {
        success.setValue("Copyright 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) Copyright(com.eventyay.organizer.data.copyright.Copyright) ViewModel(androidx.lifecycle.ViewModel) CopyrightRepository(com.eventyay.organizer.data.copyright.CopyrightRepository) ContextManager(com.eventyay.organizer.common.ContextManager) ErrorUtils(com.eventyay.organizer.utils.ErrorUtils) StringUtils(com.eventyay.organizer.utils.StringUtils) Event(com.eventyay.organizer.data.event.Event)

Aggregations

Copyright (com.eventyay.organizer.data.copyright.Copyright)13 Test (org.junit.Test)11 InOrder (org.mockito.InOrder)8 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 CopyrightRepository (com.eventyay.organizer.data.copyright.CopyrightRepository)2 Event (com.eventyay.organizer.data.event.Event)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 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2