java – Mockito:Mocking AnnotationType

我想模拟annotationType()方法,它返回Class<?扩展注释>.

但是以下行给出了编译错误.

when(annotation.annotationType()).thenReturn(notNullClass.getClass());

我使用的是java 1.7.0_45.我收到编译错误,我需要传递Class<?扩展注释>作为参数.

任何想法我应该把thenReturn作为参数进行编译?

最佳答案 annotation.annotationType()返回Class<?扩展注释>.

所以你必须返回一些注释类型的Class对象.

点赞