forked from sockeqwe/mosby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More integration tests for MviFragment and destroying activity in onS…
…tart or onCreate
- Loading branch information
Showing
8 changed files
with
269 additions
and
36 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...dorfmann/mosby3/mvi/integrationtest/lifecycle/fragment/MviFinishFragmentOnCreateTest.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,47 @@ | ||
/* | ||
* 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.fragment; | ||
|
||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
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 MviFinishFragmentOnCreateTest { | ||
|
||
@Rule public ActivityTestRule<MviFinishOnCreateContainerActivity> rule = | ||
new ActivityTestRule<>(MviFinishOnCreateContainerActivity.class); | ||
|
||
private static LifecycleTestPresenter presenter; | ||
|
||
@Test public void screenOrientationChange() throws Exception { | ||
// Context of the app under test. | ||
MviFinishOnCreateContainerActivity portraitActivity = rule.getActivity(); | ||
Thread.sleep(2000); | ||
Assert.assertNotNull(MviFinishOnCreateFragment.presenter); | ||
Assert.assertEquals(1, MviFinishOnCreateFragment.presenterCreatedCount); | ||
Assert.assertEquals(1, MviFinishOnCreateFragment.presenter.destoryInvoations); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...sdorfmann/mosby3/mvi/integrationtest/lifecycle/fragment/MviFinishFragmentOnStartTest.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,47 @@ | ||
/* | ||
* 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.fragment; | ||
|
||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
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 MviFinishFragmentOnStartTest { | ||
|
||
@Rule public ActivityTestRule<MviFinishOnStartContainerActivity> rule = | ||
new ActivityTestRule<>(MviFinishOnStartContainerActivity.class); | ||
|
||
private static LifecycleTestPresenter presenter; | ||
|
||
@Test public void screenOrientationChange() throws Exception { | ||
// Context of the app under test. | ||
MviFinishOnStartContainerActivity portraitActivity = rule.getActivity(); | ||
Thread.sleep(2000); | ||
Assert.assertNotNull(MviFinishOnStartFragment.presenter); | ||
Assert.assertEquals(1, MviFinishOnStartFragment.presenterCreatedCount); | ||
Assert.assertEquals(1, MviFinishOnStartFragment.presenter.destoryInvoations); | ||
} | ||
|
||
} |
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
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
22 changes: 22 additions & 0 deletions
22
...ann/mosby3/mvi/integrationtest/lifecycle/fragment/MviFinishOnCreateContainerActivity.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,22 @@ | ||
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.fragment; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.FragmentActivity; | ||
|
||
import com.hannesdorfmann.mosby3.mvi.integrationtest.R; | ||
|
||
public class MviFinishOnCreateContainerActivity extends FragmentActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_lifecycle); | ||
|
||
if (savedInstanceState == null) { | ||
MviFinishOnCreateFragment f = new MviFinishOnCreateFragment(); | ||
getSupportFragmentManager().beginTransaction().replace(R.id.container, f).commitNow(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...nnesdorfmann/mosby3/mvi/integrationtest/lifecycle/fragment/MviFinishOnCreateFragment.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,42 @@ | ||
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.fragment; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.FragmentActivity; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.hannesdorfmann.mosby3.mvi.MviFragment; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.R; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestView; | ||
|
||
public class MviFinishOnCreateFragment extends MviFragment<LifecycleTestView, LifecycleTestPresenter> implements LifecycleTestView { | ||
|
||
|
||
public static LifecycleTestPresenter presenter; | ||
public static int presenterCreatedCount; | ||
|
||
@NonNull | ||
@Override | ||
public LifecycleTestPresenter createPresenter() { | ||
presenter = new LifecycleTestPresenter(); | ||
presenterCreatedCount++; | ||
return presenter; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, | ||
@Nullable Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.fragment_mvi, container, false); | ||
} | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
getActivity().finish(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...mann/mosby3/mvi/integrationtest/lifecycle/fragment/MviFinishOnStartContainerActivity.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.fragment; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.FragmentActivity; | ||
|
||
import com.hannesdorfmann.mosby3.mvi.integrationtest.R; | ||
|
||
public class MviFinishOnStartContainerActivity extends FragmentActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_lifecycle); | ||
|
||
if (savedInstanceState == null) { | ||
MviFinishOnStartFragment f = new MviFinishOnStartFragment(); | ||
getSupportFragmentManager().beginTransaction().replace(R.id.container, f).commitNow(); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...annesdorfmann/mosby3/mvi/integrationtest/lifecycle/fragment/MviFinishOnStartFragment.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,41 @@ | ||
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.fragment; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.hannesdorfmann.mosby3.mvi.MviFragment; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.R; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestView; | ||
|
||
public class MviFinishOnStartFragment extends MviFragment<LifecycleTestView, LifecycleTestPresenter> implements LifecycleTestView { | ||
|
||
|
||
public static LifecycleTestPresenter presenter; | ||
public static int presenterCreatedCount; | ||
|
||
@NonNull | ||
@Override | ||
public LifecycleTestPresenter createPresenter() { | ||
presenter = new LifecycleTestPresenter(); | ||
presenterCreatedCount++; | ||
return presenter; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, | ||
@Nullable Bundle savedInstanceState) { | ||
return inflater.inflate(R.layout.fragment_mvi, container, false); | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
super.onStart(); | ||
getActivity().finish(); | ||
} | ||
} |