Skip to main content Link Search Menu Expand Document (external link)

ErrorProneTestHelperSourceFormat

SUGGESTION

Style

View source code on GitHub

Summary

Test code should follow the Google Java style

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ErrorProneTestHelperSourceFormat") to the enclosing element.

Disable this pattern completely by adding -Xep:ErrorProneTestHelperSourceFormat:OFF as compiler argument. Learn more.

Samples

Replacement

Shows the difference in example code before and after the bug pattern is applied.

 import com.google.errorprone.BugCheckerRefactoringTestHelper;
 import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
 import com.google.errorprone.CompilationTestHelper;
 import tech.picnic.errorprone.bugpatterns.EmptyMethod;
 
 class A {
   private final CompilationTestHelper compilationTestHelper =
       CompilationTestHelper.newInstance(EmptyMethod.class, getClass());
   private final BugCheckerRefactoringTestHelper refactoringTestHelper =
       BugCheckerRefactoringTestHelper.newInstance(EmptyMethod.class, getClass());
 
   void m() {
     compilationTestHelper
         .addSourceLines(
             "A.java",
-            "import java.util.Map;",
-            "import java.util.Collection;",
             "import java.util.List;",
+            "import java.util.Map;",
             "",
-            "interface A extends List<A>, Map<A,A> { }")
+            "interface A extends List<A>, Map<A, A> {}")
         .doTest();
 
     refactoringTestHelper
         .addInputLines(
             "A.java",
-            "import java.util.Map;",
-            "import java.util.Collection;",
             "import java.util.List;",
+            "import java.util.Map;",
             "",
-            "interface A extends List<A>, Map<A,A> { }")
+            "interface A extends List<A>, Map<A, A> {}")
         .addOutputLines(
             "A.java",
-            "import java.util.Map;",
             "import java.util.Collection;",
             "import java.util.List;",
+            "import java.util.Map;",
             "",
-            "interface A extends List<A>, Map<A,A> { }")
+            "interface A extends List<A>, Map<A, A> {}")
         .doTest(TestMode.TEXT_MATCH);
   }
 }

Identification

Shows code lines which will (not) be flagged by this bug pattern.
A //BUG: Diagnostic contains: comment is placed above any violating line.

import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
import com.google.errorprone.CompilationTestHelper;
import tech.picnic.errorprone.bugpatterns.EmptyMethod;

class A {
  private final CompilationTestHelper compilationTestHelper =
      CompilationTestHelper.newInstance(EmptyMethod.class, getClass());
  private final BugCheckerRefactoringTestHelper refactoringTestHelper =
      BugCheckerRefactoringTestHelper.newInstance(EmptyMethod.class, getClass());

  void m() {
    compilationTestHelper
        // BUG: Diagnostic contains: No source code provided
        .addSourceLines("A.java")
        // BUG: Diagnostic contains: Source code is malformed:
        .addSourceLines("B.java", "class B {")
        // Well-formed code, so not flagged.
        .addSourceLines("C.java", "class C {}")
        // Malformed code, but not compile-time constant, so not flagged.
        .addSourceLines("D.java", "class D {" + getClass())
        // BUG: Diagnostic contains: Test code should follow the Google Java style
        .addSourceLines("E.java", "class E { }")
        .doTest();

    refactoringTestHelper
        // BUG: Diagnostic contains: Test code should follow the Google Java style
        .addInputLines("A.java", "class A { }")
        // BUG: Diagnostic contains: Test code should follow the Google Java style
        .addOutputLines("A.java", "class A { }")
        // BUG: Diagnostic contains: Test code should follow the Google Java style
        .addInputLines("B.java", "import java.util.Map;", "", "class B {}")
        // Unused import, but in an output file, so not flagged.
        .addOutputLines("B.java", "import java.util.Map;", "", "class B {}")
        .doTest(TestMode.TEXT_MATCH);
  }
}

Copyright © 2017-2023 Picnic Technologies BV