Search in sources :

Example 1 with ChainingConstructorIgnoresParameter

use of com.google.errorprone.bugpatterns.ChainingConstructorIgnoresParameter in project error-prone by google.

the class ErrorProneJavaCompilerTest method testSeverityResetsAfterOverride.

@Test
public void testSeverityResetsAfterOverride() throws Exception {
    DiagnosticTestHelper diagnosticHelper = new DiagnosticTestHelper();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(outputStream, UTF_8), true);
    ErrorProneInMemoryFileManager fileManager = new ErrorProneInMemoryFileManager();
    JavaCompiler errorProneJavaCompiler = new ErrorProneJavaCompiler();
    List<String> args = Lists.newArrayList("-d", tempDir.getRoot().getAbsolutePath(), "-proc:none", "-Xep:ChainingConstructorIgnoresParameter:WARN");
    List<JavaFileObject> sources = fileManager.forResources(ChainingConstructorIgnoresParameter.class, "testdata/ChainingConstructorIgnoresParameterPositiveCases.java");
    fileManager.close();
    JavaCompiler.CompilationTask task = errorProneJavaCompiler.getTask(printWriter, fileManager, diagnosticHelper.collector, args, null, sources);
    boolean succeeded = task.call();
    assertThat(succeeded).isTrue();
    Matcher<? super Iterable<Diagnostic<? extends JavaFileObject>>> matcher = hasItem(diagnosticMessage(containsString("[ChainingConstructorIgnoresParameter]")));
    assertTrue(matcher.matches(diagnosticHelper.getDiagnostics()));
    // reset state between compilations
    diagnosticHelper.clearDiagnostics();
    fileManager = new ErrorProneInMemoryFileManager();
    sources = fileManager.forResources(ChainingConstructorIgnoresParameter.class, "testdata/ChainingConstructorIgnoresParameterPositiveCases.java");
    fileManager.close();
    args.remove("-Xep:ChainingConstructorIgnoresParameter:WARN");
    task = errorProneJavaCompiler.getTask(printWriter, fileManager, diagnosticHelper.collector, args, null, sources);
    succeeded = task.call();
    assertThat(succeeded).isFalse();
    assertTrue(matcher.matches(diagnosticHelper.getDiagnostics()));
}
Also used : JavaCompiler(javax.tools.JavaCompiler) Diagnostic(javax.tools.Diagnostic) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) JavaFileObject(javax.tools.JavaFileObject) ChainingConstructorIgnoresParameter(com.google.errorprone.bugpatterns.ChainingConstructorIgnoresParameter) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

ChainingConstructorIgnoresParameter (com.google.errorprone.bugpatterns.ChainingConstructorIgnoresParameter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 Diagnostic (javax.tools.Diagnostic)1 JavaCompiler (javax.tools.JavaCompiler)1 JavaFileObject (javax.tools.JavaFileObject)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1