From 5b404c271f2055e31919a134f5827e86dcce91de Mon Sep 17 00:00:00 2001 From: Rick Busarow Date: Tue, 19 Apr 2022 15:57:46 -0500 Subject: [PATCH] wrap Activity and Compose rules in LeakCanary checks on both sides fixes #657 --- .../compose/hellocompose/HelloComposeTest.kt | 6 +++--- .../hellocomposebinding/HelloBindingTest.kt | 6 +++--- .../HelloComposeWorkflowTest.kt | 6 +++--- .../inlinerendering/InlineRenderingTest.kt | 6 +++--- .../compose/launcher/SampleLauncherTest.kt | 6 +++--- .../nestedrenderings/NestedRenderingsTest.kt | 6 +++--- .../sample/compose/preview/PreviewTest.kt | 6 +++--- .../sample/compose/textinput/TextInputTest.kt | 6 +++--- .../sample/poetryapp/PoetryAppTest.kt | 6 +++--- .../squareup/sample/ravenapp/RavenAppTest.kt | 6 +++--- .../HelloBackButtonEspressoTest.kt | 6 +++--- .../squareup/sample/dungeon/DungeonAppTest.kt | 6 +++--- .../HelloWorkflowFragmentAppTest.kt | 6 +++--- .../helloworkflow/HelloWorkflowAppTest.kt | 6 +++--- .../stubvisibility/StubVisibilityAppTest.kt | 6 +++--- .../squareup/sample/TicTacToeEspressoTest.kt | 6 +++--- .../sample/mainactivity/TodoAppTest.kt | 6 +++--- .../compose/tooling/PreviewViewFactoryTest.kt | 6 +++--- .../ui/compose/ComposeViewFactoryTest.kt | 6 +++--- .../compose/ComposeViewTreeIntegrationTest.kt | 6 +++--- .../ui/compose/CompositionRootTest.kt | 6 +++--- .../workflow1/ui/compose/RenderAsStateTest.kt | 6 +++--- .../ui/compose/WorkflowRenderingTest.kt | 6 +++--- .../test/BackStackContainerPersistenceTest.kt | 6 +++--- .../test/ModalViewContainerLifecycleTest.kt | 6 +++--- .../ui/WorkflowViewStubLifecycleTest.kt | 6 +++--- .../api/internal-testing-android.api | 4 ++++ .../test/DetectLeaksAfterTestSuccess.kt | 19 ++++++++++++++++++- 28 files changed, 100 insertions(+), 79 deletions(-) diff --git a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocompose/HelloComposeTest.kt b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocompose/HelloComposeTest.kt index a0fac844c..9e77af9ec 100644 --- a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocompose/HelloComposeTest.kt +++ b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocompose/HelloComposeTest.kt @@ -6,9 +6,9 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -19,10 +19,10 @@ import org.junit.runner.RunWith class HelloComposeTest { private val composeRule = createAndroidComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun togglesBetweenStates() { composeRule.onNodeWithText("Hello") diff --git a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocomposebinding/HelloBindingTest.kt b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocomposebinding/HelloBindingTest.kt index e3487972b..714bb9c2f 100644 --- a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocomposebinding/HelloBindingTest.kt +++ b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocomposebinding/HelloBindingTest.kt @@ -6,9 +6,9 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -19,10 +19,10 @@ import org.junit.runner.RunWith class HelloBindingTest { private val composeRule = createAndroidComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun togglesBetweenStates() { composeRule.onNodeWithText("Hello") diff --git a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocomposeworkflow/HelloComposeWorkflowTest.kt b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocomposeworkflow/HelloComposeWorkflowTest.kt index 44b10c1c6..c34242a36 100644 --- a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocomposeworkflow/HelloComposeWorkflowTest.kt +++ b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/hellocomposeworkflow/HelloComposeWorkflowTest.kt @@ -6,9 +6,9 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -19,10 +19,10 @@ import org.junit.runner.RunWith class HelloComposeWorkflowTest { private val composeRule = createAndroidComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun togglesBetweenStates() { composeRule.onNodeWithText("Hello") diff --git a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/inlinerendering/InlineRenderingTest.kt b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/inlinerendering/InlineRenderingTest.kt index a18132abe..f6ee11b2c 100644 --- a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/inlinerendering/InlineRenderingTest.kt +++ b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/inlinerendering/InlineRenderingTest.kt @@ -7,9 +7,9 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.performClick import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -20,10 +20,10 @@ import org.junit.runner.RunWith class InlineRenderingTest { private val composeRule = createAndroidComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun counterIncrements() { composeRule.onNode(hasClickAction()) diff --git a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/launcher/SampleLauncherTest.kt b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/launcher/SampleLauncherTest.kt index 44be9bf8c..3cf99e073 100644 --- a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/launcher/SampleLauncherTest.kt +++ b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/launcher/SampleLauncherTest.kt @@ -12,9 +12,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import com.squareup.sample.compose.R import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -25,10 +25,10 @@ import org.junit.runner.RunWith class SampleLauncherTest { private val composeRule = createAndroidComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @OptIn(ExperimentalTestApi::class) @Test fun allSamplesLaunch() { diff --git a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/nestedrenderings/NestedRenderingsTest.kt b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/nestedrenderings/NestedRenderingsTest.kt index f197c2a68..cdc177928 100644 --- a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/nestedrenderings/NestedRenderingsTest.kt +++ b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/nestedrenderings/NestedRenderingsTest.kt @@ -10,9 +10,9 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -25,10 +25,10 @@ private const val ADD_BUTTON_TEXT = "Add Child" class NestedRenderingsTest { private val composeRule = createAndroidComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun childrenAreAddedAndRemoved() { composeRule.onNodeWithText(ADD_BUTTON_TEXT) diff --git a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/preview/PreviewTest.kt b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/preview/PreviewTest.kt index 71191ceae..1c92a12bd 100644 --- a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/preview/PreviewTest.kt +++ b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/preview/PreviewTest.kt @@ -6,9 +6,9 @@ import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithText import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -19,10 +19,10 @@ import org.junit.runner.RunWith class PreviewTest { private val composeRule = createAndroidComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun showsPreviewRendering() { composeRule.onNodeWithText(ContactDetailsRendering::class.java.simpleName, substring = true) diff --git a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/textinput/TextInputTest.kt b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/textinput/TextInputTest.kt index a2a7932cb..2eb311490 100644 --- a/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/textinput/TextInputTest.kt +++ b/samples/compose-samples/src/androidTest/java/com/squareup/sample/compose/textinput/TextInputTest.kt @@ -10,9 +10,9 @@ import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.performTextReplacement import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -23,10 +23,10 @@ import org.junit.runner.RunWith class TextInputTest { private val composeRule = createAndroidComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @OptIn(ExperimentalTestApi::class) @Test fun allowsTextEditing() { diff --git a/samples/containers/app-poetry/src/androidTest/java/com/squareup/sample/poetryapp/PoetryAppTest.kt b/samples/containers/app-poetry/src/androidTest/java/com/squareup/sample/poetryapp/PoetryAppTest.kt index 46f8c8c2f..a9a736560 100644 --- a/samples/containers/app-poetry/src/androidTest/java/com/squareup/sample/poetryapp/PoetryAppTest.kt +++ b/samples/containers/app-poetry/src/androidTest/java/com/squareup/sample/poetryapp/PoetryAppTest.kt @@ -7,9 +7,9 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.sample.container.poetryapp.R import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule import com.squareup.workflow1.ui.internal.test.inAnyView +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -20,9 +20,9 @@ import org.junit.runner.RunWith class PoetryAppTest { private val scenarioRule = ActivityScenarioRule(PoetryActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun launches() { inAnyView(withText(R.string.poems)) diff --git a/samples/containers/app-raven/src/androidTest/java/com/squareup/sample/ravenapp/RavenAppTest.kt b/samples/containers/app-raven/src/androidTest/java/com/squareup/sample/ravenapp/RavenAppTest.kt index 2dbc5d799..179438f90 100644 --- a/samples/containers/app-raven/src/androidTest/java/com/squareup/sample/ravenapp/RavenAppTest.kt +++ b/samples/containers/app-raven/src/androidTest/java/com/squareup/sample/ravenapp/RavenAppTest.kt @@ -6,9 +6,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule import com.squareup.workflow1.ui.internal.test.inAnyView +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -19,9 +19,9 @@ import org.junit.runner.RunWith class RavenAppTest { private val scenarioRule = ActivityScenarioRule(RavenActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun launches() { inAnyView(withText("The Raven")) diff --git a/samples/containers/hello-back-button/src/androidTest/java/com/squareup/sample/hellobackbutton/HelloBackButtonEspressoTest.kt b/samples/containers/hello-back-button/src/androidTest/java/com/squareup/sample/hellobackbutton/HelloBackButtonEspressoTest.kt index a08b9cc9d..91c117eb5 100644 --- a/samples/containers/hello-back-button/src/androidTest/java/com/squareup/sample/hellobackbutton/HelloBackButtonEspressoTest.kt +++ b/samples/containers/hello-back-button/src/androidTest/java/com/squareup/sample/hellobackbutton/HelloBackButtonEspressoTest.kt @@ -8,10 +8,10 @@ import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule import com.squareup.workflow1.ui.internal.test.actuallyPressBack import com.squareup.workflow1.ui.internal.test.inAnyView +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -22,9 +22,9 @@ import org.junit.runner.RunWith class HelloBackButtonEspressoTest { private val scenarioRule = ActivityScenarioRule(HelloBackButtonActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun wrappedTakesPrecedence() { inAnyView(withId(R.id.hello_message)).apply { diff --git a/samples/dungeon/app/src/androidTest/java/com/squareup/sample/dungeon/DungeonAppTest.kt b/samples/dungeon/app/src/androidTest/java/com/squareup/sample/dungeon/DungeonAppTest.kt index ae7ca336b..b53aced79 100644 --- a/samples/dungeon/app/src/androidTest/java/com/squareup/sample/dungeon/DungeonAppTest.kt +++ b/samples/dungeon/app/src/androidTest/java/com/squareup/sample/dungeon/DungeonAppTest.kt @@ -6,9 +6,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule import com.squareup.workflow1.ui.internal.test.inAnyView +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -19,9 +19,9 @@ import org.junit.runner.RunWith class DungeonAppTest { private val scenarioRule = ActivityScenarioRule(DungeonActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun loadsBoardsList() { inAnyView(withText(R.string.boards_list_label)) diff --git a/samples/hello-workflow-fragment/src/androidTest/java/com/squareup/sample/helloworkflowfragment/HelloWorkflowFragmentAppTest.kt b/samples/hello-workflow-fragment/src/androidTest/java/com/squareup/sample/helloworkflowfragment/HelloWorkflowFragmentAppTest.kt index 065e67129..b4726210e 100644 --- a/samples/hello-workflow-fragment/src/androidTest/java/com/squareup/sample/helloworkflowfragment/HelloWorkflowFragmentAppTest.kt +++ b/samples/hello-workflow-fragment/src/androidTest/java/com/squareup/sample/helloworkflowfragment/HelloWorkflowFragmentAppTest.kt @@ -7,9 +7,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule import com.squareup.workflow1.ui.internal.test.inAnyView +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.hamcrest.Matchers.containsString import org.junit.Rule import org.junit.Test @@ -21,9 +21,9 @@ import org.junit.runner.RunWith class HelloWorkflowFragmentAppTest { private val scenarioRule = ActivityScenarioRule(HelloWorkflowFragmentActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun togglesHelloAndGoodbye() { inAnyView(withText(containsString("Hello"))) diff --git a/samples/hello-workflow/src/androidTest/java/com/squareup/sample/helloworkflow/HelloWorkflowAppTest.kt b/samples/hello-workflow/src/androidTest/java/com/squareup/sample/helloworkflow/HelloWorkflowAppTest.kt index 47791f35f..7aea9c90d 100644 --- a/samples/hello-workflow/src/androidTest/java/com/squareup/sample/helloworkflow/HelloWorkflowAppTest.kt +++ b/samples/hello-workflow/src/androidTest/java/com/squareup/sample/helloworkflow/HelloWorkflowAppTest.kt @@ -7,9 +7,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule import com.squareup.workflow1.ui.internal.test.inAnyView +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -20,9 +20,9 @@ import org.junit.runner.RunWith class HelloWorkflowAppTest { private val scenarioRule = ActivityScenarioRule(HelloWorkflowActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun togglesHelloAndGoodbye() { inAnyView(withText("Hello")) diff --git a/samples/stub-visibility/src/androidTest/java/com/squareup/sample/stubvisibility/StubVisibilityAppTest.kt b/samples/stub-visibility/src/androidTest/java/com/squareup/sample/stubvisibility/StubVisibilityAppTest.kt index b47b0dd2f..27be39c22 100644 --- a/samples/stub-visibility/src/androidTest/java/com/squareup/sample/stubvisibility/StubVisibilityAppTest.kt +++ b/samples/stub-visibility/src/androidTest/java/com/squareup/sample/stubvisibility/StubVisibilityAppTest.kt @@ -8,9 +8,9 @@ import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule import com.squareup.workflow1.ui.internal.test.inAnyView +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.hamcrest.CoreMatchers.not import org.junit.Rule import org.junit.Test @@ -22,9 +22,9 @@ import org.junit.runner.RunWith internal class StubVisibilityAppTest { private val scenarioRule = ActivityScenarioRule(StubVisibilityActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun togglesFooter() { inAnyView(withId(R.id.should_be_wrapped)) diff --git a/samples/tictactoe/app/src/androidTest/java/com/squareup/sample/TicTacToeEspressoTest.kt b/samples/tictactoe/app/src/androidTest/java/com/squareup/sample/TicTacToeEspressoTest.kt index d369dffe6..f467a1409 100644 --- a/samples/tictactoe/app/src/androidTest/java/com/squareup/sample/TicTacToeEspressoTest.kt +++ b/samples/tictactoe/app/src/androidTest/java/com/squareup/sample/TicTacToeEspressoTest.kt @@ -28,10 +28,10 @@ import com.squareup.workflow1.ui.ViewEnvironment import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.environment import com.squareup.workflow1.ui.getRendering -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule import com.squareup.workflow1.ui.internal.test.actuallyPressBack import com.squareup.workflow1.ui.internal.test.inAnyView +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.hamcrest.CoreMatchers.allOf import org.hamcrest.CoreMatchers.endsWith import org.junit.After @@ -52,9 +52,9 @@ import java.util.concurrent.atomic.AtomicReference class TicTacToeEspressoTest { private val scenarioRule = ActivityScenarioRule(TicTacToeActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() private val scenario get() = scenarioRule.scenario @Before diff --git a/samples/todo-android/app/src/androidTest/java/com/squareup/sample/mainactivity/TodoAppTest.kt b/samples/todo-android/app/src/androidTest/java/com/squareup/sample/mainactivity/TodoAppTest.kt index 07b37fd3c..b72bf191f 100644 --- a/samples/todo-android/app/src/androidTest/java/com/squareup/sample/mainactivity/TodoAppTest.kt +++ b/samples/todo-android/app/src/androidTest/java/com/squareup/sample/mainactivity/TodoAppTest.kt @@ -12,10 +12,10 @@ import androidx.test.uiautomator.UiDevice import com.squareup.sample.todo.R import com.squareup.sample.todo.ToDoActivity import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule import com.squareup.workflow1.ui.internal.test.actuallyPressBack import com.squareup.workflow1.ui.internal.test.inAnyView +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.hamcrest.Matchers.allOf import org.junit.After import org.junit.Before @@ -29,9 +29,9 @@ import org.junit.runner.RunWith class TodoAppTest { private val scenarioRule = ActivityScenarioRule(ToDoActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() private val uiDevice by lazy { UiDevice.getInstance(getInstrumentation()) } @Before diff --git a/workflow-ui/compose-tooling/src/androidTest/java/com/squareup/workflow1/ui/compose/tooling/PreviewViewFactoryTest.kt b/workflow-ui/compose-tooling/src/androidTest/java/com/squareup/workflow1/ui/compose/tooling/PreviewViewFactoryTest.kt index c3c7c13cb..9b5191887 100644 --- a/workflow-ui/compose-tooling/src/androidTest/java/com/squareup/workflow1/ui/compose/tooling/PreviewViewFactoryTest.kt +++ b/workflow-ui/compose-tooling/src/androidTest/java/com/squareup/workflow1/ui/compose/tooling/PreviewViewFactoryTest.kt @@ -18,9 +18,9 @@ import com.squareup.workflow1.ui.ViewEnvironmentKey import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.compose.WorkflowRendering import com.squareup.workflow1.ui.compose.composeViewFactory -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -31,10 +31,10 @@ import org.junit.runner.RunWith internal class PreviewViewFactoryTest { private val composeRule = createComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun singleChild() { composeRule.setContent { diff --git a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/ComposeViewFactoryTest.kt b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/ComposeViewFactoryTest.kt index a429344e1..406124c30 100644 --- a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/ComposeViewFactoryTest.kt +++ b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/ComposeViewFactoryTest.kt @@ -21,9 +21,9 @@ import com.squareup.workflow1.ui.ViewEnvironmentKey import com.squareup.workflow1.ui.ViewRegistry import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.WorkflowViewStub -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -35,10 +35,10 @@ internal class ComposeViewFactoryTest { private val composeRule = createComposeRule() @get:Rule val rules: RuleChain = - RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun showsComposeContent() { val viewFactory = composeViewFactory { _, _ -> diff --git a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/ComposeViewTreeIntegrationTest.kt b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/ComposeViewTreeIntegrationTest.kt index 019f68890..805f9ea1d 100644 --- a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/ComposeViewTreeIntegrationTest.kt +++ b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/ComposeViewTreeIntegrationTest.kt @@ -32,10 +32,10 @@ import com.squareup.workflow1.ui.ViewRegistry import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.backstack.BackStackScreen import com.squareup.workflow1.ui.bindShowRendering -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule import com.squareup.workflow1.ui.internal.test.WorkflowUiTestActivity +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import com.squareup.workflow1.ui.modal.HasModals import com.squareup.workflow1.ui.modal.ModalViewContainer import org.junit.Before @@ -48,10 +48,10 @@ import kotlin.reflect.KClass internal class ComposeViewTreeIntegrationTest { private val composeRule = createAndroidComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() private val scenario get() = composeRule.activityRule.scenario diff --git a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/CompositionRootTest.kt b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/CompositionRootTest.kt index 6e5efc4b8..e45e4e27a 100644 --- a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/CompositionRootTest.kt +++ b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/CompositionRootTest.kt @@ -8,9 +8,9 @@ import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText import androidx.test.ext.junit.runners.AndroidJUnit4 import com.squareup.workflow1.ui.WorkflowUiExperimentalApi -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -21,10 +21,10 @@ import org.junit.runner.RunWith internal class CompositionRootTest { private val composeRule = createComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun wrappedWithRootIfNecessary_wrapsWhenNecessary() { val root: CompositionRoot = { content -> diff --git a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/RenderAsStateTest.kt b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/RenderAsStateTest.kt index b2f505ce6..e943a1f55 100644 --- a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/RenderAsStateTest.kt +++ b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/RenderAsStateTest.kt @@ -24,9 +24,9 @@ import com.squareup.workflow1.rendering import com.squareup.workflow1.stateless import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.compose.RenderAsStateTest.SnapshottingWorkflow.SnapshottedRendering -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import com.squareup.workflow1.writeUtf8WithLength import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.Job @@ -47,10 +47,10 @@ import kotlin.test.assertFailsWith internal class RenderAsStateTest { private val composeRule = createComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun passesPropsThrough() { val workflow = Workflow.stateless { it } diff --git a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/WorkflowRenderingTest.kt b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/WorkflowRenderingTest.kt index 1771ac74a..b67e787f2 100644 --- a/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/WorkflowRenderingTest.kt +++ b/workflow-ui/compose/src/androidTest/java/com/squareup/workflow1/ui/compose/WorkflowRenderingTest.kt @@ -67,9 +67,9 @@ import com.squareup.workflow1.ui.ViewFactory import com.squareup.workflow1.ui.ViewRegistry import com.squareup.workflow1.ui.WorkflowUiExperimentalApi import com.squareup.workflow1.ui.bindShowRendering -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdleAfterTestRule import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.hamcrest.Description import org.hamcrest.TypeSafeMatcher import org.junit.Rule @@ -83,10 +83,10 @@ import kotlin.reflect.KClass internal class WorkflowRenderingTest { private val composeRule = createComposeRule() - @get:Rule val rules: RuleChain = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(IdleAfterTestRule) + @get:Rule val rules: RuleChain = RuleChain.outerRule(IdleAfterTestRule) .around(composeRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() @Test fun doesNotRecompose_whenFactoryChanged() { val registry1 = ViewRegistry( diff --git a/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/backstack/test/BackStackContainerPersistenceTest.kt b/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/backstack/test/BackStackContainerPersistenceTest.kt index 3feb436ac..9f2f918ac 100644 --- a/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/backstack/test/BackStackContainerPersistenceTest.kt +++ b/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/backstack/test/BackStackContainerPersistenceTest.kt @@ -17,8 +17,8 @@ import com.squareup.workflow1.ui.backstack.test.fixtures.NoTransitionBackStackCo import com.squareup.workflow1.ui.backstack.test.fixtures.ViewStateTestView import com.squareup.workflow1.ui.backstack.test.fixtures.viewForScreen import com.squareup.workflow1.ui.backstack.test.fixtures.waitForScreen -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -32,9 +32,9 @@ internal class BackStackContainerPersistenceTest { private val scenarioRule = ActivityScenarioRule(BackStackContainerLifecycleActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() private val scenario get() = scenarioRule.scenario // region Basic instance state save/restore tests diff --git a/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/modal/test/ModalViewContainerLifecycleTest.kt b/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/modal/test/ModalViewContainerLifecycleTest.kt index b5101887a..b9e7c780d 100644 --- a/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/modal/test/ModalViewContainerLifecycleTest.kt +++ b/workflow-ui/container-android/src/androidTest/java/com/squareup/workflow1/ui/modal/test/ModalViewContainerLifecycleTest.kt @@ -5,8 +5,8 @@ import androidx.lifecycle.Lifecycle.State.RESUMED import androidx.lifecycle.LifecycleOwner import androidx.test.ext.junit.rules.ActivityScenarioRule import com.google.common.truth.Truth.assertThat -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import com.squareup.workflow1.ui.modal.ModalViewContainer import com.squareup.workflow1.ui.modal.test.ModalViewContainerLifecycleActivity.TestRendering.LeafRendering import com.squareup.workflow1.ui.modal.test.ModalViewContainerLifecycleActivity.TestRendering.RecurseRendering @@ -21,9 +21,9 @@ internal class ModalViewContainerLifecycleTest { private val scenarioRule = ActivityScenarioRule(ModalViewContainerLifecycleActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() private val scenario get() = scenarioRule.scenario /** diff --git a/workflow-ui/core-android/src/androidTest/java/com/squareup/workflow1/ui/WorkflowViewStubLifecycleTest.kt b/workflow-ui/core-android/src/androidTest/java/com/squareup/workflow1/ui/WorkflowViewStubLifecycleTest.kt index c87a24c3f..15920f62e 100644 --- a/workflow-ui/core-android/src/androidTest/java/com/squareup/workflow1/ui/WorkflowViewStubLifecycleTest.kt +++ b/workflow-ui/core-android/src/androidTest/java/com/squareup/workflow1/ui/WorkflowViewStubLifecycleTest.kt @@ -29,8 +29,8 @@ import com.squareup.workflow1.ui.WorkflowViewStubLifecycleActivity.TestRendering import com.squareup.workflow1.ui.WorkflowViewStubLifecycleActivity.TestRendering.LeafRendering import com.squareup.workflow1.ui.WorkflowViewStubLifecycleActivity.TestRendering.RecurseRendering import com.squareup.workflow1.ui.WorkflowViewStubLifecycleActivity.TestRendering.ViewRendering -import com.squareup.workflow1.ui.internal.test.DetectLeaksAfterTestSuccess import com.squareup.workflow1.ui.internal.test.IdlingDispatcherRule +import com.squareup.workflow1.ui.internal.test.wrapInLeakCanary import org.hamcrest.Matchers.equalTo import org.junit.Rule import org.junit.Test @@ -44,9 +44,9 @@ internal class WorkflowViewStubLifecycleTest { private val scenarioRule = ActivityScenarioRule(WorkflowViewStubLifecycleActivity::class.java) - @get:Rule val rules = RuleChain.outerRule(DetectLeaksAfterTestSuccess()) - .around(scenarioRule) + @get:Rule val rules = RuleChain.outerRule(scenarioRule) .around(IdlingDispatcherRule) + .wrapInLeakCanary() private val scenario get() = scenarioRule.scenario /** diff --git a/workflow-ui/internal-testing-android/api/internal-testing-android.api b/workflow-ui/internal-testing-android/api/internal-testing-android.api index 67658f585..79dc45ddd 100644 --- a/workflow-ui/internal-testing-android/api/internal-testing-android.api +++ b/workflow-ui/internal-testing-android/api/internal-testing-android.api @@ -54,6 +54,10 @@ public final class com/squareup/workflow1/ui/internal/test/DetectLeaksAfterTestS public fun apply (Lorg/junit/runners/model/Statement;Lorg/junit/runner/Description;)Lorg/junit/runners/model/Statement; } +public final class com/squareup/workflow1/ui/internal/test/DetectLeaksAfterTestSuccessKt { + public static final fun wrapInLeakCanary (Lorg/junit/rules/TestRule;)Lorg/junit/rules/RuleChain; +} + public final class com/squareup/workflow1/ui/internal/test/EspressoKt { public static final fun actuallyPressBack ()V public static final fun inAnyView (Lorg/hamcrest/Matcher;)Landroidx/test/espresso/ViewInteraction; diff --git a/workflow-ui/internal-testing-android/src/main/java/com/squareup/workflow1/ui/internal/test/DetectLeaksAfterTestSuccess.kt b/workflow-ui/internal-testing-android/src/main/java/com/squareup/workflow1/ui/internal/test/DetectLeaksAfterTestSuccess.kt index 7a2dae6ff..0268f05ae 100644 --- a/workflow-ui/internal-testing-android/src/main/java/com/squareup/workflow1/ui/internal/test/DetectLeaksAfterTestSuccess.kt +++ b/workflow-ui/internal-testing-android/src/main/java/com/squareup/workflow1/ui/internal/test/DetectLeaksAfterTestSuccess.kt @@ -1,7 +1,10 @@ package com.squareup.workflow1.ui.internal.test +import android.os.SystemClock import leakcanary.AppWatcher +import leakcanary.KeyedWeakReference.Companion.heapDumpUptimeMillis import leakcanary.LeakAssertions +import org.junit.rules.RuleChain import org.junit.rules.TestRule import org.junit.runner.Description import org.junit.runners.model.Statement @@ -25,15 +28,29 @@ public class DetectLeaksAfterTestSuccess( return object : Statement() { override fun evaluate() { // If the test fails, evaluate() will throw and we won't run the analysis (which is good). + var heapDumpUptimeMillis = 0L try { base.evaluate() + heapDumpUptimeMillis = SystemClock.uptimeMillis() LeakAssertions.assertNoLeaks(tag) } finally { // Otherwise upstream test failures will be reported as leaks. // https://github.com/square/leakcanary/issues/2297 - AppWatcher.objectWatcher.clearWatchedObjects() + AppWatcher.objectWatcher.clearObjectsWatchedBefore(heapDumpUptimeMillis) } } } } } + +/** + * Invokes [LeakAssertions.assertNoLeaks] before performing the tear-down logic of the receiver + * [TestRule], then again *after* the other rule's logic. + * + * https://github.com/square/workflow-kotlin/issues/657 + */ +public fun TestRule.wrapInLeakCanary(): RuleChain = requireNotNull( + RuleChain.outerRule(DetectLeaksAfterTestSuccess()) + .around(this) + .around(DetectLeaksAfterTestSuccess()) +)