我有以下方法
public ResultScanner getScanner(Scan scan) {
Table table = getTableInstance("Sampletable");
return table.getScanner(scan);
}
为此我写了以下junit测试代码
Connection mockconnection = PowerMockito.mock(Connection.class);
Table mocktable = PowerMockito.mock(Table.class);
PowerMockito.when(mockconnection.getTable(TableName.valueOf(Mockito.anyString())))
.thenReturn(mocktable);
Scan mockedScan = PowerMockito.mock(Scan.class);
ResultScanner mockrs = PowerMockito.mock(ResultScanner.class);
PowerMockito.when(mocktable.getScanner(mockedScan)).thenReturn(mockrs);
测试方法时
声明
Table table = getTableInstance("Sampletable");
运行正常,并提供模拟的表对象,但语句
table.getScanner(scan);
返回null。
请在以下链接中找到Table界面的源代码
请指导我吗?
答案 0 :(得分:1)
用
替换测试用例的最后一行 PowerMockito.when(mocktable.getScanner(Mockito.any(Scan.class))).thenReturn(mockrs);
应该有效