Class DiagnosticTestHelper


public class DiagnosticTestHelper
extends Object
Utility class for tests which need to assert on the diagnostics produced during compilation.
Author: (Alex Eagle)
  • Field Details

    • collector

      public final<JavaFileObject> collector
  • Constructor Details

    • DiagnosticTestHelper

      public DiagnosticTestHelper()
      Construct a DiagnosticTestHelper not associated with a specific check.
    • DiagnosticTestHelper

      public DiagnosticTestHelper​(String checkName)
      Construct a DiagnosticTestHelper for a check with the given name.
  • Method Details

    • suggestsRemovalOfLine

      public static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> suggestsRemovalOfLine​(URI fileURI, int line)
    • getDiagnostics

      public List<Diagnostic<? extends JavaFileObject>> getDiagnostics()
    • clearDiagnostics

      public void clearDiagnostics()
    • describe

      public String describe()
    • diagnosticLineAndColumn

      public static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> diagnosticLineAndColumn​(long line, long column)
    • diagnosticOnLine

      public static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> diagnosticOnLine​(URI fileURI, long line)
    • diagnosticOnLine

      public static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> diagnosticOnLine​(URI fileURI, long line,<? super String> matcher)
    • diagnosticMessage

      public static org.hamcrest.Matcher<Diagnostic<? extends JavaFileObject>> diagnosticMessage​(org.hamcrest.Matcher<String> matcher)
    • expectErrorMessage

      public void expectErrorMessage​(String key,<? super String> matcher)
      Expects an error message matching matcher at the line below a comment matching the key. For example, given the source
         // BUG: Diagnostic matches: X
         a = b + c;
      ... you can use expectErrorMessage("X", Predicates.containsPattern("Can't add b to c"));

      Error message keys that don't match any diagnostics will cause test to fail.

    • assertHasDiagnosticOnAllMatchingLines

      public void assertHasDiagnosticOnAllMatchingLines​(JavaFileObject source, lookForCheckNameInDiagnostic) throws IOException
      Asserts that the diagnostics contain a diagnostic on each line of the source file that matches our bug marker pattern. Parses the bug marker pattern for the specific string to look for in the diagnostic.
      source - File in which to find matching lines
    • getUnusedLookupKeys

      public Set<String> getUnusedLookupKeys()
      Returns the lookup keys that weren't used.