Search in sources :

Example 6 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, 1, 0, true, false);
    startActivity(delegate, bundle, 1, 2, 2, 1, 2, 1, true, 1, 1, 1);
    finishActivity(delegate, bundle, 2, 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 7 with MvpView

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

the class ActivityMvpViewStateDelegateImplTestNew method appStartFinishing.

@Test
public void appStartFinishing() {
    ActivityMvpViewStateDelegateImpl<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>> delegate = new ActivityMvpViewStateDelegateImpl<>(activity, callback, true);
    startActivity(delegate, null, 1, 1, 1, 1, 1, 0, null, 0, 1, 0);
    Bundle bundle = BundleMocker.create();
    finishActivity(delegate, bundle, 1, 1, false, true);
}
Also used : MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) Bundle(android.os.Bundle) MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) ViewState(com.hannesdorfmann.mosby3.mvp.viewstate.ViewState) Test(org.junit.Test)

Example 8 with MvpView

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

the class ActivityMvpViewStateDelegateImplTestNew method dontKeepPresenterAndViewState.

@Test
public void dontKeepPresenterAndViewState() {
    ActivityMvpViewStateDelegateImpl<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>> delegate = new ActivityMvpViewStateDelegateImpl<>(activity, callback, false);
    startActivity(delegate, null, 1, 1, 1, 1, 1, 0, null, 0, 1, 0);
    Bundle bundle = BundleMocker.create();
    finishActivity(delegate, bundle, 1, 1, true, false);
    startActivity(delegate, bundle, 2, 2, 2, 2, 2, 0, null, 0, 2, 0);
    finishActivity(delegate, bundle, 2, 2, false, true);
}
Also used : MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) Bundle(android.os.Bundle) MvpPresenter(com.hannesdorfmann.mosby3.mvp.MvpPresenter) ViewState(com.hannesdorfmann.mosby3.mvp.viewstate.ViewState) Test(org.junit.Test)

Example 9 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() {
    };
    savedState = null;
    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();
    Mockito.doCallRealMethod().when(callback).superOnSaveInstanceState();
    activity = Mockito.mock(FragmentActivity.class);
    application = Mockito.mock(Application.class);
    androidView = Mockito.mock(View.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);
    Mockito.when(androidView.isInEditMode()).thenReturn(false);
    delegate = new ViewGroupMvpViewStateDelegateImpl<>(androidView, 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) View(android.view.View) MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) Before(org.junit.Before)

Example 10 with MvpView

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

the class ViewGroupMvpViewStateDelegateImplTest method dontKeepPresenterIfSecondPresenterIsInPresenterManager.

/**
 * Checks if two Views one that keeps presenter, the other who doesn't keep presenter during
 * screen orientation changes work properly
 *
 * https://github.com/sockeqwe/mosby/issues/231
 */
@Test
public void dontKeepPresenterIfSecondPresenterIsInPresenterManager() {
    MvpView view1 = new MvpView() {
    };
    View androidView1 = Mockito.mock(View.class);
    ViewState<MvpView> viewState1 = Mockito.mock(ViewState.class);
    MvpPresenter<MvpView> presenter1 = Mockito.mock(MvpPresenter.class);
    PartialViewGroupMvpViewStateDelegateCallbackImpl callback1 = Mockito.mock(PartialViewGroupMvpViewStateDelegateCallbackImpl.class);
    Mockito.doCallRealMethod().when(callback1).setPresenter(presenter1);
    Mockito.doCallRealMethod().when(callback1).getPresenter();
    Mockito.doCallRealMethod().when(callback1).setViewState(viewState1);
    Mockito.doCallRealMethod().when(callback1).getViewState();
    Mockito.when(callback1.getMvpView()).thenReturn(view1);
    Mockito.when(callback1.getContext()).thenReturn(activity);
    Mockito.when(callback1.createPresenter()).thenReturn(presenter1);
    Mockito.when(callback1.createViewState()).thenReturn(viewState1);
    Mockito.when(androidView1.isInEditMode()).thenReturn(false);
    ViewGroupMvpViewStateDelegateImpl keepDelegate = new ViewGroupMvpViewStateDelegateImpl<>(androidView1, callback1, true);
    keepDelegate.onAttachedToWindow();
    delegate = new ViewGroupMvpViewStateDelegateImpl<>(androidView, callback, false);
    startViewGroup(1, 1, 1, 1, 1, 0, null, 0, 1, 0);
    finishViewGroup(1, 1, true, false);
    delegate = new ViewGroupMvpViewStateDelegateImpl<>(androidView, callback, false);
    startViewGroup(2, 2, 2, 2, 2, 0, null, 0, 2, 0);
    finishViewGroup(2, 2, false, true);
    keepDelegate.onDetachedFromWindow();
}
Also used : MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) View(android.view.View) MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) Test(org.junit.Test)

Aggregations

MvpView (com.hannesdorfmann.mosby3.mvp.MvpView)21 MvpPresenter (com.hannesdorfmann.mosby3.mvp.MvpPresenter)18 Test (org.junit.Test)15 Bundle (android.os.Bundle)10 ViewState (com.hannesdorfmann.mosby3.mvp.viewstate.ViewState)9 Application (android.app.Application)7 Before (org.junit.Before)6 Fragment (android.support.v4.app.Fragment)4 FragmentActivity (android.support.v4.app.FragmentActivity)4 View (android.view.View)4 Activity (android.app.Activity)3 RestorableViewState (com.hannesdorfmann.mosby3.mvp.viewstate.RestorableViewState)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 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