Commit cada90b5 authored by Sebastian Kaspari's avatar Sebastian Kaspari Committed by Christian Sadilek
Browse files

Closes #3278: Call unregisterObserver from unregisterObservers to guarantee same implementation.

parent e9f6dd60
......@@ -96,14 +96,10 @@ class ObserverRegistry<T> : Observable<T> {
@Synchronized
override fun unregisterObservers() {
observers.forEach {
lifecycleObservers[it]?.remove()
observers.toList().forEach { observer ->
unregister(observer)
}
observers.clear()
pausedObservers.clear()
lifecycleObservers.clear()
viewObservers.clear()
}
@Synchronized
......
......@@ -10,6 +10,8 @@ import android.view.WindowManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import mozilla.components.support.test.any
import mozilla.components.support.test.mock
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
......@@ -354,6 +356,21 @@ class ObserverRegistryTest {
assertFalse(observer.notified)
}
@Test
fun `unregisterObservers will unregister from view`() {
val view: View = mock()
doReturn(true).`when`(view).isAttachedToWindow
val registry = ObserverRegistry<TestObserver>()
val observer = TestObserver()
registry.register(observer, view)
verify(view).addOnAttachStateChangeListener(any())
registry.unregisterObservers()
verify(view).removeOnAttachStateChangeListener(any())
}
@Test
fun `wrapConsumers will return list of lambdas calling observers`() {
val observer1 = TestConsumingObserver(shouldConsume = false)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment