Google的compile-testing是单元测试注释处理器的绝佳工具。不幸的是,我目前面临以下错误:
java.lang.AssertionError:
An expected source declared one or more top-level types that were not present.
Expected top-level types: <[test.LocalStorage]>
Declared by expected file: <LocalStorageImpl.java>
The top-level types that were present are as follows:
- [test.LocalStorageImpl] in </SOURCE_OUTPUT/test/LocalStorageImpl.java>
我的处理器生成带注释的界面的实现。因此生成的代码依赖于接口(class LocalStorageImpl implements LocalStorage
)。
当我尝试使用
验证生成的代码时 JavaFileObject source = /* interface definition */
JavaFileObject expected_source = /* the generated implementation */
assertAbout(javaSource()).that(source)
.processedWith(new MyProcessor())
.compilesWithoutError()
.and()
.generatesSources(expectedSource);
... generatesSource
导致错误。正如错误消息所述,它无法解析接口定义。
所以我的问题是如何编译或编写source
中定义的接口的源文件,以便generatesSources()
识别它?