Skip to content

Commit

Permalink
Add more assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarr21 committed Aug 7, 2023
1 parent 53c718b commit 72b5415
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.findViewTreeViewModelStoreOwner
import androidx.savedstate.findViewTreeSavedStateRegistryOwner
import com.google.common.truth.Truth.assertThat
import com.uber.autodispose.AutoDispose
import com.uber.autodispose.lifecycle.LifecycleEndedException
Expand Down Expand Up @@ -191,14 +193,23 @@ class RibActivityTest {
}

@Test
fun onCreate_setsViewTreeOwners() {
fun onCreate_setsViewTreeOwners_forDecorView() {
val activity = Robolectric.buildActivity(EmptyActivity::class.java).create(null).get()
assertThat(activity.window.decorView.findViewTreeLifecycleOwner()).isNotNull()
val decorView = activity.window.decorView
assertThat(decorView.findViewTreeLifecycleOwner()).isNotNull()
assertThat(decorView.findViewTreeSavedStateRegistryOwner()).isNotNull()
assertThat(decorView.findViewTreeViewModelStoreOwner()).isNotNull()
}

@Test
fun onCreate_setsViewTreeOwners_forViewAddedToDecorView() {
val activity = Robolectric.buildActivity(EmptyActivity::class.java).create(null).get()
val contentView = activity.findViewById<FrameLayout>(android.R.id.content)
val rootView = View(RuntimeEnvironment.application)
contentView.addView(rootView)
assertThat(rootView.findViewTreeLifecycleOwner()).isNotNull()
assertThat(rootView.findViewTreeSavedStateRegistryOwner()).isNotNull()
assertThat(rootView.findViewTreeViewModelStoreOwner()).isNotNull()
}

@Test(expected = IllegalArgumentException::class)
Expand Down

0 comments on commit 72b5415

Please sign in to comment.