ucr-riple / NullAwayAnnotator

A tool to help adapting code bases to NullAway type system.
MIT License
13 stars 6 forks source link

Redesign test architecture for annotator-core module. #159

Closed nimakarimipour closed 1 year ago

nimakarimipour commented 1 year ago

This PR redesigns annotator-core module test architecture which simplifies adding a new test. This PR enables us to construct modular gradle projects programmatically while writing a new test. Please see an example below:

@Test
  public void test() {
    coreTestHelper
        .onTarget()
        .withSourceFile("Foo.java", "bar/Foo.java")
        .withDependency("DepA")
        .withSourceFile("DepA.java", "bar/DepA.java")
        .withDependency("DepB")
        .withSourceFile("DepB.java", "bar/DepB.java")
        .withSourceFile("DepBB.java", "bar/DepBB.java")
        .withDependency("DepC")
        .withSourceFile("DepC.java", "bar/DepC.java")
        .withExpectedReports(...)
        .toDepth(5)
        .start();
  }

In the tests above, the project is constructed as a target module with source file Foo.java and dependency with module name DepA and source file DepA.java and so on. Please note, in addition to withSourceFile() we can use combinations of methods below as well to construct a gradle project:

  1. withSourceFile(String path, String inputFilePath)
  2. withSourceDirectory(String path, String inputDirectoryPath)
  3. withSourceLines(String path, String... lines)

The new design significantly decreases rigidness of existing project templates and makes designing unit tests much easier.