2014-05-14 20 views
0

我有ff。测试方法:如何解决“类的表达式需要未经检查的转换符合类<Object>”

@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。

+3

'@SuppressWarnings(“unchecked”)'? – DnR

+0

谢谢。刚从这里找到答案:http://stackoverflow.com/questions/12012249/mockito-isaclasst-clazz-how-to-resolve-type-safety – Jonathan

回答

0

正如ff。 post,它可以通过@SuppressWarnings("unchecked")删除。

相关问题