-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MviViewGroup integration tests added for destroying activity early in…
… the lifecycle process
- Loading branch information
Showing
8 changed files
with
189 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...rfmann/mosby3/mvi/integrationtest/lifecycle/viewgroup/MviViewGroupFinishOnCreateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...orfmann/mosby3/mvi/integrationtest/lifecycle/viewgroup/MviViewGroupFinishOnStartTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...by3/mvi/integrationtest/lifecycle/viewgroup/ViewGroupFinishOnCreateContainerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...orfmann/mosby3/mvi/integrationtest/lifecycle/viewgroup/ViewGroupFinishOnCreateLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...sby3/mvi/integrationtest/lifecycle/viewgroup/ViewGroupFinishOnStartContainerActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
mvi-integration-test/src/main/res/layout/activity_view_group_finish_on_create_container.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |