java - Mockito:模拟 AnnotationType

标签 java junit mockito

我想模拟返回 Class<? extends Annotation> 的方法 annotationType() .

但是下一行给我一个编译错误。

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

我正在使用 java 1.7.0_45。我收到需要通过 Class<? extends Annotation> 的编译错误作为参数。

知道我应该把什么作为 thenReturn 的参数吗?为了编译?

最佳答案

annotation.annotationType()返回 Class<? extends Annotation> .

所以你必须返回一些注解类型的类对象

关于java - Mockito:模拟 AnnotationType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31317575/

相关文章:

java - 在 Spring 中列出方面代理的 Bean

java - Spring JcbcTemplate 调用 Oracle Stored Proc。 Spring 3.2

google-app-engine - 测试命名空间

unit-testing - Grails单元测试不起作用-NoClassDefFoundError:junit/framework/TestCase

java - 如何测试使用数据库登录的Servlet?

java - 是否可以出于测试目的更改 Java 中 final 字段的值?

java - Mockito + TestNG + String - 测试在没有 Autowiring 的情况下无法工作

java - 错误 :NullPointerException for java project, 如何解决?

java - 在透明 SurfaceView 上绘制

java - 斯卡拉/Mockito : How to mock the result of a method called inside another method?