com.hannesdorfmann.mosby3.mvp.MvpView Java Examples

The following examples show how to use com.hannesdorfmann.mosby3.mvp.MvpView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MvpViewStateConductorLifecycleTest.java    From mosby-conductor with Apache License 2.0 6 votes vote down vote up
@Test public void createAndSetNewViewState() {
  MvpPresenter<MvpView> presenter = Mockito.mock(MvpPresenter.class);
  Controller controller = PowerMockito.mock(Controller.class);
  View view = Mockito.mock(View.class);
  MvpView mvpView = Mockito.mock(MvpView.class);
  ViewState<MvpView> viewState = Mockito.mock(ViewState.class);

  MvpViewStateConductorDelegateCallback<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>>
      callback = Mockito.mock(MvpViewStateConductorDelegateCallback.class);

  Mockito.when(callback.getPresenter()).thenReturn(presenter);
  Mockito.when(callback.getMvpView()).thenReturn(mvpView);
  Mockito.when(callback.getViewState()).thenReturn(null);
  Mockito.when(callback.createViewState()).thenReturn(viewState);

  MvpViewStateConductorLifecycleListener<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>>
      lifecycleListener = new MvpViewStateConductorLifecycleListener<>(callback);

  lifecycleListener.postCreateView(controller, view);
  lifecycleListener.preAttach(controller, view);

  Mockito.verify(callback, Mockito.times(1)).getViewState();
  Mockito.verify(callback, Mockito.times(1)).createViewState();
  Mockito.verify(callback, Mockito.times(1)).setViewState(viewState);
  Mockito.verify(callback, Mockito.times(1)).onNewViewStateInstance();
}
 
Example #2
Source File: ActivityMvpDelegateImplTest.java    From mosby with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: ActivityMvpViewStateDelegateImplTestNew.java    From mosby with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: ActivityMvpDelegateImplTest.java    From mosby with Apache License 2.0 6 votes vote down vote up
private void finishActivity(ActivityMvpDelegateImpl<MvpView, MvpPresenter<MvpView>> delegate,
    Bundle bundle, boolean expectKeepPresenter, int detachViewCount, int destroyCount,
    boolean changingConfigurations, boolean isFinishing) {
  Mockito.when(callback.getPresenter()).thenReturn(presenter);
  Mockito.when(activity.isChangingConfigurations()).thenReturn(changingConfigurations);
  Mockito.when(activity.isFinishing()).thenReturn(isFinishing);

  delegate.onPause();
  delegate.onSaveInstanceState(bundle);
  delegate.onStop();
  delegate.onDestroy();
  delegate.onRestart();

  Mockito.verify(presenter, Mockito.times(detachViewCount)).detachView();
  if (!expectKeepPresenter) Mockito.verify(presenter, Mockito.times(destroyCount)).destroy();
}
 
Example #5
Source File: ViewGroupMvpDelegateImplTest.java    From mosby with Apache License 2.0 6 votes vote down vote up
@Before public void initComponents() {
  view = new MvpView() {
  };
  savedState = null;

  presenter = Mockito.mock(MvpPresenter.class);
  callback = Mockito.mock(PartialViewGroupMvpDelegateCallbackImpl.class);
  Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
  Mockito.doCallRealMethod().when(callback).getPresenter();
  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(androidView.isInEditMode()).thenReturn(false);

  delegate = new ViewGroupMvpDelegateImpl<>(androidView, callback, true);
}
 
Example #6
Source File: FragmentMvpDelegateImplTest.java    From mosby with Apache License 2.0 6 votes vote down vote up
@Before public void initComponents() {
  view = new MvpView() {
  };

  presenter = Mockito.mock(MvpPresenter.class);
  callback = Mockito.mock(PartialMvpDelegateCallbackImpl.class);
  Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
  Mockito.doCallRealMethod().when(callback).getPresenter();

  fragment = PowerMockito.mock(Fragment.class);
  activity = Mockito.mock(FragmentActivity.class);
  application = Mockito.mock(Application.class);

  Mockito.when(callback.getMvpView()).thenReturn(view);
  Mockito.when(fragment.getActivity()).thenReturn(activity);

  Mockito.when(activity.getApplication()).thenReturn(application);

  delegate = new FragmentMvpDelegateImpl<>(fragment, callback, true, true);
}
 
Example #7
Source File: ActivityScopedCache.java    From mosby with Apache License 2.0 6 votes vote down vote up
/**
 * Put the presenter in the internal cache
 *
 * @param viewId The mosby internal View id of the {@link MvpView} which the presenter is
 * associated to.
 * @param presenter The Presenter
 */
public void putPresenter(@NonNull String viewId,
    @NonNull MvpPresenter<? extends MvpView> presenter) {

  if (viewId == null) {
    throw new NullPointerException("ViewId is null");
  }

  if (presenter == null) {
    throw new NullPointerException("Presenter is null");
  }

  PresenterHolder presenterHolder = presenterMap.get(viewId);
  if (presenterHolder == null) {
    presenterHolder = new PresenterHolder();
    presenterHolder.presenter = presenter;
    presenterMap.put(viewId, presenterHolder);
  } else {
    presenterHolder.presenter = presenter;
  }
}
 
Example #8
Source File: ActivityMvpViewStateDelegateImplTestNew.java    From mosby with Apache License 2.0 6 votes vote down vote up
@Test public void appStartAfterProcessDeathAndViewStateRecreationFromBundle() {
  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();

  Bundle bundle = BundleMocker.create();
  bundle.putString(ActivityMvpViewStateDelegateImpl.KEY_MOSBY_VIEW_ID, "123456789");

  startActivity(delegate, bundle, 1, 1, 1, 1, 1, 1, false, 1, 0, 1);
}
 
Example #9
Source File: ActivityMvpViewStateDelegateImplTestNew.java    From mosby with Apache License 2.0 6 votes vote down vote up
@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);
  }
 
Example #10
Source File: ActivityMvpViewStateDelegateImplTestNew.java    From mosby with Apache License 2.0 6 votes vote down vote up
private void finishActivity(ActivityMvpDelegateImpl<MvpView, MvpPresenter<MvpView>> delegate,
    Bundle bundle, int detachViewCount, int destroyViewCount, boolean changingConfigurations,
    boolean isFinishing) {
  Mockito.when(callback.getPresenter()).thenReturn(presenter);
  Mockito.when(callback.getViewState()).thenReturn(viewState);
  Mockito.when(activity.isChangingConfigurations()).thenReturn(changingConfigurations);
  Mockito.when(activity.isFinishing()).thenReturn(isFinishing);

  delegate.onPause();
  delegate.onSaveInstanceState(bundle);
  delegate.onStop();
  delegate.onDestroy();
  delegate.onRestart();

  Mockito.verify(presenter, Mockito.times(detachViewCount)).detachView();
  Mockito.verify(presenter, Mockito.times(destroyViewCount)).destroy();
}
 
Example #11
Source File: MvpConductorLifecycleListenerTest.java    From mosby-conductor with Apache License 2.0 6 votes vote down vote up
@Test public void nullPointerExceptionGetPresenter() {
  MvpPresenter<MvpView> presenter = Mockito.mock(MvpPresenter.class);
  Controller controller = Mockito.mock(Controller.class);
  View view = Mockito.mock(View.class);

  MvpConductorDelegateCallback<MvpView, MvpPresenter<MvpView>> callback =
      Mockito.mock(MvpConductorDelegateCallback.class);

  MvpConductorLifecycleListener<MvpView, MvpPresenter<MvpView>> lifecycleListener =
      new MvpConductorLifecycleListener<>(callback);

  Mockito.when(callback.getPresenter()).thenReturn(null);

  try {
    lifecycleListener.preDestroyView(controller, view);
    Assert.fail();
  } catch (NullPointerException e) {
    Assert.assertEquals(e.getMessage(),
        "Presenter returned from getPresenter() is null in " + callback);
  }
}
 
Example #12
Source File: MvpViewStateConductorLifecycleTest.java    From mosby-conductor with Apache License 2.0 6 votes vote down vote up
@Test public void nullPointerOnCreateViewState() {

    MvpPresenter<MvpView> presenter = Mockito.mock(MvpPresenter.class);
    Controller controller = PowerMockito.mock(Controller.class);
    View view = Mockito.mock(View.class);
    MvpView mvpView = Mockito.mock(MvpView.class);

    MvpViewStateConductorDelegateCallback<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>>
        callback = Mockito.mock(MvpViewStateConductorDelegateCallback.class);

    Mockito.when(callback.getPresenter()).thenReturn(presenter);
    Mockito.when(callback.getMvpView()).thenReturn(mvpView);
    Mockito.when(callback.getViewState()).thenReturn(null);
    Mockito.when(callback.createViewState()).thenReturn(null);

    MvpViewStateConductorLifecycleListener<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>>
        lifecycleListener = new MvpViewStateConductorLifecycleListener<>(callback);

    try {
      lifecycleListener.preAttach(controller, view);
      Assert.fail("NullPointerException expected");
    } catch (NullPointerException e) {
      Assert.assertEquals(e.getMessage(),
          "ViewState from createViewState() is null in " + callback);
    }
  }
 
Example #13
Source File: MvpConductorLifecycleListenerTest.java    From mosby-conductor with Apache License 2.0 6 votes vote down vote up
@Test public void dontCreatePresenterIfOneExists() {
  MvpPresenter<MvpView> presenter = Mockito.mock(MvpPresenter.class);
  Controller controller = Mockito.mock(Controller.class);
  View view = Mockito.mock(View.class);
  MvpView mvpView = Mockito.mock(MvpView.class);
  MvpConductorDelegateCallback<MvpView, MvpPresenter<MvpView>> callback =
      Mockito.mock(MvpConductorDelegateCallback.class);

  MvpConductorLifecycleListener<MvpView, MvpPresenter<MvpView>> lifecycleListener =
      new MvpConductorLifecycleListener<>(callback);

  Mockito.when(callback.getPresenter()).thenReturn(presenter);
  Mockito.when(callback.getMvpView()).thenReturn(mvpView);

  lifecycleListener.postCreateView(controller, view);

  Mockito.verify(callback, Mockito.times(1)).getPresenter();
  Mockito.verify(callback, Mockito.never()).createPresenter();
  Mockito.verify(callback, Mockito.never()).setPresenter(presenter);
}
 
Example #14
Source File: MvpConductorLifecycleListenerTest.java    From mosby-conductor with Apache License 2.0 6 votes vote down vote up
@Test public void nullPointerExceptionOnGetMvpView() {

    MvpPresenter<MvpView> presenter = Mockito.mock(MvpPresenter.class);
    Controller controller = Mockito.mock(Controller.class);
    View view = Mockito.mock(View.class);

    MvpConductorDelegateCallback<MvpView, MvpPresenter<MvpView>> callback =
        Mockito.mock(MvpConductorDelegateCallback.class);

    Mockito.when(callback.getPresenter()).thenReturn(presenter);
    Mockito.when(callback.getMvpView()).thenReturn(null);

    MvpConductorLifecycleListener<MvpView, MvpPresenter<MvpView>> lifecycleListener =
        new MvpConductorLifecycleListener<>(callback);

    try {
      lifecycleListener.postCreateView(controller, view);
      Assert.fail("NullpointerException expected");
    } catch (NullPointerException e) {
      Assert.assertEquals(e.getMessage(),
          "MVP View returned from getMvpView() is null in " + callback);
    }
  }
 
Example #15
Source File: MvpConductorLifecycleListenerTest.java    From mosby-conductor with Apache License 2.0 6 votes vote down vote up
@Test public void nullPointerExceptionOnCreatePresenter() {

    Controller controller = Mockito.mock(Controller.class);
    View view = Mockito.mock(View.class);

    MvpConductorDelegateCallback<MvpView, MvpPresenter<MvpView>> callback =
        Mockito.mock(MvpConductorDelegateCallback.class);

    Mockito.when(callback.getPresenter()).thenReturn(null);
    Mockito.when(callback.createPresenter()).thenReturn(null);

    MvpConductorLifecycleListener<MvpView, MvpPresenter<MvpView>> lifecycleListener =
        new MvpConductorLifecycleListener<>(callback);

    try {
      lifecycleListener.postCreateView(controller, view);
      Assert.fail("NullpointerException expected");
    } catch (NullPointerException e) {
      Assert.assertEquals(e.getMessage(),
          "Presenter returned from createPresenter() is null in " + callback);
    }
  }
 
Example #16
Source File: MvpConductorLifecycleListenerTest.java    From mosby-conductor with Apache License 2.0 6 votes vote down vote up
@Test public void createAndSetNewPresenterAndAttachView() {

    MvpPresenter<MvpView> presenter = Mockito.mock(MvpPresenter.class);
    Controller controller = Mockito.mock(Controller.class);
    View view = Mockito.mock(View.class);
    MvpView mvpView = Mockito.mock(MvpView.class);

    MvpConductorDelegateCallback<MvpView, MvpPresenter<MvpView>> callback =
        Mockito.mock(MvpConductorDelegateCallback.class);

    Mockito.when(callback.getPresenter()).thenReturn(null);
    Mockito.when(callback.createPresenter()).thenReturn(presenter);
    Mockito.when(callback.getMvpView()).thenReturn(mvpView);

    MvpConductorLifecycleListener<MvpView, MvpPresenter<MvpView>> lifecycleListener =
        new MvpConductorLifecycleListener<>(callback);

    lifecycleListener.postCreateView(controller, view);

    Mockito.verify(callback, Mockito.times(1)).getPresenter();
    Mockito.verify(callback, Mockito.times(1)).createPresenter();
    Mockito.verify(callback, Mockito.times(1)).setPresenter(presenter);
    Mockito.verify(presenter, Mockito.times(1)).attachView(mvpView);
  }
 
Example #17
Source File: MvpViewStateConductorLifecycleTest.java    From mosby-conductor with Apache License 2.0 6 votes vote down vote up
@Test public void nullPointerExceptionOnSaveViewState() {
  Controller controller = PowerMockito.mock(Controller.class);

  MvpViewStateConductorDelegateCallback<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>>
      callback = Mockito.mock(MvpViewStateConductorDelegateCallback.class);

  MvpViewStateConductorLifecycleListener<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>>
      lifecycleListener = new MvpViewStateConductorLifecycleListener<>(callback);

  Mockito.when(callback.getViewState()).thenReturn(null);
  Bundle bundle = new Bundle();

  try {
    lifecycleListener.onSaveViewState(controller, bundle);
    Assert.fail("NullPointerException expected");
  } catch (NullPointerException e) {
    Assert.assertEquals(e.getMessage(), "ViewState from getViewState() is null in " + callback);
  }
}
 
Example #18
Source File: MvpViewStateConductorLifecycleTest.java    From mosby-conductor with Apache License 2.0 6 votes vote down vote up
@Test public void dontRestoreViewStateBecauseViewStateInMemory() {
  MvpPresenter<MvpView> presenter = Mockito.mock(MvpPresenter.class);
  Controller controller = PowerMockito.mock(Controller.class);
  View view = Mockito.mock(View.class);
  MvpView mvpView = Mockito.mock(MvpView.class);
  ViewState<MvpView> viewState = Mockito.mock(ViewState.class);

  MvpViewStateConductorDelegateCallback<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>>
      callback = Mockito.mock(MvpViewStateConductorDelegateCallback.class);

  MvpViewStateConductorLifecycleListener<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>>
      lifecycleListener = new MvpViewStateConductorLifecycleListener<>(callback);

  Mockito.when(callback.getPresenter()).thenReturn(presenter);
  Mockito.when(callback.getMvpView()).thenReturn(mvpView);
  Mockito.when(callback.getViewState()).thenReturn(viewState);

  Bundle bundle = new Bundle();

  lifecycleListener.changingConfigurations = true; // Simulate screen orientation change
  lifecycleListener.postCreateView(controller, view);
  lifecycleListener.onRestoreViewState(controller, bundle);

  Mockito.verify(callback, Mockito.never()).createViewState();
  Mockito.verify(viewState, Mockito.times(1)).apply(Mockito.eq(mvpView), Mockito.eq(true));
}
 
Example #19
Source File: MviBasePresenterTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
@Test public void bindIntentsAndUnbindIntentsOnlyOnce() {

    final AtomicInteger bindInvocations = new AtomicInteger(0);
    final AtomicInteger unbindInvocations = new AtomicInteger(0);

    MvpView view = new MvpView() {
    };

    MviBasePresenter<MvpView, Object> presenter = new MviBasePresenter<MvpView, Object>() {
      @Override protected void bindIntents() {
        bindInvocations.incrementAndGet();
      }

      @Override protected void unbindIntents() {
        super.unbindIntents();
        unbindInvocations.incrementAndGet();
      }
    };

    presenter.attachView(view);
    presenter.detachView();
    presenter.attachView(view);
    presenter.detachView();
    presenter.attachView(view);
    presenter.detachView();
    presenter.destroy();

    Assert.assertEquals(1, bindInvocations.get());
    Assert.assertEquals(1, unbindInvocations.get());
  }
 
Example #20
Source File: FragmentMvpDelegateImplTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
private void finishFragment(FragmentMvpDelegateImpl<MvpView, MvpPresenter<MvpView>> delegate,
    Bundle bundle, int detachViewCount, int destroyCount,
    boolean changingConfigurations, boolean isFinishing) {
  Mockito.when(callback.getPresenter()).thenReturn(presenter);
  Mockito.when(activity.isChangingConfigurations()).thenReturn(changingConfigurations);
  Mockito.when(activity.isFinishing()).thenReturn(isFinishing);

  finishFragment(delegate, bundle);

  Mockito.verify(presenter, Mockito.times(detachViewCount)).detachView();
  Mockito.verify(presenter, Mockito.times(destroyCount)).destroy();
}
 
Example #21
Source File: FragmentMvpDelegateImplTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if two Fragments 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 dontKeepPresenterWithSecondFragmentInPresenterManager() {

  MvpView view1 = new MvpView() {
  };

  MvpPresenter<MvpView> presenter1 = Mockito.mock(MvpPresenter.class);
  Fragment fragment1 = PowerMockito.mock(Fragment.class);
  PartialMvpDelegateCallbackImpl callback1 = Mockito.mock(PartialMvpDelegateCallbackImpl.class);
  Mockito.doCallRealMethod().when(callback1).setPresenter(presenter1);
  Mockito.doCallRealMethod().when(callback1).getPresenter();
  Mockito.when(callback1.getMvpView()).thenReturn(view1);
  Mockito.when(fragment1.getActivity()).thenReturn(activity);
  Mockito.when(callback1.createPresenter()).thenReturn(presenter1);

  FragmentMvpDelegateImpl<MvpView, MvpPresenter<MvpView>> keepDelegate =
      new FragmentMvpDelegateImpl<>(fragment1, callback1, true, false);

  startFragment(keepDelegate, null);

  FragmentMvpDelegateImpl<MvpView, MvpPresenter<MvpView>> dontKeepDelegate =
      new FragmentMvpDelegateImpl<>(fragment, callback, false, false);

  startFragment(dontKeepDelegate, null, 1, 1, 1);
  Bundle bundle = BundleMocker.create();
  finishFragment(dontKeepDelegate, bundle, 1, 1, true, false);
  startFragment(dontKeepDelegate, null, 2, 2, 2);
  finishFragment(dontKeepDelegate, bundle, 2, 2, false, true);

  Bundle bundle2 = BundleMocker.create();
  finishFragment(keepDelegate, bundle2);
}
 
Example #22
Source File: FragmentMvpDelegateImplTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
private void startFragment(FragmentMvpDelegateImpl<MvpView, MvpPresenter<MvpView>> delegate,
    Bundle bundle) {
  delegate.onAttach((Context) activity);
  delegate.onCreate(bundle);
  delegate.onViewCreated(null, bundle);
  delegate.onActivityCreated(bundle);
  delegate.onStart();
  delegate.onResume();
}
 
Example #23
Source File: FragmentMvpDelegateImplTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
private void startFragment(FragmentMvpDelegateImpl<MvpView, MvpPresenter<MvpView>> delegate,
    Bundle bundle, int createPresenter, int setPresenter, int attachView) {
  Mockito.when(callback.createPresenter()).thenReturn(presenter);

  startFragment(delegate, bundle);

  Mockito.verify(callback, Mockito.times(createPresenter)).createPresenter();
  Mockito.verify(callback, Mockito.times(setPresenter)).setPresenter(presenter);
  Mockito.verify(presenter, Mockito.times(attachView)).attachView(view);
}
 
Example #24
Source File: FragmentMvpDelegateImplTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
private void finishFragment(FragmentMvpDelegateImpl<MvpView, MvpPresenter<MvpView>> delegate,
    Bundle bundle) {
  delegate.onPause();
  delegate.onSaveInstanceState(bundle);
  delegate.onStop();
  delegate.onDestroyView();
  delegate.onDestroy();
  delegate.onDetach();
}
 
Example #25
Source File: ActivityMvpDelegateImplTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
@Test public void appStartWithScreenOrientationChangeAndFinallyFinishing() {

    ActivityMvpDelegateImpl<MvpView, MvpPresenter<MvpView>> delegate =
        new ActivityMvpDelegateImpl<>(activity, callback, true);

    startActivity(delegate, null, 1, 1, 1);
    Bundle bundle = BundleMocker.create();
    finishActivity(delegate, bundle, true, 1, 0, true, false);
    startActivity(delegate, bundle, 1, 2, 2);
    finishActivity(delegate, bundle, false, 2, 1, false, true);
  }
 
Example #26
Source File: FragmentMvpViewStateDelegateImplTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
private void startFragment(
    FragmentMvpViewStateDelegateImpl<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>> delegate,
    Bundle bundle) {

  delegate.onAttach(activity);
  delegate.onCreate(bundle);
  delegate.onViewCreated(null, bundle);
  delegate.onActivityCreated(bundle);
  delegate.onStart();
  delegate.onResume();
}
 
Example #27
Source File: PresenterManagerTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
@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) {
    }

    @Override public void detachView() {
    }

    @Override public void destroy() {
    }
  };

  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));
}
 
Example #28
Source File: PresenterManager.java    From mosby with Apache License 2.0 5 votes vote down vote up
/**
 * Puts the presenter into the internal cache
 *
 * @param activity The parent activity
 * @param viewId the view id (mosby internal)
 * @param presenter the presenter
 */
public static void putPresenter(@NonNull Activity activity, @NonNull String viewId,
    @NonNull MvpPresenter<? extends MvpView> presenter) {
  if (activity == null) {
    throw new NullPointerException("Activity is null");
  }

  ActivityScopedCache scopedCache = getOrCreateActivityScopedCache(activity);
  scopedCache.putPresenter(viewId, presenter);
}
 
Example #29
Source File: FragmentMvpViewStateDelegateImplTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
private void finishFragment(
    FragmentMvpViewStateDelegateImpl<MvpView, MvpPresenter<MvpView>, ViewState<MvpView>> delegate,
    Bundle bundle) {
  delegate.onPause();
  delegate.onSaveInstanceState(bundle);
  delegate.onStop();
  delegate.onDestroyView();
  delegate.onDestroy();
  delegate.onDetach();
}
 
Example #30
Source File: MviBasePresenterTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
@Test public void resetOnViewDetachedPermanently() {
  final AtomicInteger bindInvocations = new AtomicInteger(0);
  final AtomicInteger unbindInvocations = new AtomicInteger(0);

  MvpView view = new MvpView() {
  };

  MviBasePresenter<MvpView, Object> presenter = new MviBasePresenter<MvpView, Object>() {
    @Override protected void bindIntents() {
      bindInvocations.incrementAndGet();
    }

    @Override protected void unbindIntents() {
      super.unbindIntents();
      unbindInvocations.incrementAndGet();
    }
  };

  presenter.attachView(view);
  presenter.detachView();
  presenter.destroy();
  presenter.attachView(view);
  presenter.detachView();
  presenter.attachView(view);
  presenter.detachView();
  presenter.destroy();

  Assert.assertEquals(2, bindInvocations.get());
  Assert.assertEquals(2, unbindInvocations.get());
}