How to test Java 9+ doclet without mocking Doclet API?

196 Views Asked by At

I have written a Doclet using Java 9+. I would like to test it using JUnit framework without mocking the Doclet API. Any good way of proceeding?

1

There are 1 best solutions below

0
Abbadon On BEST ANSWER

The answer is simple when you know what to use. Here is an example of manual invocation which can be use in a JUnit test.

DocumentationTool systemDocumentationTool = ToolProvider.getSystemDocumentationTool();
        String[] args = new String[] {
          "-sourcepath",
          "./src/test/java",
          "-subpackages",
          "<whatever-package-in-test-sources>",
          "<whatever-package-in-test-sources>",
          "-d",
          "whatever not used just to show compatibility",
          "-author",
          "whatever not used just to show compatibility",
          "-doctitle",
          "whatever not used just to show compatibility",
          "-windowtitle",
          "whatever not used just to show compatibility",
          "-classdir",
          BUILD_PROPERTY_FILE_LOCATION
        };
        DocumentationTool.DocumentationTask task = systemDocumentationTool.getTask(null, null, null,
          <MyDocletClass>.class, Arrays.asList(args), null);

        task.call();
        // Your checks after invocation