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()));
}
Aggregations