From b3ada936977cbbdb074dbe70a069c2c7a306219d Mon Sep 17 00:00:00 2001 From: "Ahmed I. Khalil" Date: Tue, 8 Oct 2019 20:07:32 +0200 Subject: [PATCH] [fenix] Closes https://github.com/mozilla-mobile/fenix/issues/5852 - Use createAddedTestFragments in tests. --- .../CreateCollectionFragmentTest.kt | 16 ++-------- .../fenix/components/StoreProviderTest.kt | 29 ++----------------- 2 files changed, 5 insertions(+), 40 deletions(-) diff --git a/app/src/test/java/org/mozilla/fenix/collections/CreateCollectionFragmentTest.kt b/app/src/test/java/org/mozilla/fenix/collections/CreateCollectionFragmentTest.kt index 49a3ebc877..09535f3ea6 100644 --- a/app/src/test/java/org/mozilla/fenix/collections/CreateCollectionFragmentTest.kt +++ b/app/src/test/java/org/mozilla/fenix/collections/CreateCollectionFragmentTest.kt @@ -4,17 +4,16 @@ package org.mozilla.fenix.collections -import androidx.fragment.app.FragmentActivity import androidx.test.ext.junit.runners.AndroidJUnit4 import assertk.assertThat import assertk.assertions.isNotNull import assertk.assertions.isNull import assertk.assertions.isTrue import kotlinx.coroutines.ObsoleteCoroutinesApi +import mozilla.components.support.test.robolectric.createAddedTestFragment import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.TestApplication -import org.robolectric.Robolectric import org.robolectric.annotation.Config @ObsoleteCoroutinesApi @@ -23,18 +22,7 @@ import org.robolectric.annotation.Config class CreateCollectionFragmentTest { @Test fun `creation dialog shows and can be dismissed`() { - val activity = Robolectric.buildActivity(FragmentActivity::class.java) - .create() - .start() - .resume() - .get() - - val fragment = CreateCollectionFragment() - - activity.supportFragmentManager.beginTransaction().apply { - add(fragment, "test") - commitNow() - } + val fragment = createAddedTestFragment { CreateCollectionFragment() } assertThat(fragment.dialog).isNotNull() assertThat(fragment.requireDialog().isShowing).isTrue() diff --git a/app/src/test/java/org/mozilla/fenix/components/StoreProviderTest.kt b/app/src/test/java/org/mozilla/fenix/components/StoreProviderTest.kt index 27bc1b221b..5ea25d0a83 100644 --- a/app/src/test/java/org/mozilla/fenix/components/StoreProviderTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/StoreProviderTest.kt @@ -5,18 +5,17 @@ package org.mozilla.fenix.components import androidx.fragment.app.Fragment -import androidx.fragment.app.FragmentActivity import kotlinx.coroutines.ObsoleteCoroutinesApi import mozilla.components.lib.state.Action import mozilla.components.lib.state.State import mozilla.components.lib.state.Store +import mozilla.components.support.test.robolectric.createAddedTestFragment import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.TestApplication -import org.robolectric.Robolectric import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config @@ -46,18 +45,7 @@ class StoreProviderTest { @Test fun `get returns store`() { - val activity = Robolectric.buildActivity(FragmentActivity::class.java) - .create() - .start() - .resume() - .get() - - val fragment = Fragment() - - activity.supportFragmentManager.beginTransaction().apply { - add(fragment, "test") - commitNow() - } + val fragment = createAddedTestFragment { Fragment() } val store = StoreProvider.get(fragment) { basicStore } assertEquals(basicStore, store) @@ -65,18 +53,7 @@ class StoreProviderTest { @Test fun `get only calls createStore if needed`() { - val activity = Robolectric.buildActivity(FragmentActivity::class.java) - .create() - .start() - .resume() - .get() - - val fragment = Fragment() - - activity.supportFragmentManager.beginTransaction().apply { - add(fragment, "test") - commitNow() - } + val fragment = createAddedTestFragment { Fragment() } var createCalled = false val createStore = {