Skip to content

Unit tests for DataElementProcessor

Created by: dbluhm

This PR adds unit tests for the DataElementProcessor using the compile-testing library.

The compile-testing library works by invoking the Java compiler through javax.tools. It creates an in-memory file manager so generated and compiled files aren't written to disk. The facilities it provides to then make assertions about the generated files are done through parsing the generated files and comparing the ASTs. As a result, we can test that annotations cause failures when we expect it to and that it generates files matching (with a high level of granularity) what we would expect it to generate BUT, as it does not compile the final generated classes, we cannot test the logic of generated classes in this manner.

Most of the tests use the "golden file" test strategy with the minor modification that the golden files are actually patterns. ASTs are parsed from the golden files/patterns and compared with the ASTs of the files generated from the input. In other words, the pattern AST must be a subgraph of the generated AST. A nuance of this strategy is that if methods are included in the pattern, the entire body of the method in the pattern must match exactly (AST-wise) the entire body of the method in the generated AST. Knowing that this would result in potentially brittle test cases, the patterns do not verify presence of the methods directly in the generated Implementation AST. They are, however, verified in the generated Interface and any methods missing in the implementation that are present in the interface are caught during testing. So by verifying both the methods in the interface and the fields in the implementation, the presence of all fields and methods on the generated implementation is verified.

Merge request reports