如何解决&#34;类型Class的表达式需要未经检查的转换以符合Class <object>&#34; </object>

时间:2014-05-14 00:57:52

标签: java junit mockito powermock data-access

我有ff。测试方法:

@Mock
private DBAccessor accessor;

/**
 * Successful find().
 */
@Test
public void testFind() {
    // Prepare
    MockDto mockDto = mock(MockDto.class);
    try {
        when(accessor.executeQuery(any(Class.class), anyString(), any(ConcurrentHashMap.class))).thenReturn(
                mockDto);
    } catch (Exception e) {
        fail("Unexpected exception.");
    }
}

然而,ff。警告发生:

Multiple markers at this line
    - Type safety: Unchecked invocation executeQuery(Class, String, ConcurrentHashMap) of the generic method executeQuery(Class<T>, String, Object) of type DBAccessor
    - Type safety: The expression of type Class needs unchecked conversion to conform to Class<Object>

如何解决上述警告?

我使用Mockit和Powermock作为模拟框架和JUnit。

1 个答案:

答案 0 :(得分:0)

如ff所示。 post,可以@SuppressWarnings("unchecked")删除它。