Search in sources :

Example 11 with MvpView

use of com.hannesdorfmann.mosby3.mvp.MvpView in project mosby by sockeqwe.

the class ActivityMvpViewStateDelegateImplTestNew method initComponents.

@Before
public void initComponents() {
    view = new MvpView() {
    };
    viewState = Mockito.mock(ViewState.class);
    presenter = Mockito.mock(MvpPresenter.class);
    callback = Mockito.spy(PartialMvpViewStateDelegateCallbackImpl.class);
    activity = Mockito.mock(Activity.class);
    application = Mockito.mock(Application.class);
    Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
    Mockito.doCallRealMethod().when(callback).getPresenter();
    Mockito.doCallRealMethod().when(callback).setViewState(viewState);
    Mockito.doCallRealMethod().when(callback).getViewState();
    Mockito.when(callback.getMvpView()).thenReturn(view);
    Mockito.when(activity.getApplication()).thenReturn(application);
    Mockito.when(callback.createPresenter()).thenReturn(presenter);
    Mockito.when(callback.createViewState()).thenReturn(viewState);
}
Also used : MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) Activity(android.app.Activity) ViewState(com.hannesdorfmann.mosby3.mvp.viewstate.ViewState) Application(android.app.Application) Before(org.junit.Before)

Example 12 with MvpView

use of com.hannesdorfmann.mosby3.mvp.MvpView in project mosby by sockeqwe.

the class ActivityMvpViewStateDelegateImplTestNew method appStartWithViewStateFromMemoryAndBundleButPreferViewStateFromMemory.

@Test
public void appStartWithViewStateFromMemoryAndBundleButPreferViewStateFromMemory() {
    ActivityMvpViewStateDelegateImpl<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>> delegate = new ActivityMvpViewStateDelegateImpl<>(activity, callback, true);
    Mockito.doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            viewState = Mockito.spy(new SimpleRestorableViewState());
            return viewState;
        }
    }).when(callback).createViewState();
    startActivity(delegate, null, 1, 1, 1, 1, 1, 0, null, 0, 1, 0);
    Bundle bundle = BundleMocker.create();
    finishActivity(delegate, bundle, true, 1, true, false);
    startActivity(delegate, bundle, 1, 2, 2, 1, 2, 1, true, 1, 1, 1);
    finishActivity(delegate, bundle, false, 1, false, true);
}
Also used : Answer(org.mockito.stubbing.Answer) MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Bundle(android.os.Bundle) MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) ViewState(com.hannesdorfmann.mosby3.mvp.viewstate.ViewState) Test(org.junit.Test)

Example 13 with MvpView

use of com.hannesdorfmann.mosby3.mvp.MvpView in project mosby by sockeqwe.

the class ViewGroupMvpViewStateDelegateImplTest method initComponents.

@Before
public void initComponents() {
    view = new MvpView() {
    };
    viewState = Mockito.mock(ViewState.class);
    presenter = Mockito.mock(MvpPresenter.class);
    callback = Mockito.mock(PartialViewGroupMvpViewStateDelegateCallbackImpl.class);
    Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
    Mockito.doCallRealMethod().when(callback).getPresenter();
    Mockito.doCallRealMethod().when(callback).setViewState(viewState);
    Mockito.doCallRealMethod().when(callback).getViewState();
    activity = Mockito.mock(FragmentActivity.class);
    application = Mockito.mock(Application.class);
    Mockito.when(callback.getMvpView()).thenReturn(view);
    Mockito.when(callback.getContext()).thenReturn(activity);
    Mockito.when(activity.getApplication()).thenReturn(application);
    Mockito.when(callback.createPresenter()).thenReturn(presenter);
    Mockito.when(callback.createViewState()).thenReturn(viewState);
    delegate = new ViewGroupMvpViewStateDelegateImpl<>(callback, true);
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) ViewState(com.hannesdorfmann.mosby3.mvp.viewstate.ViewState) Application(android.app.Application) Before(org.junit.Before)

Example 14 with MvpView

use of com.hannesdorfmann.mosby3.mvp.MvpView in project mosby by sockeqwe.

the class PresenterManagerTest method putGetRemovePresenter.

@Test
public void putGetRemovePresenter() {
    Activity activity = Mockito.mock(Activity.class);
    Application application = Mockito.mock(Application.class);
    Mockito.when(activity.getApplication()).thenReturn(application);
    MvpPresenter<MvpView> presenter = new MvpPresenter<MvpView>() {

        @Override
        public void attachView(MvpView view) {
        }

        @Override
        public void detachView(boolean retainInstance) {
        }
    };
    String viewId = "123";
    Assert.assertNull(PresenterManager.getPresenter(activity, viewId));
    PresenterManager.putPresenter(activity, viewId, presenter);
    Assert.assertTrue(presenter == PresenterManager.getPresenter(activity, viewId));
    PresenterManager.remove(activity, viewId);
    Assert.assertNull(PresenterManager.getPresenter(activity, viewId));
}
Also used : MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) Activity(android.app.Activity) Application(android.app.Application) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with MvpView

use of com.hannesdorfmann.mosby3.mvp.MvpView in project mosby by sockeqwe.

the class ActivityMvpDelegateImplTest method initComponents.

@Before
public void initComponents() {
    view = new MvpView() {
    };
    presenter = Mockito.mock(MvpPresenter.class);
    callback = Mockito.mock(PartialMvpDelegateCallbackImpl.class);
    activity = Mockito.mock(Activity.class);
    application = Mockito.mock(Application.class);
    Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
    Mockito.doCallRealMethod().when(callback).getPresenter();
    Mockito.when(callback.getMvpView()).thenReturn(view);
    Mockito.when(activity.getApplication()).thenReturn(application);
    Mockito.when(callback.createPresenter()).thenReturn(presenter);
}
Also used : MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) Activity(android.app.Activity) Application(android.app.Application) Before(org.junit.Before)

Aggregations

MvpView (com.hannesdorfmann.mosby3.mvp.MvpView)17 MvpPresenter (com.hannesdorfmann.mosby3.mvp.MvpPresenter)15 Test (org.junit.Test)11 Bundle (android.os.Bundle)8 ViewState (com.hannesdorfmann.mosby3.mvp.viewstate.ViewState)8 Application (android.app.Application)7 Before (org.junit.Before)6 FragmentActivity (android.support.v4.app.FragmentActivity)4 Activity (android.app.Activity)3 Fragment (android.support.v4.app.Fragment)2 RestorableViewState (com.hannesdorfmann.mosby3.mvp.viewstate.RestorableViewState)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 Object (org.omg.CORBA.Object)2 Parcelable (android.os.Parcelable)1 RestorableParcelableViewState (com.hannesdorfmann.mosby3.mvp.viewstate.RestorableParcelableViewState)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1