Closes #4719: Get rid of fragment-testing dependency and create fragments in StoreProviderTest manually. (#4722)
parent
e6f9445d11
commit
b733fcdbd5
|
@ -415,12 +415,6 @@ dependencies {
|
||||||
}
|
}
|
||||||
|
|
||||||
testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3'
|
testImplementation 'org.apache.maven:maven-ant-tasks:2.1.3'
|
||||||
debugImplementation Deps.fragment_testing, {
|
|
||||||
exclude group: 'androidx.test', module: 'core'
|
|
||||||
}
|
|
||||||
forPerformanceTestImplementation Deps.fragment_testing, {
|
|
||||||
exclude group: 'androidx.test', module: 'core'
|
|
||||||
}
|
|
||||||
// For production builds, the native code for all `org.mozilla.appservices`
|
// For production builds, the native code for all `org.mozilla.appservices`
|
||||||
// dependencies gets compiled together into a single "megazord" build, and
|
// dependencies gets compiled together into a single "megazord" build, and
|
||||||
// different megazords are published for different subsets of features. Ref
|
// different megazords are published for different subsets of features. Ref
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
package org.mozilla.fenix.components
|
package org.mozilla.fenix.components
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.testing.launchFragmentInContainer
|
import androidx.fragment.app.FragmentActivity
|
||||||
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
||||||
import mozilla.components.lib.state.Action
|
import mozilla.components.lib.state.Action
|
||||||
import mozilla.components.lib.state.State
|
import mozilla.components.lib.state.State
|
||||||
|
@ -16,6 +16,7 @@ import org.junit.Assert.assertTrue
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mozilla.fenix.TestApplication
|
import org.mozilla.fenix.TestApplication
|
||||||
|
import org.robolectric.Robolectric
|
||||||
import org.robolectric.RobolectricTestRunner
|
import org.robolectric.RobolectricTestRunner
|
||||||
import org.robolectric.annotation.Config
|
import org.robolectric.annotation.Config
|
||||||
|
|
||||||
|
@ -45,31 +46,49 @@ class StoreProviderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `get returns store`() {
|
fun `get returns store`() {
|
||||||
val scenario = launchFragmentInContainer { Fragment() }
|
val activity = Robolectric.buildActivity(FragmentActivity::class.java)
|
||||||
scenario.onFragment {
|
.create()
|
||||||
val store = StoreProvider.get(it) { basicStore }
|
.start()
|
||||||
assertEquals(basicStore, store)
|
.resume()
|
||||||
|
.get()
|
||||||
|
|
||||||
|
val fragment = Fragment()
|
||||||
|
|
||||||
|
activity.supportFragmentManager.beginTransaction().apply {
|
||||||
|
add(fragment, "test")
|
||||||
|
commitNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val store = StoreProvider.get(fragment) { basicStore }
|
||||||
|
assertEquals(basicStore, store)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `get only calls createStore if needed`() {
|
fun `get only calls createStore if needed`() {
|
||||||
val scenario = launchFragmentInContainer { Fragment() }
|
val activity = Robolectric.buildActivity(FragmentActivity::class.java)
|
||||||
|
.create()
|
||||||
|
.start()
|
||||||
|
.resume()
|
||||||
|
.get()
|
||||||
|
|
||||||
|
val fragment = Fragment()
|
||||||
|
|
||||||
|
activity.supportFragmentManager.beginTransaction().apply {
|
||||||
|
add(fragment, "test")
|
||||||
|
commitNow()
|
||||||
|
}
|
||||||
|
|
||||||
var createCalled = false
|
var createCalled = false
|
||||||
val createStore = {
|
val createStore = {
|
||||||
createCalled = true
|
createCalled = true
|
||||||
basicStore
|
basicStore
|
||||||
}
|
}
|
||||||
|
|
||||||
scenario.onFragment {
|
StoreProvider.get(fragment, createStore)
|
||||||
StoreProvider.get(it, createStore)
|
|
||||||
}
|
|
||||||
assertTrue(createCalled)
|
assertTrue(createCalled)
|
||||||
|
|
||||||
createCalled = false
|
createCalled = false
|
||||||
scenario.onFragment {
|
StoreProvider.get(fragment, createStore)
|
||||||
StoreProvider.get(it, createStore)
|
|
||||||
}
|
|
||||||
assertFalse(createCalled)
|
assertFalse(createCalled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,6 @@ object Deps {
|
||||||
const val tools_test_runner = "androidx.test:runner:${Versions.tools_test_runner}"
|
const val tools_test_runner = "androidx.test:runner:${Versions.tools_test_runner}"
|
||||||
const val uiautomator = "com.android.support.test.uiautomator:uiautomator-v18:${Versions.uiautomator}"
|
const val uiautomator = "com.android.support.test.uiautomator:uiautomator-v18:${Versions.uiautomator}"
|
||||||
const val robolectric = "org.robolectric:robolectric:${Versions.robolectric}"
|
const val robolectric = "org.robolectric:robolectric:${Versions.robolectric}"
|
||||||
const val fragment_testing = "androidx.fragment:fragment-testing:${Versions.androidx_fragment}"
|
|
||||||
const val androidx_junit = "androidx.test.ext:junit:${Versions.androidx_test_ext}"
|
const val androidx_junit = "androidx.test.ext:junit:${Versions.androidx_test_ext}"
|
||||||
const val androidx_test_core = "androidx.test:core:${Versions.androidx_testing}"
|
const val androidx_test_core = "androidx.test:core:${Versions.androidx_testing}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue