From f94e1eb3c1aa711f376d7a05023b0b4571bbc8d7 Mon Sep 17 00:00:00 2001 From: Motorro Date: Thu, 30 May 2024 12:38:08 +0200 Subject: [PATCH] Test fixes --- .../motorro/rxlcemodel/view/LceStateView.kt | 7 +++++-- .../rxlcemodel/view/LceStateViewTest.kt | 20 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/viewmodel/src/main/kotlin/com/motorro/rxlcemodel/view/LceStateView.kt b/viewmodel/src/main/kotlin/com/motorro/rxlcemodel/view/LceStateView.kt index 7dd2401c..dfe530d9 100644 --- a/viewmodel/src/main/kotlin/com/motorro/rxlcemodel/view/LceStateView.kt +++ b/viewmodel/src/main/kotlin/com/motorro/rxlcemodel/view/LceStateView.kt @@ -4,9 +4,12 @@ import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelStoreOwner import com.motorro.rxlcemodel.lce.LceState -import com.motorro.rxlcemodel.lce.LceState.* +import com.motorro.rxlcemodel.lce.LceState.Content +import com.motorro.rxlcemodel.lce.LceState.Error +import com.motorro.rxlcemodel.lce.LceState.Loading import com.motorro.rxlcemodel.lce.LceState.Loading.Type.LOADING import com.motorro.rxlcemodel.lce.LceState.Loading.Type.UPDATING +import com.motorro.rxlcemodel.lce.LceState.Terminated import com.motorro.rxlcemodel.viewmodel.BaseLceModel /** @@ -116,7 +119,7 @@ inline fun > LceStateView modelStoreOwner: ViewModelStoreOwner, init: MODEL.() -> Unit = { initialize() } ): MODEL { - val model = ViewModelProvider(modelStoreOwner).get(MODEL::class.java) + val model = ViewModelProvider(modelStoreOwner)[MODEL::class.java] model.state.observe(getLifecycleOwner()) { processState(it) } model.init() return model diff --git a/viewmodel/src/test/kotlin/com/motorro/rxlcemodel/view/LceStateViewTest.kt b/viewmodel/src/test/kotlin/com/motorro/rxlcemodel/view/LceStateViewTest.kt index f486e08d..4c4328b2 100644 --- a/viewmodel/src/test/kotlin/com/motorro/rxlcemodel/view/LceStateViewTest.kt +++ b/viewmodel/src/test/kotlin/com/motorro/rxlcemodel/view/LceStateViewTest.kt @@ -13,13 +13,27 @@ package com.motorro.rxlcemodel.view -import androidx.lifecycle.* +import androidx.lifecycle.HasDefaultViewModelProviderFactory +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.LiveData +import androidx.lifecycle.Observer +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.ViewModelStore +import androidx.lifecycle.ViewModelStoreOwner import androidx.lifecycle.viewmodel.CreationExtras import com.motorro.rxlcemodel.lce.LceState import com.motorro.rxlcemodel.viewmodel.BaseLceModel -import com.nhaarman.mockitokotlin2.* +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.argThat +import com.nhaarman.mockitokotlin2.argumentCaptor +import com.nhaarman.mockitokotlin2.doReturn +import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.never +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.whenever import org.junit.Before import org.junit.Test +import kotlin.reflect.KClass import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -133,7 +147,7 @@ class LceStateViewTest { on { state } doReturn liveData } val factory: ViewModelProvider.Factory = mock { - onGeneric { create>(any(), any()) } doReturn model + onGeneric { create(any>>(), any()) } doReturn model } val lceView: LceStateView = mock { on { getLifecycleOwner() } doReturn lifecycleOwner