summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Steve Elliott <steell@google.com> 2019-10-30 15:23:12 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-10-30 15:23:12 +0000
commitfc34dee468f55f701ea1bc2d3a461abd4c3062d0 (patch)
tree2b243f1ee0e4bdd21eaf4a3109f3cef251a653ae
parent45216b4fdf3a6a2b93913ddd2a95f37ac1f8c293 (diff)
parent3f549e3cf4a2c71f46fb8e371dc69614f09456bd (diff)
Merge "Mark test with @Test + comments"
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/people/PeopleHubViewControllerTest.kt13
1 files changed, 7 insertions, 6 deletions
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/people/PeopleHubViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/people/PeopleHubViewControllerTest.kt
index a1822c72fe18..f5d6f223b86c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/people/PeopleHubViewControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/people/PeopleHubViewControllerTest.kt
@@ -50,19 +50,14 @@ class PeopleHubViewControllerTest : SysuiTestCase() {
fun testBindViewModelToViewBoundary() {
val fakePerson1 = fakePersonViewModel("name")
val fakeViewModel = PeopleHubViewModel(sequenceOf(fakePerson1), true)
-
val fakePersonViewAdapter1 = FakeDataListener<PersonViewModel?>()
val fakePersonViewAdapter2 = FakeDataListener<PersonViewModel?>()
-
val mockClickView = mock(View::class.java)
-
`when`(mockViewBoundary.associatedViewForClickAnimation).thenReturn(mockClickView)
`when`(mockViewBoundary.personViewAdapters)
.thenReturn(sequenceOf(fakePersonViewAdapter1, fakePersonViewAdapter2))
-
val mockFactory = mock(PeopleHubViewModelFactory::class.java)
`when`(mockFactory.createWithAssociatedClickView(any())).thenReturn(fakeViewModel)
-
val mockSubscription = mock(Subscription::class.java)
val fakeFactoryDataSource = object : DataSource<PeopleHubViewModelFactory> {
override fun registerListener(
@@ -82,6 +77,7 @@ class PeopleHubViewControllerTest : SysuiTestCase() {
verify(mockFactory).createWithAssociatedClickView(mockClickView)
}
+ @Test
fun testViewModelDataSourceTransformsModel() {
val fakeClickIntent = PendingIntent.getActivity(context, 0, Intent("action"), 0)
val fakePerson = fakePersonModel("id", "name", fakeClickIntent)
@@ -99,16 +95,17 @@ class PeopleHubViewControllerTest : SysuiTestCase() {
val mockClickView = mock(View::class.java)
factoryDataSource.registerListener(fakeListener)
+
val viewModel = (fakeListener.lastSeen as Maybe.Just).value
.createWithAssociatedClickView(mockClickView)
assertThat(viewModel.isVisible).isTrue()
-
val people = viewModel.people.toList()
assertThat(people.size).isEqualTo(1)
assertThat(people[0].name).isEqualTo("name")
assertThat(people[0].icon).isSameAs(fakePerson.avatar)
people[0].onClick()
+
verify(mockActivityStarter).startPendingIntentDismissingKeyguard(
same(fakeClickIntent),
any(),
@@ -117,16 +114,20 @@ class PeopleHubViewControllerTest : SysuiTestCase() {
}
}
+/** Works around Mockito matchers returning `null` and breaking non-nullable Kotlin code. */
private inline fun <reified T : Any> any(): T {
return Mockito.any() ?: createInstance(T::class)
}
+/** Works around Mockito matchers returning `null` and breaking non-nullable Kotlin code. */
private inline fun <reified T : Any> same(value: T): T {
return Mockito.same(value) ?: createInstance(T::class)
}
+/** Creates an instance of the given class. */
private fun <T : Any> createInstance(clazz: KClass<T>): T = castNull()
+/** Tricks the Kotlin compiler into assigning `null` to a non-nullable variable. */
@Suppress("UNCHECKED_CAST")
private fun <T> castNull(): T = null as T