Skip to content

Commit

Permalink
MviViewGroup integration tests added for destroying activity early in…
Browse files Browse the repository at this point in the history
… the lifecycle process
  • Loading branch information
sockeqwe committed Apr 24, 2018
1 parent d2048d9 commit 62bcd2a
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mvi-integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ android {

dependencies {
compile project(':mvi')
compile "io.reactivex.rxjava2:rxandroid:"+ rootProject.ext.rxAndroid2Version
compile "io.reactivex.rxjava2:rxandroid:" + rootProject.ext.rxAndroid2Version


androidTestCompile 'com.android.support.test:runner:' + rootProject.ext.androidSupportTestVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2016 Hannes Dorfmann.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.viewgroup;

import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.ViewGroup;

import com.hannesdorfmann.mosby3.ViewGroupMviDelegateImpl;
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter;

import junit.framework.Assert;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class MviViewGroupFinishOnCreateTest {

@Rule
public ActivityTestRule<ViewGroupFinishOnCreateContainerActivity> rule =
new ActivityTestRule<>(ViewGroupFinishOnCreateContainerActivity.class);

@Test
public void screenOrientationChange() throws Exception {
// Context of the app under test.
ViewGroupFinishOnCreateContainerActivity portraitActivity = rule.getActivity();
ViewGroupMviDelegateImpl.DEBUG = true;
ViewGroupFinishOnCreateLayout layout = portraitActivity.getLayout();

Thread.sleep(2000);

Assert.assertNull(layout.presenter);
Assert.assertEquals(0, layout.createPresenterInvocations);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2016 Hannes Dorfmann.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.viewgroup;

import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.hannesdorfmann.mosby3.ViewGroupMviDelegateImpl;

import junit.framework.Assert;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class MviViewGroupFinishOnStartTest {

@Rule
public ActivityTestRule<ViewGroupFinishOnStartContainerActivity> rule =
new ActivityTestRule<>(ViewGroupFinishOnStartContainerActivity.class);

@Test
public void screenOrientationChange() throws Exception {
// Context of the app under test.
ViewGroupFinishOnStartContainerActivity portraitActivity = rule.getActivity();
ViewGroupMviDelegateImpl.DEBUG = true;
ViewGroupFinishOnCreateLayout layout = portraitActivity.getLayout();

Thread.sleep(2000);

Assert.assertNull(layout.presenter);
Assert.assertEquals(0, layout.createPresenterInvocations);
}
}
8 changes: 5 additions & 3 deletions mvi-integration-test/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<activity android:name=".lifecycle.viewgroup.MviViewGroupContainerActivity" />
<activity android:name=".lifecycle.activity.MviFinishInOnCreateActivity" />
<activity android:name=".lifecycle.activity.MviFinishInOnStartActivity" />
<activity android:name=".lifecycle.fragment.MviFinishOnCreateContainerActivity"/>
<activity android:name=".lifecycle.fragment.MviFinishOnStartContainerActivity"/>
<activity android:name=".lifecycle.fragment.MviFinishOnCreateContainerActivity" />
<activity android:name=".lifecycle.fragment.MviFinishOnStartContainerActivity" />
<activity
android:name=".backstack.BackstackActivity"
android:label="@string/title_activity_backstack"
Expand All @@ -52,7 +52,9 @@
<activity
android:name=".eager.EagerViewActivity"
android:label="@string/title_activity_eager_view"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".lifecycle.viewgroup.ViewGroupFinishOnCreateContainerActivity" />
<activity android:name=".lifecycle.viewgroup.ViewGroupFinishOnStartContainerActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.viewgroup;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.hannesdorfmann.mosby3.mvi.integrationtest.R;

public class ViewGroupFinishOnCreateContainerActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_group_finish_on_create_container);
finish();
}

public ViewGroupFinishOnCreateLayout getLayout() {
return (ViewGroupFinishOnCreateLayout) findViewById(R.id.mviLayout);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.viewgroup;

import android.content.Context;
import android.util.AttributeSet;

import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter;
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestView;
import com.hannesdorfmann.mosby3.mvi.layout.MviFrameLayout;

public class ViewGroupFinishOnCreateLayout extends MviFrameLayout<LifecycleTestView, LifecycleTestPresenter> implements LifecycleTestView {

public LifecycleTestPresenter presenter;
public int createPresenterInvocations;

public ViewGroupFinishOnCreateLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public LifecycleTestPresenter createPresenter() {
createPresenterInvocations++;
presenter = new LifecycleTestPresenter();
return presenter;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.viewgroup;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.hannesdorfmann.mosby3.mvi.integrationtest.R;

public class ViewGroupFinishOnStartContainerActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_group_finish_on_create_container);
}

@Override
protected void onStart() {
super.onStart();
finish();
}

public ViewGroupFinishOnCreateLayout getLayout() {
return (ViewGroupFinishOnCreateLayout) findViewById(R.id.mviLayout);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.viewgroup.ViewGroupFinishOnCreateLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mviLayout"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".lifecycle.viewgroup.ViewGroupFinishOnCreateContainerActivity">

</com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.viewgroup.ViewGroupFinishOnCreateLayout>

0 comments on commit 62bcd2a

Please sign in to comment.