Search in sources :

Example 1 with MviBasePresenter

use of com.hannesdorfmann.mosby3.mvi.MviBasePresenter in project mosby by sockeqwe.

the class MviBasePresenterTest method bindIntentsAndUnbindIntentsOnlyOnce.

@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(true);
    presenter.attachView(view);
    presenter.detachView(true);
    presenter.attachView(view);
    presenter.detachView(false);
    Assert.assertEquals(1, bindInvocations.get());
    Assert.assertEquals(1, unbindInvocations.get());
}
Also used : MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Object(org.omg.CORBA.Object) Test(org.junit.Test)

Example 2 with MviBasePresenter

use of com.hannesdorfmann.mosby3.mvi.MviBasePresenter in project mosby by sockeqwe.

the class MviBasePresenterTest method resetOnViewDetachedPermanently.

@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(false);
    presenter.attachView(view);
    presenter.detachView(true);
    presenter.attachView(view);
    presenter.detachView(false);
    Assert.assertEquals(2, bindInvocations.get());
    Assert.assertEquals(2, unbindInvocations.get());
}
Also used : MvpView(com.hannesdorfmann.mosby3.mvp.MvpView) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Object(org.omg.CORBA.Object) Test(org.junit.Test)

Aggregations

MvpView (com.hannesdorfmann.mosby3.mvp.MvpView)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 Object (org.omg.CORBA.Object)2