-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ActivityMviDelegateImpl now checks if presenter != null if Activity.f…
…inish() is called in Activity.onCreate() #290
- Loading branch information
Showing
6 changed files
with
162 additions
and
8 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...rfmann/mosby3/mvi/integrationtest/lifecycle/activity/MviFinishInOnCreateActivityTest.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 @@ | ||
/* | ||
* 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.activity; | ||
|
||
import android.content.pm.ActivityInfo; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) public class MviFinishInOnCreateActivityTest { | ||
|
||
@Rule public ActivityTestRule<MviFinishInOnCreateActivity> rule = | ||
new ActivityTestRule<>(MviFinishInOnCreateActivity.class); | ||
|
||
@Test public void finishInOnCreate() throws Exception { | ||
// Context of the app under test. | ||
MviFinishInOnCreateActivity activity = rule.getActivity(); | ||
activity.onDestroyReached.blockingFirst(); // Waits until onDestroy() is reached | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...orfmann/mosby3/mvi/integrationtest/lifecycle/activity/MviFinishInOnStartActivityTest.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,37 @@ | ||
/* | ||
* 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.activity; | ||
|
||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) public class MviFinishInOnStartActivityTest { | ||
|
||
@Rule public ActivityTestRule<MviFinishInOnStartActivity> rule = | ||
new ActivityTestRule<>(MviFinishInOnStartActivity.class); | ||
|
||
@Test public void finishInOnCreate() throws Exception { | ||
// Context of the app under test. | ||
MviFinishInOnStartActivity activity = rule.getActivity(); | ||
activity.onDestroyReached.blockingFirst(); // Waits until onDestroy() is reached | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...esdorfmann/mosby3/mvi/integrationtest/lifecycle/activity/MviFinishInOnCreateActivity.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,36 @@ | ||
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.activity; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
|
||
import com.hannesdorfmann.mosby3.mvi.MviActivity; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestView; | ||
import io.reactivex.subjects.BehaviorSubject; | ||
import io.reactivex.subjects.Subject; | ||
|
||
public class MviFinishInOnCreateActivity extends MviActivity<LifecycleTestView, LifecycleTestPresenter> implements LifecycleTestView { | ||
|
||
@NonNull | ||
@Override | ||
public LifecycleTestPresenter createPresenter() { | ||
return new LifecycleTestPresenter(); | ||
} | ||
|
||
public Subject<Boolean> onDestroyReached = BehaviorSubject.create(); | ||
|
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
finish(); // finish imeediately is what we would like to test --> App should not crash | ||
} | ||
|
||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
onDestroyReached.onNext(true); | ||
onDestroyReached.onComplete(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...nesdorfmann/mosby3/mvi/integrationtest/lifecycle/activity/MviFinishInOnStartActivity.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,36 @@ | ||
package com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.activity; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
|
||
import com.hannesdorfmann.mosby3.mvi.MviActivity; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestPresenter; | ||
import com.hannesdorfmann.mosby3.mvi.integrationtest.lifecycle.LifecycleTestView; | ||
|
||
import io.reactivex.subjects.BehaviorSubject; | ||
import io.reactivex.subjects.Subject; | ||
|
||
public class MviFinishInOnStartActivity extends MviActivity<LifecycleTestView, LifecycleTestPresenter> implements LifecycleTestView { | ||
|
||
@NonNull | ||
@Override | ||
public LifecycleTestPresenter createPresenter() { | ||
return new LifecycleTestPresenter(); | ||
} | ||
|
||
public Subject<Boolean> onDestroyReached = BehaviorSubject.create(); | ||
|
||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
finish(); // finish --> this is what we would like to test --> App should not crash | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
onDestroyReached.onNext(true); | ||
onDestroyReached.onComplete(); | ||
} | ||
} |
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