Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
motorro committed May 30, 2024
1 parent 0666f2c commit f94e1eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -116,7 +119,7 @@ inline fun <reified DATA : Any, reified MODEL : BaseLceModel<DATA>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -133,7 +147,7 @@ class LceStateViewTest {
on { state } doReturn liveData
}
val factory: ViewModelProvider.Factory = mock {
onGeneric { create<BaseLceModel<Int>>(any(), any()) } doReturn model
onGeneric { create(any<KClass<BaseLceModel<Int>>>(), any()) } doReturn model
}
val lceView: LceStateView<Int> = mock {
on { getLifecycleOwner() } doReturn lifecycleOwner
Expand Down

0 comments on commit f94e1eb

Please sign in to comment.