Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6862 from robolectric/piper_410168815
Fix UnsupportedOperationException if a leaked Activity.recreate is called
- Loading branch information
Showing
2 changed files
with
100 additions
and
31 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...tric/src/test/java/org/robolectric/android/controller/ActivityControllerRecreateTest.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,34 @@ | ||
package org.robolectric.android.controller; | ||
|
||
import android.app.Activity; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.Robolectric; | ||
|
||
/** | ||
* This test captures an issue where {@link ActivityController#recreate()} would throw an {@link | ||
* UnsupportedOperationException} if an Activity from a previous test was recreated. | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ActivityControllerRecreateTest { | ||
private static final AtomicReference<ActivityController<Activity>> createdActivity = | ||
new AtomicReference<>(); | ||
|
||
@Before | ||
public void setUp() { | ||
createdActivity.compareAndSet(null, Robolectric.buildActivity(Activity.class).create()); | ||
} | ||
|
||
@Test | ||
public void failsTryingToRecreateActivityFromOtherTest1() { | ||
createdActivity.get().recreate(); | ||
} | ||
|
||
@Test | ||
public void failsTryingToRecreateActivityFromOtherTest2() { | ||
createdActivity.get().recreate(); | ||
} | ||
} |
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