Skip to content

Commit

Permalink
Mvi integration test refactored to new presenter lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
sockeqwe committed Sep 5, 2017
1 parent 31e88a5 commit 125daec
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hannesdorfmann.mosby3.FragmentMviDelegateImpl;
import com.hannesdorfmann.mosby3.mvi.integrationtest.backstack.BackstackActivity;
import org.junit.AfterClass;
import org.junit.Assert;
Expand All @@ -33,10 +34,8 @@

@Test public void testConfigChange() throws Exception {

// FragmentMviDelegateImpl.DEBUG = true;
FragmentMviDelegateImpl.DEBUG = true;

// Context of the app under test.
BackstackActivity portraitActivity = rule.getActivity();

Thread.sleep(1000);
Assert.assertEquals(1, BackstackActivity.createFirstPresenterCalls.get());
Expand All @@ -63,7 +62,7 @@
Thread.sleep(1000);

Assert.assertEquals(2, BackstackActivity.firstPresenter.detachViewCalls.get());
Assert.assertEquals(1, BackstackActivity.firstPresenter.unbindIntentCalls.get());
Assert.assertEquals(0, BackstackActivity.firstPresenter.unbindIntentCalls.get());
Assert.assertEquals(1, BackstackActivity.createFirstPresenterCalls.get());
Assert.assertEquals(2, BackstackActivity.firstPresenter.attachViewCalls.get());
Assert.assertEquals(1, BackstackActivity.firstPresenter.bindIntentCalls.get());
Expand All @@ -88,14 +87,28 @@
Assert.assertEquals(1, BackstackActivity.secondPresenter.bindIntentCalls.get());

//
// Press back button
// Press back button --> Finish second fragment
//
BackstackActivity.pressBackButton();
Thread.sleep(1000);
}

@AfterClass public static void afterBackButtonPressed() {
Assert.assertEquals(2, BackstackActivity.secondPresenter.detachViewCalls.get());
Assert.assertEquals(1, BackstackActivity.secondPresenter.unbindIntentCalls.get());

//
// First Fragment restored from backstack
//
Assert.assertEquals(1, BackstackActivity.createFirstPresenterCalls.get());
Assert.assertEquals(3, BackstackActivity.firstPresenter.attachViewCalls.get());
Assert.assertEquals(1, BackstackActivity.firstPresenter.bindIntentCalls.get());

// Press back button --> finishes the activity
BackstackActivity.pressBackButton();
Thread.sleep(1000);

}

@AfterClass public static void afterActivityFinished() {
Assert.assertEquals(3, BackstackActivity.firstPresenter.detachViewCalls.get());
Assert.assertEquals(1, BackstackActivity.firstPresenter.unbindIntentCalls.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
Assert.assertEquals(1, portraitActivity.createPresenterInvokations);
Assert.assertEquals(1, presenter.attachViewInvokations);
Assert.assertTrue(presenter.attachedView == portraitActivity);
Assert.assertEquals(1, presenter.bindIntentInvocations);

Thread.sleep(1000);

Expand All @@ -53,18 +54,23 @@
Thread.sleep(1000);

Assert.assertEquals(1, presenter.detachViewInvokations);
Assert.assertTrue(presenter.onDettachViewRetainInstance);

Assert.assertEquals(1, presenter.bindIntentInvocations);
Assert.assertEquals(0, presenter.unbindIntentInvocations);
Assert.assertEquals(0, presenter.destoryInvoations);
Assert.assertEquals(1, MviLifecycleActivity.createPresenterInvokations);
Assert.assertEquals(2, presenter.attachViewInvokations);
Assert.assertTrue(presenter.attachedView != portraitActivity);
Assert.assertTrue(presenter.attachedView != portraitActivity && presenter.attachedView != null);

// Press back button --> Finishes Activity
MviLifecycleActivity.pressBackButton();
Thread.sleep(1000);
}

@AfterClass public static void checkPresenterNotRetained() {

// TODO is there a better way to test after onDestroy() has been called?
Assert.assertNotNull(presenter);
Assert.assertEquals(2, presenter.detachViewInvokations);
Assert.assertFalse(presenter.onDettachViewRetainInstance);
Assert.assertEquals(1, presenter.unbindIntentInvocations);
Assert.assertEquals(1, presenter.destoryInvoations);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter;
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.fragment.childfragment.MviLifecycleChildFragmentActivity;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Rule;
Expand All @@ -44,6 +45,7 @@
Assert.assertNotNull(presenter);
Assert.assertEquals(1, fragment.createPresenterInvokations);
Assert.assertEquals(1, presenter.attachViewInvokations);
Assert.assertEquals(1, presenter.bindIntentInvocations);
Assert.assertTrue(presenter.attachedView == fragment);

Thread.sleep(1000);
Expand All @@ -55,20 +57,25 @@
Thread.sleep(1000);

Assert.assertEquals(1, presenter.detachViewInvokations);
Assert.assertTrue(presenter.onDettachViewRetainInstance);

Assert.assertEquals(1, fragment.createPresenterInvokations);
Assert.assertEquals(2, presenter.attachViewInvokations);
Assert.assertEquals(1, presenter.bindIntentInvocations);
Assert.assertTrue(presenter.attachedView == fragment);


//
// Press back button --> Activity finishes
//
RetainingFragmentContainerActivity.pressBackButton();
Thread.sleep(1000);
}

@AfterClass
public static void checkPresenterNotRetained(){

// TODO is there a better way to test after onDestroy() has been called?
Assert.assertNotNull(presenter);
Assert.assertEquals(2, presenter.detachViewInvokations);
Assert.assertFalse(presenter.onDettachViewRetainInstance);

Assert.assertEquals(1, presenter.destoryInvoations);
Assert.assertEquals(1, presenter.unbindIntentInvocations);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
Assert.assertNotNull(presenter);
Assert.assertEquals(1, fragment.createPresenterInvokations);
Assert.assertEquals(1, presenter.attachViewInvokations);
Assert.assertEquals(1, presenter.bindIntentInvocations);
Assert.assertTrue(presenter.attachedView == fragment);

Thread.sleep(1000);
Expand All @@ -55,19 +56,27 @@
Thread.sleep(1000);

Assert.assertEquals(1, presenter.detachViewInvokations);
Assert.assertTrue(presenter.onDettachViewRetainInstance);
Assert.assertEquals(0, presenter.unbindIntentInvocations);
Assert.assertEquals(0, presenter.destoryInvoations);
Assert.assertEquals(1, fragment.createPresenterInvokations);
Assert.assertEquals(2, presenter.attachViewInvokations);
Assert.assertNotNull(presenter.attachedView);
Assert.assertTrue(presenter.attachedView != fragment);

//
// press back --> Finish Activity
//

SimpleFragmentContainerActivity.pressBackButton();
Thread.sleep(1000);
}

@AfterClass
public static void checkPresenterNotRetained(){

// TODO is there a better way to test after onDestroy() has been called?
Assert.assertNotNull(presenter);
Assert.assertEquals(2, presenter.detachViewInvokations);
Assert.assertFalse(presenter.onDettachViewRetainInstance);
Assert.assertEquals(1, presenter.unbindIntentInvocations);
Assert.assertEquals(1, presenter.destoryInvoations);

}
}

This file was deleted.

Loading

0 comments on commit 125daec

Please sign in to comment.