Kotlin和Mockito'检测到错误或错误使用的参数匹配器'

时间:2018-08-07 06:36:20

标签: kotlin mocking mockito

我正在尝试通过在本地集合中存储和提取传递的项目来模拟存储库对象。我声明了类范围参数:

data = data.loc[:, data.min().sort_values().index]

然后我尝试像这样模拟存储库:

import seaborn as sns
import pandas as pd

data = [[5,1,9],
        [7,8,6],
        [5,3,2]]


data = pd.DataFrame(data)
#sns.heatmap(data)


data = data.loc[:, data.min().sort_values().index]
#sns.heatmap(data) # Gives result in step 1
# Step1, Columsn sorted by min value, 1, 2, 5
data = [[1,9,5],
        [8,6,7],
        [3,2,5]]

data = pd.DataFrame(data)
#sns.heatmap(data)
# How do i perform step two, maintinaing column order.
# Step 2, Rows sorted by min value 1,2,7
data = [[1,9,5],
        [3,2,5],
        [8,6,7]]

data = pd.DataFrame(data)
sns.heatmap(data)

插入并获取所有项目的部件工作得很好,但是当我添加更新部件时,我开始出现如下错误:

@RunWith(MockitoJUnitRunner::class)
class ChangeItemCheckStateUseCaseTest : UseCaseTest<ChangeItemCheckStateUseCase>() {

@Mock
private lateinit var listItemsRepository: ListItemRepository

private lateinit var repositoryItems: MutableList<ListItem>

private fun mockItemsRepository() {
    repositoryItems = mutableListOf()

    `when`(listItemsRepository.insert(Mockito.anyList())).thenAnswer {
        @Suppress("UNCHECKED_CAST")
        repositoryItems.addAll(it.arguments[0] as? List<ListItem> ?: listOf())
    }

    `when`(listItemsRepository.getAllListItems()).thenReturn(
            MutableLiveData<List<ListItem>>().also { it.value = repositoryItems }
    )

    `when`(listItemsRepository.updateItemCheckState(ArgumentMatchers.any(ListItem::class.java))).then {invocation -> 
        val argument = invocation.arguments[0] as ListItem
        val index = repositoryItems.indexOf(repositoryItems.find { it.localId == argument.localId })
        repositoryItems[index] = argument
        Unit
    }
}

java.lang.IllegalStateException: ArgumentMatchers.any(ListItem::class.java) must not be null

0 个答案:

没有答案