Skip to content

Commit

Permalink
Make error-prone compatible with hamcrest 1.3
Browse files Browse the repository at this point in the history
RELNOTES: N/A
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=87060296
  • Loading branch information
cushon committed Feb 25, 2015
1 parent 4b4f41e commit c3c8cb9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions core/pom.xml
Expand Up @@ -109,19 +109,19 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit-dep</artifactId> <artifactId>junit-dep</artifactId>
<version>4.10</version> <version>4.11</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hamcrest</groupId> <groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId> <artifactId>hamcrest-core</artifactId>
<version>1.1</version> <version>1.3</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hamcrest</groupId> <groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId> <artifactId>hamcrest-library</artifactId>
<version>1.1</version> <version>1.3</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
Expand Down
Expand Up @@ -212,7 +212,7 @@ public void assertHasDiagnosticOnAllMatchingLines(JavaFileObject source)
List<String> patterns = extractPatterns(line, reader); List<String> patterns = extractPatterns(line, reader);
int lineNumber = reader.getLineNumber(); int lineNumber = reader.getLineNumber();
for (String pattern : patterns) { for (String pattern : patterns) {
Matcher<Iterable<Diagnostic<JavaFileObject>>> patternMatcher = Matcher<? super Iterable<Diagnostic<JavaFileObject>>> patternMatcher =
hasItem(diagnosticOnLine(source.toUri(), lineNumber, pattern)); hasItem(diagnosticOnLine(source.toUri(), lineNumber, pattern));
assertTrue( assertTrue(
"Did not see an error on line " + lineNumber + " containing " + pattern "Did not see an error on line " + lineNumber + " containing " + pattern
Expand All @@ -222,7 +222,7 @@ public void assertHasDiagnosticOnAllMatchingLines(JavaFileObject source)


if (checkName != null) { if (checkName != null) {
// Diagnostic must contain check name. // Diagnostic must contain check name.
Matcher<Iterable<Diagnostic<JavaFileObject>>> checkNameMatcher = hasItem( Matcher<? super Iterable<Diagnostic<JavaFileObject>>> checkNameMatcher = hasItem(
diagnosticOnLine(source.toUri(), lineNumber, "[" + checkName + "]")); diagnosticOnLine(source.toUri(), lineNumber, "[" + checkName + "]"));
assertTrue( assertTrue(
"Did not see an error on line " + lineNumber + " containing [" + checkName "Did not see an error on line " + lineNumber + " containing [" + checkName
Expand All @@ -232,7 +232,7 @@ public void assertHasDiagnosticOnAllMatchingLines(JavaFileObject source)


} else { } else {
int lineNumber = reader.getLineNumber() + 1; int lineNumber = reader.getLineNumber() + 1;
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher =
not(hasItem(diagnosticOnLine(source.toUri(), lineNumber))); not(hasItem(diagnosticOnLine(source.toUri(), lineNumber)));
if (!matcher.matches(diagnostics)) { if (!matcher.matches(diagnostics)) {
fail("Saw unexpected error on line " + lineNumber + ". All errors:\n" + diagnostics); fail("Saw unexpected error on line " + lineNumber + ". All errors:\n" + diagnostics);
Expand Down
Expand Up @@ -104,7 +104,7 @@ public void fileWithError() throws Exception {
"bugpatterns/BadShiftAmountPositiveCases.java")); "bugpatterns/BadShiftAmountPositiveCases.java"));
assertThat(outputStream.toString(), exitCode, is(Result.ERROR)); assertThat(outputStream.toString(), exitCode, is(Result.ERROR));


Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem( Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem(
diagnosticMessage(containsString("[BadShiftAmount]"))); diagnosticMessage(containsString("[BadShiftAmount]")));
assertTrue("Error should be found. " + diagnosticHelper.describe(), assertTrue("Error should be found. " + diagnosticHelper.describe(),
matcher.matches(diagnosticHelper.getDiagnostics())); matcher.matches(diagnosticHelper.getDiagnostics()));
Expand All @@ -118,7 +118,7 @@ public void fileWithWarning() throws Exception {
"bugpatterns/NonAtomicVolatileUpdatePositiveCases.java")); "bugpatterns/NonAtomicVolatileUpdatePositiveCases.java"));
assertThat(outputStream.toString(), exitCode, is(Result.OK)); assertThat(outputStream.toString(), exitCode, is(Result.OK));


Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem( Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem(
diagnosticMessage(containsString("[NonAtomicVolatileUpdate]"))); diagnosticMessage(containsString("[NonAtomicVolatileUpdate]")));
assertTrue("Warning should be found. " + diagnosticHelper.describe(), assertTrue("Warning should be found. " + diagnosticHelper.describe(),
matcher.matches(diagnosticHelper.getDiagnostics())); matcher.matches(diagnosticHelper.getDiagnostics()));
Expand Down Expand Up @@ -150,7 +150,7 @@ public void fileWithMultipleTopLevelClassesExtendsWithError()
compiler.fileManager().sources(getClass(), "MultipleTopLevelClassesWithErrors.java", compiler.fileManager().sources(getClass(), "MultipleTopLevelClassesWithErrors.java",
"ExtendedMultipleTopLevelClassesWithErrors.java")); "ExtendedMultipleTopLevelClassesWithErrors.java"));
assertThat(outputStream.toString(), exitCode, is(Result.ERROR)); assertThat(outputStream.toString(), exitCode, is(Result.ERROR));
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem( Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem(
diagnosticMessage(containsString("[SelfAssignment]"))); diagnosticMessage(containsString("[SelfAssignment]")));
assertTrue("Warning should be found. " + diagnosticHelper.describe(), assertTrue("Warning should be found. " + diagnosticHelper.describe(),
matcher.matches(diagnosticHelper.getDiagnostics())); matcher.matches(diagnosticHelper.getDiagnostics()));
Expand All @@ -174,7 +174,7 @@ public Description matchExpressionStatement(ExpressionStatementTree tree, Visito
compiler.fileManager().sources(getClass(), "MultipleTopLevelClassesWithErrors.java", compiler.fileManager().sources(getClass(), "MultipleTopLevelClassesWithErrors.java",
"ExtendedMultipleTopLevelClassesWithErrors.java")); "ExtendedMultipleTopLevelClassesWithErrors.java"));
assertThat(outputStream.toString(), exitCode, is(Result.ERROR)); assertThat(outputStream.toString(), exitCode, is(Result.ERROR));
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem( Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem(
diagnosticMessage(CoreMatchers.<String>allOf( diagnosticMessage(CoreMatchers.<String>allOf(
containsString("IllegalStateException: test123"), containsString("IllegalStateException: test123"),
containsString("unhandled exception was thrown by the Error Prone")))); containsString("unhandled exception was thrown by the Error Prone"))));
Expand Down Expand Up @@ -263,7 +263,7 @@ public void ignoreGeneratedConstructors() throws Exception {
Result exitCode = compiler.compile( Result exitCode = compiler.compile(
Arrays.asList(compiler.fileManager().forSourceLines("Test.java", "public class Test {}"))); Arrays.asList(compiler.fileManager().forSourceLines("Test.java", "public class Test {}")));


Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = not(hasItem( Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher = not(hasItem(
diagnosticMessage(containsString("[ConstructorMatcher]")))); diagnosticMessage(containsString("[ConstructorMatcher]"))));
assertTrue( assertTrue(
"Warning should be found. " + diagnosticHelper.describe(), "Warning should be found. " + diagnosticHelper.describe(),
Expand Down Expand Up @@ -304,7 +304,7 @@ public void ignoreGeneratedSuperInvocations() throws Exception {
" public Test() {}", " public Test() {}",
"}"))); "}")));


Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = not(hasItem( Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher = not(hasItem(
diagnosticMessage(containsString("[SuperCallMatcher]")))); diagnosticMessage(containsString("[SuperCallMatcher]"))));
assertTrue( assertTrue(
"Warning should be found. " + diagnosticHelper.describe(), "Warning should be found. " + diagnosticHelper.describe(),
Expand Down Expand Up @@ -345,7 +345,7 @@ public void flagEnablesCheck() throws Exception {
Arrays.asList(compiler.fileManager().forSourceLines("Test.java", testFile))); Arrays.asList(compiler.fileManager().forSourceLines("Test.java", testFile)));
outputStream.flush(); outputStream.flush();


Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem( Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem(
diagnosticMessage(containsString("[EmptyIf]"))); diagnosticMessage(containsString("[EmptyIf]")));
assertTrue( assertTrue(
"Error should be found. " + diagnosticHelper.describe(), "Error should be found. " + diagnosticHelper.describe(),
Expand All @@ -364,7 +364,7 @@ public void severityIsResetOnNextCompilation() throws Exception {
Result exitCode = compiler.compile(args, Result exitCode = compiler.compile(args,
Arrays.asList(compiler.fileManager().forSourceLines("Test.java", testFile))); Arrays.asList(compiler.fileManager().forSourceLines("Test.java", testFile)));
outputStream.flush(); outputStream.flush();
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem( Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem(
diagnosticMessage(containsString("[LongLiteralLowerCaseSuffix]"))); diagnosticMessage(containsString("[LongLiteralLowerCaseSuffix]")));
assertThat(outputStream.toString(), exitCode, is(Result.OK)); assertThat(outputStream.toString(), exitCode, is(Result.OK));
assertTrue( assertTrue(
Expand All @@ -390,7 +390,7 @@ public void maturityIsResetOnNextCompilation() throws Exception {
Result exitCode = compiler.compile(args, Result exitCode = compiler.compile(args,
Arrays.asList(compiler.fileManager().forSourceLines("Test.java", testFile))); Arrays.asList(compiler.fileManager().forSourceLines("Test.java", testFile)));
outputStream.flush(); outputStream.flush();
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem( Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher = hasItem(
diagnosticMessage(containsString("[EmptyIf]"))); diagnosticMessage(containsString("[EmptyIf]")));
assertThat(outputStream.toString(), exitCode, is(Result.ERROR)); assertThat(outputStream.toString(), exitCode, is(Result.ERROR));
assertTrue( assertTrue(
Expand Down
Expand Up @@ -131,7 +131,7 @@ public void fileWithErrorIntegrationTest() throws Exception {
Collections.<String>emptyList(), Collections.<String>emptyList(),
Collections.<Class<? extends BugChecker>>emptyList()); Collections.<Class<? extends BugChecker>>emptyList());
assertThat(result.succeeded).isFalse(); assertThat(result.succeeded).isFalse();
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher =
hasItem(diagnosticMessage(containsString("[DepAnn]"))); hasItem(diagnosticMessage(containsString("[DepAnn]")));
assertTrue(matcher.matches(result.diagnosticHelper.getDiagnostics())); assertTrue(matcher.matches(result.diagnosticHelper.getDiagnostics()));
} }
Expand Down Expand Up @@ -162,7 +162,7 @@ public void testWithCheckPromotedToError() throws Exception {
Collections.<Class<? extends BugChecker>>emptyList()); Collections.<Class<? extends BugChecker>>emptyList());
assertThat(result.succeeded).isTrue(); assertThat(result.succeeded).isTrue();
assertThat(result.diagnosticHelper.getDiagnostics().size()).isGreaterThan(0); assertThat(result.diagnosticHelper.getDiagnostics().size()).isGreaterThan(0);
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher =
hasItem(diagnosticMessage(containsString("[WaitNotInLoop]"))); hasItem(diagnosticMessage(containsString("[WaitNotInLoop]")));
assertTrue(matcher.matches(result.diagnosticHelper.getDiagnostics())); assertTrue(matcher.matches(result.diagnosticHelper.getDiagnostics()));


Expand All @@ -185,7 +185,7 @@ public void testWithCheckDemotedToWarning() throws Exception {
Collections.<Class<? extends BugChecker>>emptyList()); Collections.<Class<? extends BugChecker>>emptyList());
assertThat(result.succeeded).isFalse(); assertThat(result.succeeded).isFalse();
assertThat(result.diagnosticHelper.getDiagnostics().size()).isGreaterThan(0); assertThat(result.diagnosticHelper.getDiagnostics().size()).isGreaterThan(0);
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher =
hasItem(diagnosticMessage(containsString("[DepAnn]"))); hasItem(diagnosticMessage(containsString("[DepAnn]")));
assertTrue(matcher.matches(result.diagnosticHelper.getDiagnostics())); assertTrue(matcher.matches(result.diagnosticHelper.getDiagnostics()));


Expand Down Expand Up @@ -216,7 +216,7 @@ public void testWithNonDefaultCheckOn() throws Exception {
Collections.<Class<? extends BugChecker>>emptyList()); Collections.<Class<? extends BugChecker>>emptyList());
assertThat(result.succeeded).isFalse(); assertThat(result.succeeded).isFalse();
assertThat(result.diagnosticHelper.getDiagnostics().size()).isGreaterThan(0); assertThat(result.diagnosticHelper.getDiagnostics().size()).isGreaterThan(0);
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher =
hasItem(diagnosticMessage(containsString("[EmptyIf]"))); hasItem(diagnosticMessage(containsString("[EmptyIf]")));
assertTrue(matcher.matches(result.diagnosticHelper.getDiagnostics())); assertTrue(matcher.matches(result.diagnosticHelper.getDiagnostics()));
} }
Expand Down Expand Up @@ -264,7 +264,7 @@ public void testWithCustomCheckPositive() throws Exception {
Arrays.<Class<? extends BugChecker>>asList(BadShiftAmount.class)); Arrays.<Class<? extends BugChecker>>asList(BadShiftAmount.class));
assertThat(result.succeeded).isFalse(); assertThat(result.succeeded).isFalse();
assertThat(result.diagnosticHelper.getDiagnostics().size()).isGreaterThan(0); assertThat(result.diagnosticHelper.getDiagnostics().size()).isGreaterThan(0);
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher =
hasItem(diagnosticMessage(containsString("[BadShiftAmount]"))); hasItem(diagnosticMessage(containsString("[BadShiftAmount]")));
assertTrue(matcher.matches(result.diagnosticHelper.getDiagnostics())); assertTrue(matcher.matches(result.diagnosticHelper.getDiagnostics()));
} }
Expand Down Expand Up @@ -304,7 +304,7 @@ public void testSeverityResetsAfterOverride() throws Exception {
sources); sources);
boolean succeeded = task.call(); boolean succeeded = task.call();
assertThat(succeeded).isTrue(); assertThat(succeeded).isTrue();
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher =
hasItem(diagnosticMessage(containsString("[ChainingConstructorIgnoresParameter]"))); hasItem(diagnosticMessage(containsString("[ChainingConstructorIgnoresParameter]")));
assertTrue(matcher.matches(diagnosticHelper.getDiagnostics())); assertTrue(matcher.matches(diagnosticHelper.getDiagnostics()));


Expand Down Expand Up @@ -352,7 +352,7 @@ public void testMaturityResetsAfterOverride() throws Exception {
sources); sources);
boolean succeeded = task.call(); boolean succeeded = task.call();
assertThat(succeeded).isFalse(); assertThat(succeeded).isFalse();
Matcher<Iterable<Diagnostic<JavaFileObject>>> matcher = Matcher<? super Iterable<Diagnostic<JavaFileObject>>> matcher =
hasItem(diagnosticMessage(containsString("[EmptyIf]"))); hasItem(diagnosticMessage(containsString("[EmptyIf]")));
assertTrue(matcher.matches(diagnosticHelper.getDiagnostics())); assertTrue(matcher.matches(diagnosticHelper.getDiagnostics()));


Expand Down

0 comments on commit c3c8cb9

Please sign in to comment.