Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiveData Arraylist casting error #9064

Open
abhijeetraahi opened this issue May 8, 2024 · 0 comments
Open

LiveData Arraylist casting error #9064

abhijeetraahi opened this issue May 8, 2024 · 0 comments

Comments

@abhijeetraahi
Copy link

abhijeetraahi commented May 8, 2024

Getting these error while trying to mock the LiveData object below code is in my class
ViewModelClass -
private val _departmentDropDownList = MutableLiveData<List?>()
val departmentDropDownList: LiveData<List?> = _departmentDropDownList
TestClass -
mockViewModel = declareMock {
when(this.showProgressBar).thenReturn(MutableLiveData(false))
when(this.departmentDropDownList).thenReturn(MutableLiveData(null))
when(this.selectedCompareType).thenReturn("")
val itemList = context.resources.getStringArray(R.array.comparison_type)
when(this.getComparisonDropDownList(itemList)).thenReturn(getItemList(itemList))
}

Error which i am getting -
class java.util.ArrayList cannot be cast to class androidx.lifecycle.LiveData (java.util.ArrayList is in module java.base of loader 'bootstrap'; androidx.lifecycle.LiveData is in unnamed module of loader org.robolectric.internal.AndroidSandbox$SdkSandboxClassLoader @4da9f723)
java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class androidx.lifecycle.LiveData (java.util.ArrayList is in module java.base of loader 'bootstrap'; androidx.lifecycle.LiveData is in unnamed module of loader org.robolectric.internal.AndroidSandbox$SdkSandboxClassLoader @4da9f723)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant