diff --git a/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java b/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java index 1460c59da537..2c52c2a31400 100644 --- a/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java +++ b/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java @@ -2822,7 +2822,7 @@ public static boolean isRuleKind(CaseTree caseTree) { "unchecked", // reflection }) public static Stream getCaseExpressions(CaseTree caseTree) { - if (!RuntimeVersion.isAtLeast12()) { + if (Runtime.version().feature() < 12) { // "default" case gives an empty stream return Stream.ofNullable(caseTree.getExpression()); } diff --git a/check_api/src/main/java/com/google/errorprone/util/ErrorProneScope.java b/check_api/src/main/java/com/google/errorprone/util/ErrorProneScope.java index 6c73cf1c8636..50e2c9201a0e 100644 --- a/check_api/src/main/java/com/google/errorprone/util/ErrorProneScope.java +++ b/check_api/src/main/java/com/google/errorprone/util/ErrorProneScope.java @@ -61,7 +61,7 @@ public boolean anyMatch(Predicate predicate) { private static final Class FILTER_CLASS = getFilterClass(); private static @Nullable Class getFilterClass() { - if (RuntimeVersion.isAtLeast17()) { + if (Runtime.version().feature() >= 17) { return null; } try { diff --git a/check_api/src/main/java/com/google/errorprone/util/FindIdentifiers.java b/check_api/src/main/java/com/google/errorprone/util/FindIdentifiers.java index 1f0b82ac45fb..98b1cee86f40 100644 --- a/check_api/src/main/java/com/google/errorprone/util/FindIdentifiers.java +++ b/check_api/src/main/java/com/google/errorprone/util/FindIdentifiers.java @@ -112,7 +112,7 @@ public static Symbol findIdent(String name, VisitorState state) { private static Symbol findIdent( String name, VisitorState state, KindSelector kind, Env env) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { - if (RuntimeVersion.isAtLeast13()) { + if (Runtime.version().feature() >= 13) { Method method = Resolve.class.getDeclaredMethod( "findIdent", DiagnosticPosition.class, Env.class, Name.class, KindSelector.class); diff --git a/check_api/src/main/java/com/google/errorprone/util/RuntimeVersion.java b/check_api/src/main/java/com/google/errorprone/util/RuntimeVersion.java deleted file mode 100644 index 28e95215a2a6..000000000000 --- a/check_api/src/main/java/com/google/errorprone/util/RuntimeVersion.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2018 The Error Prone Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.errorprone.util; - -/** - * JDK runtime version utilities. - * - *

These methods are generally used when deciding which method to call reflectively. Bug checkers - * that rely on support for specific source code constructs should consult {@link SourceVersion} - * instead. - * - * @see SourceVersion - */ -public final class RuntimeVersion { - - private static final int FEATURE = Runtime.version().feature(); - - /** Returns true if the current runtime is JDK 12 or newer. */ - public static boolean isAtLeast12() { - return FEATURE >= 12; - } - - /** Returns true if the current runtime is JDK 13 or newer. */ - public static boolean isAtLeast13() { - return FEATURE >= 13; - } - - /** Returns true if the current runtime is JDK 14 or newer. */ - public static boolean isAtLeast14() { - return FEATURE >= 14; - } - - /** Returns true if the current runtime is JDK 15 or newer. */ - public static boolean isAtLeast15() { - return FEATURE >= 15; - } - - /** Returns true if the current runtime is JDK 16 or newer. */ - public static boolean isAtLeast16() { - return FEATURE >= 16; - } - - /** Returns true if the current runtime is JDK 17 or newer. */ - public static boolean isAtLeast17() { - return FEATURE >= 17; - } - - /** Returns true if the current runtime is JDK 18 or newer. */ - public static boolean isAtLeast18() { - return FEATURE >= 18; - } - - /** Returns true if the current runtime is JDK 19 or newer. */ - public static boolean isAtLeast19() { - return FEATURE >= 19; - } - - /** Returns true if the current runtime is JDK 20 or newer. */ - public static boolean isAtLeast20() { - return FEATURE >= 20; - } - - /** Returns true if the current runtime is JDK 21 or newer. */ - public static boolean isAtLeast21() { - return FEATURE >= 21; - } - - /** Returns true if the current runtime is JDK 22 or newer. */ - public static boolean isAtLeast22() { - return FEATURE >= 22; - } - - /** Returns true if the current runtime is JDK 23 or newer. */ - public static boolean isAtLeast23() { - return FEATURE >= 23; - } - - /** - * Returns the latest {@code --release} version. - * - *

Prefer the {@code isAtLeast} methods for assumption checks in tests. - */ - public static int release() { - return FEATURE; - } - - private RuntimeVersion() {} -} diff --git a/core/src/main/java/com/google/errorprone/refaster/PlaceholderUnificationVisitor.java b/core/src/main/java/com/google/errorprone/refaster/PlaceholderUnificationVisitor.java index faee2aa028f2..9a59350dd337 100644 --- a/core/src/main/java/com/google/errorprone/refaster/PlaceholderUnificationVisitor.java +++ b/core/src/main/java/com/google/errorprone/refaster/PlaceholderUnificationVisitor.java @@ -26,7 +26,6 @@ import com.google.errorprone.refaster.PlaceholderUnificationVisitor.State; import com.google.errorprone.refaster.UPlaceholderExpression.PlaceholderParamIdent; import com.google.errorprone.util.ASTHelpers; -import com.google.errorprone.util.RuntimeVersion; import com.sun.source.tree.ArrayAccessTree; import com.sun.source.tree.AssignmentTree; import com.sun.source.tree.BinaryTree; @@ -668,12 +667,12 @@ public Choice> visitCase(CaseTree node, State state) { private JCCase makeCase(CaseTree node, List stmts) { try { - if (RuntimeVersion.isAtLeast12()) { + if (Runtime.version().feature() >= 12) { Enum caseKind = (Enum) CaseTree.class.getMethod("getCaseKind").invoke(node); checkState( caseKind.name().contentEquals("STATEMENT"), "expression switches are not supported yet"); - if (RuntimeVersion.isAtLeast21()) { + if (Runtime.version().feature() >= 21) { return (JCCase) TreeMaker.class .getMethod( @@ -702,7 +701,7 @@ private JCCase makeCase(CaseTree node, List stmts) { .invoke( maker(), caseKind, - RuntimeVersion.isAtLeast17() + Runtime.version().feature() >= 17 ? CaseTree.class.getMethod("getLabels").invoke(node) : List.of((JCExpression) node.getExpression()), stmts, diff --git a/core/src/main/java/com/google/errorprone/refaster/UBreak.java b/core/src/main/java/com/google/errorprone/refaster/UBreak.java index 74c86f1b0f37..ddd2037acb6e 100644 --- a/core/src/main/java/com/google/errorprone/refaster/UBreak.java +++ b/core/src/main/java/com/google/errorprone/refaster/UBreak.java @@ -16,7 +16,6 @@ package com.google.errorprone.refaster; -import com.google.errorprone.util.RuntimeVersion; import com.sun.source.tree.BreakTree; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.TreeVisitor; @@ -75,7 +74,7 @@ public JCBreak inline(Inliner inliner) { private static JCBreak makeBreak(Name label, Inliner inliner) { try { - if (RuntimeVersion.isAtLeast12()) { + if (Runtime.version().feature() >= 12) { return (JCBreak) TreeMaker.class .getMethod("Break", JCExpression.class) diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/AnnotateFormatMethodTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/AnnotateFormatMethodTest.java index 47b8490f6bf1..d8b8e476d2e2 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/AnnotateFormatMethodTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/AnnotateFormatMethodTest.java @@ -16,10 +16,9 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -50,7 +49,7 @@ public void positiveCase() { @Test public void formatted() { - assumeTrue(RuntimeVersion.isAtLeast15()); + assume().that(Runtime.version().feature()).isAtLeast(15); compilationHelper .addSourceLines( "AnnotateFormatMethodPositiveCases.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/AnnotationPositionTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/AnnotationPositionTest.java index f800c772df56..247935577536 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/AnnotationPositionTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/AnnotationPositionTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns; +import static com.google.common.truth.TruthJUnit.assume; import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH; -import static org.junit.Assume.assumeTrue; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -361,7 +360,7 @@ public void diagnostic() { // TODO(b/168625474): 'sealed' doesn't have a TokenKind @Test public void sealedInterface() { - assumeTrue(RuntimeVersion.isAtLeast15()); + assume().that(Runtime.version().feature()).isAtLeast(15); refactoringHelper .addInputLines( "Test.java", // @@ -375,7 +374,7 @@ public void sealedInterface() { "sealed @Deprecated interface Test {", " final class A implements Test {}", "}") - .setArgs("--enable-preview", "--release", Integer.toString(RuntimeVersion.release())) + .setArgs("--enable-preview", "--release", Integer.toString(Runtime.version().feature())) .doTest(TEXT_MATCH); } @@ -532,7 +531,7 @@ public void varKeyword() { @Test public void recordAnnotation() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); refactoringHelper .addInputLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayFillIncompatibleTypeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayFillIncompatibleTypeTest.java index 21b00df1dd6b..e4149bb9346a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayFillIncompatibleTypeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayFillIncompatibleTypeTest.java @@ -16,10 +16,9 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeFalse; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import java.util.Arrays; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,7 +32,9 @@ public class ArrayFillIncompatibleTypeTest { @Test public void primitiveBoxingIntoObject() { - assumeFalse(RuntimeVersion.isAtLeast12()); // https://bugs.openjdk.java.net/browse/JDK-8028563 + assume() + .that(Runtime.version().feature()) + .isLessThan(12); // https://bugs.openjdk.java.net/browse/JDK-8028563 compilationHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java index e22105d689e6..4d3e45e9c5dc 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/CannotMockFinalClassTest.java @@ -16,10 +16,9 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -41,7 +40,7 @@ public void positiveCase() { @Test public void positiveCase_record() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); compilationHelper .addSourceLines( diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ClassCanBeStaticTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ClassCanBeStaticTest.java index 71a385a15e9a..bd0c694d59ea 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ClassCanBeStaticTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ClassCanBeStaticTest.java @@ -16,10 +16,9 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -346,7 +345,7 @@ public void nestedInLocal() { @Test public void nestedInLocal_static() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); compilationHelper .addSourceLines( "A.java", // diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/DefaultCharsetTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/DefaultCharsetTest.java index 059e8271b2c2..10352c7e97cb 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/DefaultCharsetTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/DefaultCharsetTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -505,7 +504,7 @@ public void scannerDefaultCharset() { @Test public void withVar() { - assumeTrue(RuntimeVersion.isAtLeast15()); + assume().that(Runtime.version().feature()).isAtLeast(15); refactoringTest() .addInputLines( "in/Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/DefaultLocaleTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/DefaultLocaleTest.java index 1bac680baacb..927007f3c879 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/DefaultLocaleTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/DefaultLocaleTest.java @@ -17,16 +17,15 @@ package com.google.errorprone.bugpatterns; import static com.google.common.base.Predicates.containsPattern; +import static com.google.common.truth.TruthJUnit.assume; import static com.google.errorprone.bugpatterns.DefaultLocale.onlyContainsSpecifiersInAllowList; import static java.util.function.Predicate.not; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -143,7 +142,7 @@ public void formatMethods_negative() { @Test public void stringFormatted() { - assumeTrue(RuntimeVersion.isAtLeast15()); + assume().that(Runtime.version().feature()).isAtLeast(15); compilationHelper .addSourceLines( "Test.java", @@ -236,7 +235,7 @@ public void factoryMethods() { @Test public void factoryMethodsJdk12plus() { - assumeTrue(RuntimeVersion.isAtLeast12()); + assume().that(Runtime.version().feature()).isAtLeast(12); compilationHelper .addSourceLines( "Test.java", @@ -313,7 +312,7 @@ public void resourceBundle() { @Test public void resourceBundleJdk9plus() { - assumeTrue(RuntimeVersion.release() >= 9); + assume().that(Runtime.version().feature()).isAtLeast(9); compilationHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/EqualsIncompatibleTypeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/EqualsIncompatibleTypeTest.java index b452433c6b0e..a5e3410bd9bf 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/EqualsIncompatibleTypeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/EqualsIncompatibleTypeTest.java @@ -16,10 +16,9 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeFalse; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import java.util.Arrays; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,7 +49,9 @@ public void negativeCase_recursive() { @Test public void primitiveBoxingIntoObject() { - assumeFalse(RuntimeVersion.isAtLeast12()); // https://bugs.openjdk.java.net/browse/JDK-8028563 + assume() + .that(Runtime.version().feature()) + .isLessThan(12); // https://bugs.openjdk.java.net/browse/JDK-8028563 compilationHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/FallThroughTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/FallThroughTest.java index 774e4f2791d5..1696ef1d3f1b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/FallThroughTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/FallThroughTest.java @@ -16,10 +16,9 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -102,7 +101,7 @@ public void emptyBlock() { @Test public void arrowSwitch() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", @@ -122,7 +121,7 @@ public void arrowSwitch() { @Ignore("https://github.com/google/error-prone/issues/2638") @Test public void i2118() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/FieldCanBeStaticTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/FieldCanBeStaticTest.java index 4e5a9319dbf7..49bdf3f5bf48 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/FieldCanBeStaticTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/FieldCanBeStaticTest.java @@ -16,11 +16,10 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -291,7 +290,7 @@ public void inner() { @Test public void inner_static() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); compilationHelper .addSourceLines( "Test.java", @@ -329,7 +328,7 @@ public void inner_static() { @Test public void record() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); compilationHelper .addSourceLines( "ExampleClass.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MethodCanBeStaticTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MethodCanBeStaticTest.java index 2a929f7bd1cf..8e39f176f427 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MethodCanBeStaticTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MethodCanBeStaticTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.common.collect.ImmutableList; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -336,7 +335,7 @@ public void innerClass() { @Test public void innerClass_static() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); testHelper .addSourceLines( "Test.java", // @@ -397,7 +396,7 @@ public void negativeLocal() { @Test public void positiveLocal() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); testHelper .addSourceLines( "Test.java", // diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MissingCasesInEnumSwitchTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MissingCasesInEnumSwitchTest.java index 887db8d71180..32208051f3c5 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MissingCasesInEnumSwitchTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MissingCasesInEnumSwitchTest.java @@ -16,10 +16,9 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -52,7 +51,7 @@ public void exhaustive() { @Test public void exhaustive_multipleCaseExpressions() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", @@ -163,7 +162,7 @@ public void empty() { @Test public void nonExhaustive_arrowStatement() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", @@ -183,7 +182,7 @@ public void nonExhaustive_arrowStatement() { @Test public void nonExhaustive_multi() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", @@ -202,7 +201,7 @@ public void nonExhaustive_multi() { @Test public void nonExhaustive_multiArrow() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MissingDefaultTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MissingDefaultTest.java index 977467e0d17d..d063c2230cca 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MissingDefaultTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MissingDefaultTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns; +import static com.google.common.truth.TruthJUnit.assume; import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH; -import static org.junit.Assume.assumeTrue; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -230,7 +229,7 @@ public void multipleStatementsInGroup() { @Test public void arrowSwitch() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", @@ -248,7 +247,7 @@ public void arrowSwitch() { @Test public void arrowSwitchNegative() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", @@ -266,7 +265,7 @@ public void arrowSwitchNegative() { @Test public void arrowComment() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", @@ -285,7 +284,7 @@ public void arrowComment() { @Test public void exhaustiveExpressionSwitch() { - assumeTrue(RuntimeVersion.isAtLeast21()); + assume().that(Runtime.version().feature()).isAtLeast(21); compilationHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MixedMutabilityReturnTypeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MixedMutabilityReturnTypeTest.java index b41f4d191af8..09a2706cdbec 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MixedMutabilityReturnTypeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MixedMutabilityReturnTypeTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -480,7 +479,7 @@ public void refactoringWithNestedCollectionsHelper() { @Test public void refactoringWithVar() { - assumeTrue(RuntimeVersion.isAtLeast15()); + assume().that(Runtime.version().feature()).isAtLeast(15); refactoringHelper .addInputLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MultipleTopLevelClassesTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MultipleTopLevelClassesTest.java index 9138ed036a28..4d0e67b18ce6 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MultipleTopLevelClassesTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MultipleTopLevelClassesTest.java @@ -19,7 +19,6 @@ import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -89,7 +88,7 @@ public void emptyDeclaration() { @Test public void semiInImportList() { - assume().that(RuntimeVersion.isAtLeast21()).isFalse(); + assume().that(Runtime.version().feature()).isLessThan(21); compilationHelper .addSourceLines( "a/A.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/NamedLikeContextualKeywordTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/NamedLikeContextualKeywordTest.java index 7f2a74d52f3d..3b14ea017fe9 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/NamedLikeContextualKeywordTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/NamedLikeContextualKeywordTest.java @@ -16,11 +16,10 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.common.collect.ImmutableList; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -141,7 +140,7 @@ public void className_error() { @Test public void yieldInSwitch_noError() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/NestedInstanceOfConditionsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/NestedInstanceOfConditionsTest.java index 44bdbbb7c66f..74455956b818 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/NestedInstanceOfConditionsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/NestedInstanceOfConditionsTest.java @@ -19,7 +19,6 @@ import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -46,7 +45,7 @@ public void negativeCase() { @Test public void patternMatchingInstanceof() { - assume().that(RuntimeVersion.isAtLeast21()).isTrue(); + assume().that(Runtime.version().feature()).isAtLeast(21); compilationHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/NewFileSystemTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/NewFileSystemTest.java index e31e301b4886..bd95d877f53d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/NewFileSystemTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/NewFileSystemTest.java @@ -16,11 +16,10 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeFalse; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -36,7 +35,7 @@ public class NewFileSystemTest { @Test public void refactoring() { - assumeFalse(RuntimeVersion.isAtLeast13()); + assume().that(Runtime.version().feature()).isLessThan(13); refactoringTestHelper .addInputLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/NullTernaryTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/NullTernaryTest.java index 55d58c55070b..47dcb2878278 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/NullTernaryTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/NullTernaryTest.java @@ -16,10 +16,9 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -127,7 +126,7 @@ public void conditionalInCondition() { @Test public void expressionSwitch_doesNotCrash() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/PatternMatchingInstanceofTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/PatternMatchingInstanceofTest.java index b6a5bec5f217..95b0a14cbec1 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/PatternMatchingInstanceofTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/PatternMatchingInstanceofTest.java @@ -19,7 +19,6 @@ import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.BugCheckerRefactoringTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -31,7 +30,7 @@ public final class PatternMatchingInstanceofTest { @Test public void positive() { - assume().that(RuntimeVersion.isAtLeast21()).isTrue(); + assume().that(Runtime.version().feature()).isAtLeast(21); helper .addInputLines( "Test.java", @@ -74,7 +73,7 @@ public void notDefinitelyChecked_noFinding() { @Test public void moreChecksInIf_stillMatches() { - assume().that(RuntimeVersion.isAtLeast21()).isTrue(); + assume().that(Runtime.version().feature()).isAtLeast(21); helper .addInputLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/PrivateConstructorForUtilityClassTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/PrivateConstructorForUtilityClassTest.java index a1165e445fe3..6b9d87c021bb 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/PrivateConstructorForUtilityClassTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/PrivateConstructorForUtilityClassTest.java @@ -15,11 +15,10 @@ */ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -351,7 +350,7 @@ public void abstractClass_noPrivateConstructor() { @Test public void record() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); CompilationTestHelper.newInstance(PrivateConstructorForUtilityClass.class, getClass()) .addSourceLines( "ExampleUtilityClass.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java index 461ae7928225..629a8e4039d5 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.common.collect.ImmutableList; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -38,7 +37,7 @@ public final class StatementSwitchToExpressionSwitchTest { @Test public void switchByEnum_removesRedundantBreak_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -124,7 +123,7 @@ public void switchByEnum_removesRedundantBreak_error() { @Test public void switchByEnumWithCompletionAnalsis_removesRedundantBreak_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -202,7 +201,7 @@ public void switchByEnumWithCompletionAnalsis_removesRedundantBreak_error() { @Test public void switchByEnumCard_combinesCaseComments_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -289,7 +288,7 @@ public void switchByEnumCard_combinesCaseComments_error() { @Test public void switchByEnumCard2_removesRedundantBreaks_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -374,7 +373,7 @@ public void switchByEnumCard2_removesRedundantBreaks_error() { @Test public void switchByEnumCard_onlyExpressionsAndThrowAreBraceless_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -461,7 +460,7 @@ public void switchByEnumCard_onlyExpressionsAndThrowAreBraceless_error() { @Test public void switchFallsThruToDefault_noError() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -492,7 +491,7 @@ public void switchFallsThruToDefault_noError() { public void switchFallsThruFromDefault_noError() { // Placing default in the middle of the switch is not recommended, but is valid Java - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -525,7 +524,7 @@ public void switchFallsThruFromDefault_noError() { public void switchWithDefaultInMiddle_error() { // Placing default in the middle of the switch is not recommended, but is valid Java - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -610,7 +609,7 @@ public void switchWithDefaultInMiddle_error() { @Test public void switchWithLabelledBreak_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -696,7 +695,7 @@ public void switchWithLabelledBreak_error() { @Test public void switchByEnum_statementSwitchWithMultipleExpressions_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -768,7 +767,7 @@ public void switchByEnum_statementSwitchWithMultipleExpressions_error() { @Test public void switchByEnumCardWithThrow_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -799,7 +798,7 @@ public void switchByEnumCardWithThrow_error() { @Test public void switchInSwitch_error() { // Only the outer "switch" should generate a finding - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -836,7 +835,7 @@ public void switchInSwitch_error() { @Test public void switchByEnumCardWithReturnNested1_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -910,7 +909,7 @@ public void switchByEnumCardWithReturnNested1_error() { @Test public void switchByEnumCardWithReturnNested2_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -942,7 +941,7 @@ public void switchByEnumCardWithReturnNested2_error() { @Test public void switchByEnumWithConditionalControl_noError() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -973,7 +972,7 @@ public void switchByEnumWithConditionalControl_noError() { @Test public void switchByEnumWithLambda_noError() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1005,7 +1004,7 @@ public void switchByEnumWithLambda_noError() { @Test public void singleCaseConvertible_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1030,7 +1029,7 @@ public void singleCaseConvertible_error() { @Test public void emptyExpressionSwitchCases_noMatch() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1047,7 +1046,7 @@ public void emptyExpressionSwitchCases_noMatch() { @Test public void nonEmptyExpressionSwitchCases_noMatch() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1064,7 +1063,7 @@ public void nonEmptyExpressionSwitchCases_noMatch() { @Test public void dynamicWithThrowableDuringInitializationFromMethod_noMatch() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1085,7 +1084,7 @@ public void dynamicWithThrowableDuringInitializationFromMethod_noMatch() { @Test public void switchByEnum_exampleInDocumentation_error() { // This code appears as an example in the documentation (added surrounding class) - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1163,7 +1162,7 @@ public void switchByEnum_exampleInDocumentation_error() { public void switchByEnum_caseHasOnlyComments_error() { // When a case is solely comments, we should still try to convert the switch using braceless // syntax - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1243,7 +1242,7 @@ public void switchByEnum_caseHasOnlyComments_error() { @Test public void switchByEnum_accumulatedComments_error() { // Comments should be aggregated across multiple cases - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1325,7 +1324,7 @@ public void switchByEnum_accumulatedComments_error() { public void switchByEnum_surroundingBracesCannotRemove_error() { // Can't remove braces around OBVERSE because break statements are not a member of // KINDS_CONVERTIBLE_WITHOUT_BRACES - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1400,7 +1399,7 @@ public void switchByEnum_surroundingBracesCannotRemove_error() { public void switchByEnum_surroundingBracesEmpty_error() { // Test handling of cases with surrounding braces that are empty. The braces around OBVERSE // can be removed because throw is a member of KINDS_CONVERTIBLE_WITHOUT_BRACES. - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( @@ -1471,7 +1470,7 @@ public void switchByEnum_surroundingBracesEmpty_error() { @Test public void switchByEnum_afterReturnComments_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1552,7 +1551,7 @@ public void switchByEnum_afterReturnComments_error() { @Test public void switchByEnum_returnSwitch_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1632,7 +1631,7 @@ public void switchByEnum_returnSwitch_error() { @Test public void switchByEnum_returnSwitchWithShouldNeverHappen_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); // Check correct generated code refactoringHelper @@ -1690,7 +1689,7 @@ public void switchByEnum_returnSwitchWithShouldNeverHappen_error() { @Test public void switchByEnum_switchInReturnSwitchWithShouldNeverHappen_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); // No error because the inner switch is the only fixable one helper .addSourceLines( @@ -1735,7 +1734,7 @@ public void switchByEnum_switchInReturnSwitchWithShouldNeverHappen_error() { @Test public void switchByEnum_exhaustiveWithDefault_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1819,7 +1818,7 @@ public void switchByEnum_exhaustiveWithDefault_error() { @Test public void switchByEnum_defaultFallThru_noError() { // No error because default doesn't return anything within its block - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1853,7 +1852,7 @@ public void switchByEnum_defaultFallThru_noError() { @Test public void switchByEnum_alwaysThrows_noError() { // Every case throws, thus no type for return switch - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -1886,7 +1885,7 @@ public void switchByEnum_alwaysThrows_noError() { @Test public void switchByEnum_returnSwitchWithShouldNeverHappen_errorAndRemoveShouldNeverHappen() { // The switch has a case for each enum and "should never happen" error handling - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2007,7 +2006,7 @@ public void switchByEnum_returnSwitchWithShouldNeverHappen_errorAndRemoveShouldN public void switchByEnum_returnSwitchNoFollowingStatementsInBlock_errorAndNoRemoval() { // The switch is exhaustive but doesn't have any statements immediately following it in the // lowest ancestor statement block - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2120,7 +2119,7 @@ public void switchByEnum_returnSwitchNoFollowingStatementsInBlock_errorAndNoRemo public void switchByEnum_groupedComments_errorAndNoRemoval() { // The switch is exhaustive but doesn't have any statements immediately following it in the // lowest ancestor statement block - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2249,7 +2248,7 @@ public void switchByEnum_groupedComments_errorAndNoRemoval() { public void switchByEnum_returnSwitchWithShouldNeverHappenInLambda_errorAndRemoveShouldNeverHappen() { // Conversion to return switch within a lambda - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); refactoringHelper .addInputLines( @@ -2320,7 +2319,7 @@ public void switchByEnum_groupedComments_errorAndNoRemoval() { @Test public void switchByEnum_returnSwitchVoid_noError() { // A void cannot be converted to a return switch - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2351,7 +2350,7 @@ public void switchByEnum_returnSwitchVoid_noError() { @Test public void switchByEnum_returnLabelledContinue_noError() { // Control jumps outside the switch for HEART - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2385,7 +2384,7 @@ public void switchByEnum_returnLabelledContinue_noError() { @Test public void switchByEnum_returnUnlabelledContinue_noError() { // Control jumps outside the switch for HEART - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2419,7 +2418,7 @@ public void switchByEnum_returnUnlabelledContinue_noError() { @Test public void switchByEnum_returnLabelledBreak_noError() { // Control jumps outside the switch for HEART - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2454,7 +2453,7 @@ public void switchByEnum_returnLabelledBreak_noError() { @Test public void switchByEnum_returnYield_noError() { // Does not attempt to convert "yield" expressions - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2490,7 +2489,7 @@ public void switchByEnum_returnYield_noError() { @Test public void switchByEnum_assignmentSwitchToLocalHasDefault_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2573,7 +2572,7 @@ public void switchByEnum_assignmentSwitchToLocalHasDefault_error() { @Test public void switchByEnum_assignmentSwitchMixedReferences_error() { // Must deduce that "x" and "this.x" refer to same thing - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2667,7 +2666,7 @@ public void switchByEnum_assignmentSwitchMixedReferences_error() { @Test public void switchByEnum_assignmentSwitchMixedReferences_noError() { // Must deduce that "x" and "this.y" refer to different things - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2704,7 +2703,7 @@ public void switchByEnum_assignmentSwitchMixedReferences_noError() { @Test public void switchByEnum_assignmentSwitchTwoAssignments_noError() { // Can't convert multiple assignments, even if redundant - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2740,7 +2739,7 @@ public void switchByEnum_assignmentSwitchTwoAssignments_noError() { @Test public void switchByEnum_assignmentSwitchToSingleArray_error() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2829,7 +2828,7 @@ public void switchByEnum_assignmentSwitchToMultipleArray_noError() { // Multiple array dereferences or other non-variable left-hand-side expressions may (in // principle) be convertible to assignment switches, but this feature is not supported at this // time - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2866,7 +2865,7 @@ public void switchByEnum_assignmentSwitchToMultipleArray_noError() { @Test public void switchByEnum_assignmentSwitchToMultipleDistinct_noError() { // x[5] and x[6] are distinct assignment targets - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2904,7 +2903,7 @@ public void switchByEnum_assignmentSwitchToMultipleDistinct_noError() { public void switchByEnum_assignmentSwitchMixedKinds_noError() { // Different assignment types ("=" versus "+="). The check does not attempt to alter the // assignments to make the assignment types match (e.g. does not change to "x = x + 2") - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2939,7 +2938,7 @@ public void switchByEnum_assignmentSwitchMixedKinds_noError() { @Test public void switchByEnum_assignmentLabelledContinue_noError() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -2980,7 +2979,7 @@ public void switchByEnum_assignmentLabelledContinue_noError() { @Test public void switchByEnum_assignmentLabelledBreak_noError() { // Can't convert because of "break before" - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -3021,7 +3020,7 @@ public void switchByEnum_assignmentLabelledBreak_noError() { @Test public void switchByEnum_assignmentLabelledBreak2_noError() { // Can't convert because of "break before" as the second statement in its block - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -3062,7 +3061,7 @@ public void switchByEnum_assignmentLabelledBreak2_noError() { @Test public void switchByEnum_assignmentUnlabelledContinue_noError() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -3103,7 +3102,7 @@ public void switchByEnum_assignmentUnlabelledContinue_noError() { @Test public void switchByEnum_assignmentYield_noError() { // Does not attempt to convert "yield" expressions - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -3138,7 +3137,7 @@ public void switchByEnum_exhaustiveAssignmentSwitch_error() { // Transformation can change error handling. Here, if the enum is not exhaustive at runtime // (say there is a new JOKER suit), then nothing would happen. But the transformed source, // would throw. - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -3223,7 +3222,7 @@ public void switchByEnum_exhaustiveAssignmentSwitch_error() { @Test public void switchByEnum_exhaustiveCompoundAssignmentSwitch_error() { // Verify compound assignments (here, +=) - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -3302,7 +3301,7 @@ public void switchByEnum_exhaustiveCompoundAssignmentSwitch_error() { @Test public void switchByEnum_groupedComments_error() { // Verify compound assignments (here, *=) with grouped comments - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -3408,7 +3407,7 @@ public void switchByEnum_groupedComments_error() { @Test public void switchByEnum_compoundAssignmentExampleInDocumentation_error() { // This code appears as an example in the documentation (added surrounding class) - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -3479,7 +3478,7 @@ public void switchByEnum_compoundAssignmentExampleInDocumentation_error() { @Test public void switchByEnum_exhaustiveAssignmentSwitchCaseList_error() { // Statement switch has cases with multiple values - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -3551,7 +3550,7 @@ public void switchByEnum_exhaustiveAssignmentSwitchCaseList_error() { @Test public void switchByEnum_nonExhaustiveAssignmentSwitch_noError() { // No HEART case - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); helper .addSourceLines( "Test.java", @@ -3582,7 +3581,7 @@ public void switchByEnum_nonExhaustiveAssignmentSwitch_noError() { @Test public void i4222() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); refactoringHelper .addInputLines( "Test.java", @@ -3624,7 +3623,7 @@ public void i4222() { @Test public void unnecessaryBreaks() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); refactoringHelper .addInputLines( "Test.java", @@ -3660,7 +3659,7 @@ public void unnecessaryBreaks() { @Test public void mixedExpressionsAndYields() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); refactoringHelper .addInputLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/StreamResourceLeakTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/StreamResourceLeakTest.java index bf2734ab6277..968efb804518 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/StreamResourceLeakTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/StreamResourceLeakTest.java @@ -16,13 +16,12 @@ package com.google.errorprone.bugpatterns; +import static com.google.common.truth.TruthJUnit.assume; import static java.lang.String.format; -import static org.junit.Assume.assumeTrue; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import com.google.testing.junit.testparameterinjector.TestParameter; import com.google.testing.junit.testparameterinjector.TestParameterInjector; import org.junit.Test; @@ -289,7 +288,7 @@ public void defaultMethod() { @Test public void record() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); testHelper .addSourceLines( "ExampleRecord.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/StringFormatWithLiteralTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/StringFormatWithLiteralTest.java index dda227eef24c..127be1c0ff8f 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/StringFormatWithLiteralTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/StringFormatWithLiteralTest.java @@ -16,11 +16,10 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -200,7 +199,7 @@ public void refactoringStringFormatWithNoArguments() { @Test public void refactoringFormattedWithNoArguments() { - assumeTrue(RuntimeVersion.isAtLeast15()); + assume().that(Runtime.version().feature()).isAtLeast(15); refactoringHelper .addInputLines( "ExampleClass.java", @@ -241,7 +240,7 @@ public void refactoringStringFormatWithIntegerLiteral() { @Test public void refactoringFormattedWithIntegerLiteral() { - assumeTrue(RuntimeVersion.isAtLeast15()); + assume().that(Runtime.version().feature()).isAtLeast(15); refactoringHelper .addInputLines( "ExampleClass.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/SwitchDefaultTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/SwitchDefaultTest.java index 14215648b788..25ab12ef524b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/SwitchDefaultTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/SwitchDefaultTest.java @@ -16,11 +16,10 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -235,7 +234,7 @@ public void refactoring_outOfOrder() { @Test public void newNotation_validDefault() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", @@ -257,7 +256,7 @@ public void newNotation_validDefault() { @Test public void newNotation_changeOrder() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addInputLines( "Test.java", @@ -294,7 +293,7 @@ public void newNotation_changeOrder() { @Test public void arrowSwitch_noDefault() { - assumeTrue(RuntimeVersion.isAtLeast21()); + assume().that(Runtime.version().feature()).isAtLeast(21); compilationHelper .addSourceLines( "Foo.java", // diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/TraditionalSwitchExpressionTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/TraditionalSwitchExpressionTest.java index 00a3dbc18c41..57edd30a543b 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/TraditionalSwitchExpressionTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/TraditionalSwitchExpressionTest.java @@ -16,10 +16,9 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -32,7 +31,7 @@ public class TraditionalSwitchExpressionTest { @Test public void positive() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", @@ -66,7 +65,7 @@ public void negativeStatement() { @Test public void negativeArrowStatement() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", @@ -82,7 +81,7 @@ public void negativeArrowStatement() { @Test public void negativeArrow() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java index f2fb2305beba..f7be58d98a31 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java @@ -16,13 +16,12 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.common.collect.ImmutableList; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -293,7 +292,7 @@ public void describingConstructors() { @Test public void recordConstructor() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); compilationHelper .addSourceLines( diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBreakInSwitchTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBreakInSwitchTest.java index 49da24c7c46a..a43781e70038 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBreakInSwitchTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBreakInSwitchTest.java @@ -16,10 +16,9 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -32,7 +31,7 @@ public class UnnecessaryBreakInSwitchTest { @Test public void positive() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", @@ -67,7 +66,7 @@ public void negativeTraditional() { @Test public void negativeEmpty() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", @@ -84,7 +83,7 @@ public void negativeEmpty() { @Test public void negativeNotLast() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", @@ -105,7 +104,7 @@ public void negativeNotLast() { @Test public void negativeLabelledBreak() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", @@ -126,7 +125,7 @@ public void negativeLabelledBreak() { @Test public void negativeLoop() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", @@ -148,7 +147,7 @@ public void negativeLoop() { @Test public void positiveIf() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); testHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryDefaultInEnumSwitchTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryDefaultInEnumSwitchTest.java index 4ef8b07473db..6fe6a0b750d7 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryDefaultInEnumSwitchTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryDefaultInEnumSwitchTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns; +import static com.google.common.truth.TruthJUnit.assume; import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH; -import static org.junit.Assume.assumeTrue; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -784,7 +783,7 @@ public void messages() { @Test public void defaultCaseKindRule() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", @@ -804,7 +803,7 @@ public void defaultCaseKindRule() { @Test public void unrecognizedCaseKindRule() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", @@ -824,7 +823,7 @@ public void unrecognizedCaseKindRule() { @Test public void multipleLabels() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryParenthesesTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryParenthesesTest.java index e60ef9a75eaf..fc8fc026b8e2 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryParenthesesTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryParenthesesTest.java @@ -16,11 +16,10 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -242,7 +241,7 @@ public void positiveStatements() { @Test public void switchExpression() { - assumeTrue(RuntimeVersion.isAtLeast12()); + assume().that(Runtime.version().feature()).isAtLeast(12); helper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UnusedVariableTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UnusedVariableTest.java index 4db2f04b54ff..bc25c7b2762c 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UnusedVariableTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UnusedVariableTest.java @@ -14,14 +14,13 @@ package com.google.errorprone.bugpatterns; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.common.collect.ImmutableList; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -1387,7 +1386,7 @@ public void unusedReassignment_keepSideEffectsFix() { @Test public void simpleRecord() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "SimpleRecord.java", // @@ -1398,7 +1397,7 @@ public void simpleRecord() { @Test public void nestedRecord() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "SimpleClass.java", @@ -1411,7 +1410,7 @@ public void nestedRecord() { @Test public void recordWithStaticFields() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "SimpleClass.java", @@ -1440,7 +1439,7 @@ public void recordWithStaticFields() { // methods differently @Test public void nestedPrivateRecord() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "SimpleClass.java", @@ -1453,7 +1452,7 @@ public void nestedPrivateRecord() { @Test public void nestedPrivateRecordCompactCanonicalConstructor() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "SimpleClass.java", @@ -1471,7 +1470,7 @@ public void nestedPrivateRecordCompactCanonicalConstructor() { @Test public void nestedPrivateRecordNormalCanonicalConstructor() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "SimpleClass.java", @@ -1489,7 +1488,7 @@ public void nestedPrivateRecordNormalCanonicalConstructor() { @Test public void unusedRecordConstructorParameter() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "SimpleRecord.java", @@ -1504,7 +1503,7 @@ public void unusedRecordConstructorParameter() { @Test public void unusedInRecord() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "SimpleClass.java", @@ -1682,7 +1681,7 @@ public void parameterUsedInOverride() { @Test public void underscoreVariable() { - assumeTrue(RuntimeVersion.isAtLeast22()); + assume().that(Runtime.version().feature()).isAtLeast(22); refactoringHelper .addInputLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/formatstring/FormatStringTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/formatstring/FormatStringTest.java index 3d0587ee40c2..db2e77133c50 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/formatstring/FormatStringTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/formatstring/FormatStringTest.java @@ -16,10 +16,9 @@ package com.google.errorprone.bugpatterns.formatstring; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -353,7 +352,7 @@ public void number() { @Test public void invalidIndex() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); compilationHelper .addSourceLines( "T.java", @@ -368,7 +367,7 @@ public void invalidIndex() { @Test public void stringFormattedNegativeCase() { - assumeTrue(RuntimeVersion.isAtLeast15()); + assume().that(Runtime.version().feature()).isAtLeast(15); compilationHelper .addSourceLines( "Test.java", @@ -382,7 +381,7 @@ public void stringFormattedNegativeCase() { @Test public void stringFormattedPositiveCase() { - assumeTrue(RuntimeVersion.isAtLeast15()); + assume().that(Runtime.version().feature()).isAtLeast(15); compilationHelper .addSourceLines( "Test.java", @@ -397,7 +396,7 @@ public void stringFormattedPositiveCase() { @Test public void nonConstantStringFormattedNegativeCase() { - assumeTrue(RuntimeVersion.isAtLeast15()); + assume().that(Runtime.version().feature()).isAtLeast(15); compilationHelper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/InvalidLinkTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/InvalidLinkTest.java index bad5c2775fda..f010099bec20 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/InvalidLinkTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/InvalidLinkTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns.javadoc; +import static com.google.common.truth.TruthJUnit.assume; import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH; -import static org.junit.Assume.assumeTrue; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -186,7 +185,7 @@ public void emptyLinkTest() { @Test public void markdown() { - assumeTrue(RuntimeVersion.isAtLeast23()); + assume().that(Runtime.version().feature()).isAtLeast(23); helper .addSourceLines( "Test.java", // diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/InvalidParamTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/InvalidParamTest.java index 69fe498018cf..31256a344e8d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/InvalidParamTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/InvalidParamTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns.javadoc; +import static com.google.common.truth.TruthJUnit.assume; import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH; -import static org.junit.Assume.assumeTrue; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -192,7 +191,7 @@ public void excludedName_noMatchDespiteSimilarParam() { @Test public void negative_record() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "Test.java", // @@ -205,7 +204,7 @@ public void negative_record() { @Test public void badParameterName_record() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "Test.java", @@ -219,7 +218,7 @@ public void badParameterName_record() { @Test public void multipleConstructors_record() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "Test.java", @@ -245,7 +244,7 @@ public void multipleConstructors_record() { @Test public void typeParameter_record() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "Negative.java", @@ -269,7 +268,7 @@ public void typeParameter_record() { @Test public void compactConstructor_record() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "Test.java", @@ -284,7 +283,7 @@ public void compactConstructor_record() { @Test public void normalConstructor_record() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); helper .addSourceLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/UnescapedEntityTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/UnescapedEntityTest.java index aa82a4413ac6..ef8280e5e75d 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/UnescapedEntityTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/javadoc/UnescapedEntityTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns.javadoc; -import static org.junit.Assume.assumeFalse; +import static com.google.common.truth.TruthJUnit.assume; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -111,7 +110,9 @@ public void withinPre_singleChar() { @Test public void withinPre_alreadyEscaped() { - assumeFalse(RuntimeVersion.isAtLeast15()); // https://bugs.openjdk.java.net/browse/JDK-8241780 + assume() + .that(Runtime.version().feature()) + .isLessThan(15); // https://bugs.openjdk.java.net/browse/JDK-8241780 refactoring .addInputLines( "Test.java", @@ -131,7 +132,9 @@ public void withinPre_alreadyEscaped() { @Test public void withinPre_hasAnnotations() { - assumeFalse(RuntimeVersion.isAtLeast15()); // https://bugs.openjdk.java.net/browse/JDK-8241780 + assume() + .that(Runtime.version().feature()) + .isLessThan(15); // https://bugs.openjdk.java.net/browse/JDK-8241780 refactoring .addInputLines( "Test.java", @@ -160,7 +163,9 @@ public void withinPre_hasAnnotations() { @Test public void escapesWithoutAddingCodeBlock_withinPreBlockWithAnnotation() { - assumeFalse(RuntimeVersion.isAtLeast15()); // https://bugs.openjdk.java.net/browse/JDK-8241780 + assume() + .that(Runtime.version().feature()) + .isLessThan(15); // https://bugs.openjdk.java.net/browse/JDK-8241780 refactoring .addInputLines( "Test.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/FieldMissingNullableTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/FieldMissingNullableTest.java index e5d6d2939bac..f5695e3cc67a 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/FieldMissingNullableTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/FieldMissingNullableTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns.nullness; +import static com.google.common.truth.TruthJUnit.assume; import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH; -import static org.junit.Assume.assumeTrue; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -168,7 +167,7 @@ public void comparisonToNullOnOtherInstance() { @Test public void recordComponent() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); createAggressiveRefactoringTestHelper() .addInputLines( "com/google/errorprone/bugpatterns/nullness/FieldMissingNullTest.java", @@ -281,7 +280,7 @@ public void negativeCases_alreadyTypeAnnotatedInnerClass() { @Test public void negativeCases_alreadyAnnotatedRecordComponent() { - assumeTrue(RuntimeVersion.isAtLeast16()); + assume().that(Runtime.version().feature()).isAtLeast(16); createAggressiveCompilationTestHelper() .addSourceLines( "com/google/errorprone/bugpatterns/nullness/FieldMissingNullTest.java", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullableTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullableTest.java index 3fbb6ec97c61..95561d171582 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullableTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullableTest.java @@ -16,12 +16,11 @@ package com.google.errorprone.bugpatterns.nullness; +import static com.google.common.truth.TruthJUnit.assume; import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH; -import static org.junit.Assume.assumeTrue; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.util.RuntimeVersion; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -139,7 +138,7 @@ public void parenthesizedConditionalLiteralNullReturn() { @Test public void switchExpressionTree() { - assumeTrue(RuntimeVersion.isAtLeast12()); + assume().that(Runtime.version().feature()).isAtLeast(12); createCompilationTestHelper() .addSourceLines( @@ -159,7 +158,7 @@ public void switchExpressionTree() { @Test public void switchExpressionTree_negative() { - assumeTrue(RuntimeVersion.isAtLeast12()); + assume().that(Runtime.version().feature()).isAtLeast(12); createCompilationTestHelper() .addSourceLines( diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableCheckerTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableCheckerTest.java index 10e4da2f7364..121826b219d7 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableCheckerTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/threadsafety/ImmutableCheckerTest.java @@ -16,14 +16,13 @@ package com.google.errorprone.bugpatterns.threadsafety; -import static org.junit.Assume.assumeTrue; +import static com.google.common.truth.TruthJUnit.assume; import com.google.common.collect.ImmutableList; import com.google.errorprone.CompilationTestHelper; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.Immutable; import com.google.errorprone.annotations.concurrent.LazyInit; -import com.google.errorprone.util.RuntimeVersion; import java.util.Arrays; import org.junit.Ignore; import org.junit.Test; @@ -2994,7 +2993,7 @@ public void anonymousClass_canCallSuperMethodOnNonImmutableSuperClass() { @Test public void switchExpressionsResultingInGenericTypes_doesNotThrow() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Kind.java", @@ -3017,7 +3016,7 @@ public void switchExpressionsResultingInGenericTypes_doesNotThrow() { @Test public void switchExpressionsYieldStatement_doesNotThrow() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", @@ -3037,7 +3036,7 @@ public void switchExpressionsYieldStatement_doesNotThrow() { @Test public void switchExpressionsMethodReference_doesNotThrow() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java", @@ -3055,7 +3054,7 @@ public void switchExpressionsMethodReference_doesNotThrow() { @Test public void switchExpressionsYieldStatementMethodReference_doesNotThrow() { - assumeTrue(RuntimeVersion.isAtLeast14()); + assume().that(Runtime.version().feature()).isAtLeast(14); compilationHelper .addSourceLines( "Test.java",