diff --git a/README.md b/README.md index a2e221589..dca08f586 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,6 @@ Safe Logging can be found at [github.com/palantir/safe-logging](https://github.c - `StrictUnusedVariable`: Functions shouldn't have unused parameters. - `StringBuilderConstantParameters`: StringBuilder with a constant number of parameters should be replaced by simple concatenation. - `JUnit5SuiteMisuse`: When migrating from JUnit4 -> JUnit5, classes annotated with `@RunWith(Suite.class)` are dangerous because if they reference any JUnit5 test classes, these tests will silently not run! -- `PreferAssertj`: Prefer AssertJ fluent assertions. - `ThrowError`: Prefer throwing a RuntimeException rather than Error. - `ReverseDnsLookup`: Calling address.getHostName may result in an unexpected DNS lookup. - `ReadReturnValueIgnored`: The result of a read call must be checked to know if EOF has been reached or the expected number of bytes have been consumed. @@ -182,7 +181,6 @@ Safe Logging can be found at [github.com/palantir/safe-logging](https://github.c - `JooqResultStreamLeak`: Autocloseable streams and cursors from jOOQ results should be obtained in a try-with-resources statement. - `StreamOfEmpty`: Stream.of() should be replaced with Stream.empty() to avoid unnecessary varargs allocation. - `RedundantMethodReference`: Redundant method reference to the same type. -- `AssertjPrimitiveComparison`: Prefer using AssertJ fluent comparisons over logic in an assertThat statement. - `ExceptionSpecificity`: Prefer more specific catch types than Exception and Throwable. - `ThrowSpecificity`: Prefer to declare more specific `throws` types than Exception and Throwable. @@ -198,7 +196,7 @@ You may apply specific error-prone refactors including those which are not enabl delimited list of check names to the `-PerrorProneApply` option. ```bash -./gradlew compileJava compileTestJava -PerrorProneApply=PreferAssertj +./gradlew compileJava compileTestJava -PerrorProneApply=ThrowSpecificity ``` ## com.palantir.baseline-checkstyle diff --git a/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/AssertjPrimitiveComparison.java b/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/AssertjPrimitiveComparison.java deleted file mode 100644 index b93098385..000000000 --- a/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/AssertjPrimitiveComparison.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.errorprone; - -import com.google.auto.service.AutoService; -import com.google.errorprone.BugPattern; -import com.google.errorprone.VisitorState; -import com.google.errorprone.bugpatterns.BugChecker; -import com.google.errorprone.fixes.SuggestedFix; -import com.google.errorprone.matchers.Description; -import com.google.errorprone.matchers.Matcher; -import com.google.errorprone.matchers.Matchers; -import com.google.errorprone.matchers.method.MethodMatchers; -import com.google.errorprone.util.ASTHelpers; -import com.sun.source.tree.BinaryTree; -import com.sun.source.tree.ExpressionTree; -import com.sun.source.tree.MemberSelectTree; -import com.sun.source.tree.MethodInvocationTree; -import com.sun.source.tree.Tree; -import com.sun.tools.javac.code.Symtab; -import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.code.Types; -import java.util.Optional; - -@AutoService(BugChecker.class) -@BugPattern( - name = "AssertjPrimitiveComparison", - link = "https://github.com/palantir/gradle-baseline#baseline-error-prone-checks", - linkType = BugPattern.LinkType.CUSTOM, - providesFix = BugPattern.ProvidesFix.REQUIRES_HUMAN_ATTENTION, - severity = BugPattern.SeverityLevel.SUGGESTION, - summary = "Prefer using AssertJ fluent comparisons over logic in an assertThat statement for better " - + "failure output. assertThat(a == b).isTrue() failures report 'expected true' where " - + "assertThat(a).isEqualTo(b) provides the expected and actual values.") -public final class AssertjPrimitiveComparison extends BugChecker implements BugChecker.MethodInvocationTreeMatcher { - - private static final Matcher IS_TRUE = MethodMatchers.instanceMethod() - .onDescendantOf("org.assertj.core.api.Assert") - .named("isTrue") - .withParameters(); - - private static final Matcher IS_FALSE = MethodMatchers.instanceMethod() - .onDescendantOf("org.assertj.core.api.Assert") - .named("isFalse") - .withParameters(); - - private static final Matcher BOOLEAN_ASSERT = Matchers.anyOf(IS_TRUE, IS_FALSE); - - private final AssertjSingleAssertMatcher matcher = AssertjSingleAssertMatcher.of(this::match); - - @Override - public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { - if (BOOLEAN_ASSERT.matches(tree, state)) { - return matcher.matches(tree, state); - } - return Description.NO_MATCH; - } - - private Description match(AssertjSingleAssertMatcher.SingleAssertMatch match, VisitorState state) { - boolean negated = IS_FALSE.matches(match.getCheck(), state); - if (!negated && !IS_TRUE.matches(match.getCheck(), state)) { - return Description.NO_MATCH; - } - ExpressionTree target = match.getAssertThat().getArguments().get(0); - if (!(target instanceof BinaryTree)) { - return Description.NO_MATCH; - } - BinaryTree binaryTree = (BinaryTree) target; - Optional maybeTarget = getPromotionType(binaryTree.getLeftOperand(), binaryTree.getRightOperand(), state); - if (!maybeTarget.isPresent()) { - return Description.NO_MATCH; - } - Type targetType = maybeTarget.get(); - Optional comparison = negated - ? negate(binaryTree.getKind()).flatMap(AssertjPrimitiveComparison::getAssertionName) - : getAssertionName(binaryTree.getKind()); - if (!comparison.isPresent()) { - return Description.NO_MATCH; - } - ExpressionTree expected = binaryTree.getRightOperand(); - ExpressionTree actual = binaryTree.getLeftOperand(); - SuggestedFix fix = SuggestedFix.builder() - .replace( - state.getEndPosition(((MemberSelectTree) match.getCheck().getMethodSelect()).getExpression()), - state.getEndPosition(match.getCheck()), - String.format(".%s(%s)", comparison.get(), - getExpressionSource(expected, targetType, state, false))) - .replace(target, getExpressionSource(actual, targetType, state, true)) - .build(); - return buildDescription(match.getAssertThat()) - .addFix(fix) - .build(); - } - - private static String getExpressionSource( - ExpressionTree expression, - Type targetType, - VisitorState state, - // True if an exact type match is required, otherwise assignment compatibility is allowed. - boolean strict) { - String source = state.getSourceForNode(expression); - Types types = state.getTypes(); - Type resultType = types.unboxedTypeOrType(ASTHelpers.getType(expression)); - if (strict ? types.isSameType(resultType, targetType) : types.isAssignable(resultType, targetType)) { - return source; - } - String cast = '(' + MoreSuggestedFixes.prettyType(state, null, targetType) + ") "; - if (ASTHelpers.requiresParentheses(expression, state)) { - return cast + '(' + source + ')'; - } - return cast + source; - } - - /** - * Returns the promotion type used to compare the results of the first and second args based on - * jls-5.6.2. - */ - private static Optional getPromotionType( - ExpressionTree firstArg, - ExpressionTree secondArg, - VisitorState state) { - Types types = state.getTypes(); - // Handle unboxing per JLS 5.6.2 item 1. - Type firstType = types.unboxedTypeOrType(ASTHelpers.getType(firstArg)); - Type secondType = types.unboxedTypeOrType(ASTHelpers.getType(secondArg)); - if (!firstType.isPrimitive() || !secondType.isPrimitive()) { - return Optional.empty(); - } - if (types.isSameType(firstType, secondType)) { - return Optional.of(firstType); - } - // Handle widening per JLS 5.6.2 item 2. - Symtab symtab = state.getSymtab(); - // If either operand is of type double, the other is converted to double. - if (types.isSameType(symtab.doubleType, firstType) || types.isSameType(symtab.doubleType, secondType)) { - return Optional.of(symtab.doubleType); - } - // Otherwise, if either operand is of type float, the other is converted to float. - if (types.isSameType(symtab.floatType, firstType) || types.isSameType(symtab.floatType, secondType)) { - return Optional.of(symtab.floatType); - } - // Otherwise, if either operand is of type long, the other is converted to long. - if (types.isSameType(symtab.longType, firstType) || types.isSameType(symtab.longType, secondType)) { - return Optional.of(symtab.longType); - } - // Otherwise, both operands are converted to type int. - return Optional.of(symtab.intType); - } - - @SuppressWarnings("SwitchStatementDefaultCase") - private static Optional getAssertionName(Tree.Kind binaryExpression) { - switch (binaryExpression) { - case EQUAL_TO: - return Optional.of("isEqualTo"); - case NOT_EQUAL_TO: - return Optional.of("isNotEqualTo"); - case LESS_THAN: - return Optional.of("isLessThan"); - case LESS_THAN_EQUAL: - return Optional.of("isLessThanOrEqualTo"); - case GREATER_THAN: - return Optional.of("isGreaterThan"); - case GREATER_THAN_EQUAL: - return Optional.of("isGreaterThanOrEqualTo"); - default: - return Optional.empty(); - } - } - - @SuppressWarnings("SwitchStatementDefaultCase") - private static Optional negate(Tree.Kind binaryExpression) { - switch (binaryExpression) { - case EQUAL_TO: - return Optional.of(Tree.Kind.NOT_EQUAL_TO); - case NOT_EQUAL_TO: - return Optional.of(Tree.Kind.EQUAL_TO); - case LESS_THAN: - return Optional.of(Tree.Kind.GREATER_THAN_EQUAL); - case LESS_THAN_EQUAL: - return Optional.of(Tree.Kind.GREATER_THAN); - case GREATER_THAN: - return Optional.of(Tree.Kind.LESS_THAN_EQUAL); - case GREATER_THAN_EQUAL: - return Optional.of(Tree.Kind.LESS_THAN); - default: - return Optional.empty(); - } - } -} diff --git a/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/AssertjSingleAssertMatcher.java b/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/AssertjSingleAssertMatcher.java deleted file mode 100644 index 3094822be..000000000 --- a/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/AssertjSingleAssertMatcher.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.errorprone; - -import com.google.errorprone.VisitorState; -import com.google.errorprone.matchers.Description; -import com.google.errorprone.matchers.Matcher; -import com.google.errorprone.matchers.Matchers; -import com.google.errorprone.matchers.method.MethodMatchers; -import com.google.errorprone.util.ASTHelpers; -import com.sun.source.tree.ExpressionTree; -import com.sun.source.tree.LambdaExpressionTree; -import com.sun.source.tree.MemberSelectTree; -import com.sun.source.tree.MethodInvocationTree; -import com.sun.source.tree.Tree; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.function.BiFunction; -import javax.lang.model.type.TypeKind; - - -final class AssertjSingleAssertMatcher { - - private static final Matcher ASSERT_THAT = MethodMatchers.staticMethod() - .onClass("org.assertj.core.api.Assertions") - .named("assertThat"); - - private static final Matcher ASSERTION = MethodMatchers.instanceMethod() - .onDescendantOf("org.assertj.core.api.Assert") - .withAnyName(); - - // Matches metadata methods which only impact messages. - private static final Matcher METADATA_METHOD = Matchers.anyOf( - MethodMatchers.instanceMethod() - .onDescendantOf("org.assertj.core.api.Descriptable") - .namedAnyOf("as", "describedAs"), - MethodMatchers.instanceMethod() - .onDescendantOf("org.assertj.core.api.Assert") - .namedAnyOf("withRepresentation", "withThreadDumpOnError"), - MethodMatchers.instanceMethod() - .onDescendantOf("org.assertj.core.api.AbstractAssert") - .namedAnyOf("overridingErrorMessage", "withFailMessage")); - - private static final Matcher SINGLE_STATEMENT = Matchers.parentNode(Matchers.anyOf( - Matchers.kindIs(Tree.Kind.EXPRESSION_STATEMENT), - // lambda returning void - (tree, state) -> tree instanceof LambdaExpressionTree - && state.getTypes().findDescriptorType(ASTHelpers.getType(tree)) - .getReturnType().getKind() == TypeKind.VOID)); - - private final BiFunction function; - - static AssertjSingleAssertMatcher of(BiFunction function) { - return new AssertjSingleAssertMatcher(function); - } - - private AssertjSingleAssertMatcher(BiFunction function) { - this.function = function; - } - - public Description matches(ExpressionTree tree, VisitorState state) { - // Only match full statements, otherwise dangling statements may expect the wrong type. - if (!SINGLE_STATEMENT.matches(tree, state)) { - return Description.NO_MATCH; - } - return matchAssertj(tree, state) - .flatMap(list -> list.size() == 2 - ? Optional.of(new SingleAssertMatch(list.get(0), list.get(1))) - : Optional.empty()) - .map(result -> function.apply(result, state)) - .orElse(Description.NO_MATCH); - } - - private static Optional> matchAssertj( - ExpressionTree expressionTree, VisitorState state) { - if (expressionTree == null) { - return Optional.empty(); - } - if (expressionTree instanceof MemberSelectTree) { - return matchAssertj(((MemberSelectTree) expressionTree).getExpression(), state); - } - if (expressionTree instanceof MethodInvocationTree) { - MethodInvocationTree methodInvocationTree = (MethodInvocationTree) expressionTree; - if (ASSERT_THAT.matches(methodInvocationTree, state) - && methodInvocationTree.getArguments().size() == 1) { - List results = new ArrayList<>(); - results.add(methodInvocationTree); - return Optional.of(results); - } else if (METADATA_METHOD.matches(methodInvocationTree, state)) { - return matchAssertj(methodInvocationTree.getMethodSelect(), state); - } else if (ASSERTION.matches(methodInvocationTree, state)) { - Optional> result = - matchAssertj(methodInvocationTree.getMethodSelect(), state); - result.ifPresent(list -> list.add(methodInvocationTree)); - return result; - } - } - return Optional.empty(); - } - - static final class SingleAssertMatch { - private final MethodInvocationTree assertThat; - private final MethodInvocationTree check; - - SingleAssertMatch(MethodInvocationTree assertThat, MethodInvocationTree check) { - this.assertThat = assertThat; - this.check = check; - } - - MethodInvocationTree getAssertThat() { - return assertThat; - } - - MethodInvocationTree getCheck() { - return check; - } - } -} diff --git a/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/PreferAssertj.java b/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/PreferAssertj.java deleted file mode 100644 index 65110a6fe..000000000 --- a/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/PreferAssertj.java +++ /dev/null @@ -1,804 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.errorprone; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import com.google.auto.service.AutoService; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.errorprone.BugPattern; -import com.google.errorprone.VisitorState; -import com.google.errorprone.bugpatterns.BugChecker; -import com.google.errorprone.fixes.SuggestedFix; -import com.google.errorprone.matchers.Description; -import com.google.errorprone.matchers.Matcher; -import com.google.errorprone.matchers.Matchers; -import com.google.errorprone.matchers.method.MethodMatchers; -import com.google.errorprone.predicates.TypePredicate; -import com.google.errorprone.predicates.TypePredicates; -import com.google.errorprone.util.ASTHelpers; -import com.sun.source.tree.AssertTree; -import com.sun.source.tree.ExpressionTree; -import com.sun.source.tree.ImportTree; -import com.sun.source.tree.MemberSelectTree; -import com.sun.source.tree.MethodInvocationTree; -import com.sun.source.tree.Tree; -import com.sun.source.util.SimpleTreeVisitor; -import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Type; -import java.util.List; -import java.util.Optional; -import java.util.function.BiConsumer; -import java.util.stream.Collectors; -import javax.annotation.Nullable; -import javax.lang.model.type.TypeKind; - -/** - * {@link PreferAssertj} provides an automated path from legacy test libraries to AssertJ. Our goal is to migrate - * existing assertions to AssertJ without losing any information. It's an explicit non-goal to take advantage - * of better assertions provided by AssertJ, because those should be implemented in such a way to improve poor - * uses of AssertJ as well, which may run after the suggested fixes provided by this checker. - */ -@AutoService(BugChecker.class) -@BugPattern( - name = "PreferAssertj", - link = "https://github.com/palantir/gradle-baseline#baseline-error-prone-checks", - linkType = BugPattern.LinkType.CUSTOM, - providesFix = BugPattern.ProvidesFix.REQUIRES_HUMAN_ATTENTION, - severity = BugPattern.SeverityLevel.SUGGESTION, - summary = "Prefer AssertJ fluent assertions") -public final class PreferAssertj - extends BugChecker implements BugChecker.AssertTreeMatcher, BugChecker.MethodInvocationTreeMatcher { - - private static final ImmutableSet LEGACY_ASSERT_CLASSES = ImmutableSet.of( - "org.hamcrest.MatcherAssert", - "org.junit.Assert", - "junit.framework.TestCase", - "junit.framework.Assert"); - - // Must match everything otherwise matched by this check, used to avoid - // additional checks for each method invocation. - private static final Matcher FAST_CHECK = MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES); - - private static final Matcher ASSERT_TRUE = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertTrue") - .withParameters(boolean.class.getName()); - - private static final Matcher ASSERT_TRUE_DESCRIPTION = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .namedAnyOf( - "assertTrue", - // org.hamcrest.MatcherAssert.assertThat(String,boolean) is an assertTrue - "assertThat") - .withParameters(String.class.getName(), boolean.class.getName()); - - private static final Matcher ASSERT_FALSE = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertFalse") - .withParameters(boolean.class.getName()); - - private static final Matcher ASSERT_FALSE_DESCRIPTION = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertFalse") - .withParameters(String.class.getName(), boolean.class.getName()); - - private static final Matcher ASSERT_NULL = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertNull") - .withParameters(Object.class.getName()); - - private static final Matcher ASSERT_NULL_DESCRIPTION = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertNull") - .withParameters(String.class.getName(), Object.class.getName()); - - private static final Matcher ASSERT_NOT_NULL = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertNotNull") - .withParameters(Object.class.getName()); - - private static final Matcher ASSERT_NOT_NULL_DESCRIPTION = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertNotNull") - .withParameters(String.class.getName(), Object.class.getName()); - - private static final Matcher ASSERT_SAME = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertSame") - .withParameters(Object.class.getName(), Object.class.getName()); - - private static final Matcher ASSERT_SAME_DESCRIPTION = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertSame") - .withParameters(String.class.getName(), Object.class.getName(), Object.class.getName()); - - private static final Matcher ASSERT_NOT_SAME = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertNotSame") - .withParameters(Object.class.getName(), Object.class.getName()); - - private static final Matcher ASSERT_NOT_SAME_DESCRIPTION = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertNotSame") - .withParameters(String.class.getName(), Object.class.getName(), Object.class.getName()); - - private static final Matcher FAIL = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("fail") - .withParameters(); - - private static final Matcher FAIL_DESCRIPTION = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("fail") - .withParameters(String.class.getName()); - - private static final Matcher ASSERT_EQUALS_FLOATING = Matchers.anyOf( - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertEquals") - .withParameters("double", "double", "double"), - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertEquals") - .withParameters("float", "float", "float")); - - private static final Matcher ASSERT_EQUALS_FLOATING_DESCRIPTION = Matchers.anyOf( - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertEquals") - .withParameters(String.class.getName(), "double", "double", "double"), - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertEquals") - .withParameters(String.class.getName(), "float", "float", "float")); - - private static final Matcher ASSERT_NOT_EQUALS_FLOATING = Matchers.anyOf( - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertNotEquals") - .withParameters("double", "double", "double"), - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertNotEquals") - .withParameters("float", "float", "float")); - - private static final Matcher ASSERT_NOT_EQUALS_FLOATING_DESCRIPTION = Matchers.anyOf( - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertNotEquals") - .withParameters(String.class.getName(), "double", "double", "double"), - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertNotEquals") - .withParameters(String.class.getName(), "float", "float", "float")); - - private static final Matcher ASSERT_THAT = MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertThat") - .withParameters(Object.class.getName(), "org.hamcrest.Matcher"); - - private static final Matcher ASSERT_THAT_DESCRIPTION = MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertThat") - .withParameters(String.class.getName(), Object.class.getName(), "org.hamcrest.Matcher"); - - // Does not match specific patterns, this handles all overloads of both assertEquals and assertArrayEquals. - // Order is important, more specific (e.g. floating point) checks must execute first. - private static final Matcher ASSERT_EQUALS_CATCHALL = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .namedAnyOf("assertEquals", "assertArrayEquals"); - - private static final Matcher ASSERT_ARRAY_EQUALS_CATCHALL = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - .named("assertArrayEquals"); - - private static final Matcher ASSERT_NOT_EQUALS_CATCHALL = - MethodMatchers.staticMethod() - .onClassAny(LEGACY_ASSERT_CLASSES) - // There is no Assert.assertArrayNotEquals - .named("assertNotEquals"); - - @Override - @SuppressWarnings({"CyclomaticComplexity", "MethodLength"}) - public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { - // We check a lot of methods, the fast check allows us to quickly rule out most invocations - // without individually checking each of the more specific patterns. - if (!FAST_CHECK.matches(tree, state)) { - return Description.NO_MATCH; - } - if (ASSERT_TRUE.matches(tree, state)) { - return withAssertThat(tree, state, 0, (assertThat, fix) -> fix.replace(tree, assertThat + ".isTrue()")); - } - if (ASSERT_TRUE_DESCRIPTION.matches(tree, state)) { - return withAssertThat(tree, state, 1, (assertThat, fix) -> - fix.replace(tree, assertThat + ".describedAs(" + argSource(tree, state, 0) + ").isTrue()")); - } - if (ASSERT_FALSE.matches(tree, state)) { - return withAssertThat(tree, state, 0, (assertThat, fix) -> fix.replace(tree, assertThat + ".isFalse()")); - } - if (ASSERT_FALSE_DESCRIPTION.matches(tree, state)) { - return withAssertThat(tree, state, 1, (assertThat, fix) -> - fix.replace(tree, assertThat + ".describedAs(" + argSource(tree, state, 0) + ").isFalse()")); - } - if (ASSERT_NULL.matches(tree, state)) { - return withAssertThat(tree, state, 0, (assertThat, fix) -> fix.replace(tree, assertThat + ".isNull()")); - } - if (ASSERT_NULL_DESCRIPTION.matches(tree, state)) { - return withAssertThat(tree, state, 1, (assertThat, fix) -> - fix.replace(tree, assertThat + ".describedAs(" + argSource(tree, state, 0) + ").isNull()")); - } - if (ASSERT_NOT_NULL.matches(tree, state)) { - return withAssertThat(tree, state, 0, (assertThat, fix) -> fix.replace(tree, assertThat + ".isNotNull()")); - } - if (ASSERT_NOT_NULL_DESCRIPTION.matches(tree, state)) { - return withAssertThat(tree, state, 1, (assertThat, fix) -> - fix.replace(tree, assertThat + ".describedAs(" + argSource(tree, state, 0) + ").isNotNull()")); - } - if (ASSERT_SAME.matches(tree, state)) { - return withAssertThat(tree, state, 1, (assertThat, fix) -> - fix.replace(tree, assertThat + ".isSameAs(" + argSource(tree, state, 0) + ")")); - } - if (ASSERT_SAME_DESCRIPTION.matches(tree, state)) { - return withAssertThat(tree, state, 2, (assertThat, fix) -> - fix.replace(tree, assertThat - + ".describedAs(" + argSource(tree, state, 0) + ").isSameAs(" - + argSource(tree, state, 1) + ")")); - } - if (ASSERT_NOT_SAME.matches(tree, state)) { - return withAssertThat(tree, state, 1, (assertThat, fix) -> - fix.replace(tree, assertThat + ".isNotSameAs(" + argSource(tree, state, 0) + ")")); - } - if (ASSERT_NOT_SAME_DESCRIPTION.matches(tree, state)) { - return withAssertThat(tree, state, 2, (assertThat, fix) -> - fix.replace(tree, assertThat - + ".describedAs(" + argSource(tree, state, 0) + ").isNotSameAs(" - + argSource(tree, state, 1) + ")")); - } - if (FAIL_DESCRIPTION.matches(tree, state) || FAIL.matches(tree, state)) { - return buildDescription(tree) - .addFix(SuggestedFix.builder() - .removeStaticImport("org.junit.Assert.fail") - .addStaticImport("org.assertj.core.api.Assertions.fail") - .replace(tree, "fail(" + (tree.getArguments().isEmpty() - ? "\"fail\"" - : argSource(tree, state, 0)) + ")") - .build()) - .build(); - - } - if (ASSERT_EQUALS_FLOATING.matches(tree, state)) { - return withAssertThat(tree, state, 1, (assertThat, fix) -> fix - .addStaticImport("org.assertj.core.api.Assertions.within") - .replace(tree, String.format("%s%s", - assertThat, - isConstantZero(tree.getArguments().get(2)) - ? String.format(".isEqualTo(%s)", argSource(tree, state, 0)) - : String.format(".isCloseTo(%s, within(%s))", - argSource(tree, state, 0), argSource(tree, state, 2))))); - } - if (ASSERT_EQUALS_FLOATING_DESCRIPTION.matches(tree, state)) { - return withAssertThat(tree, state, 2, (assertThat, fix) -> fix - .addStaticImport("org.assertj.core.api.Assertions.within") - .replace(tree, String.format("%s.describedAs(%s)%s", - assertThat, - argSource(tree, state, 0), - isConstantZero(tree.getArguments().get(3)) - ? String.format(".isEqualTo(%s)", argSource(tree, state, 1)) - : String.format(".isCloseTo(%s, within(%s))", - argSource(tree, state, 1), argSource(tree, state, 3))))); - } - if (ASSERT_NOT_EQUALS_FLOATING.matches(tree, state)) { - return withAssertThat(tree, state, 1, (assertThat, fix) -> fix - .addStaticImport("org.assertj.core.api.Assertions.within") - .replace(tree, String.format("%s%s", - assertThat, - isConstantZero(tree.getArguments().get(2)) - ? String.format(".isNotEqualTo(%s)", argSource(tree, state, 0)) - : String.format(".isNotCloseTo(%s, within(%s))", - argSource(tree, state, 0), argSource(tree, state, 2))))); - } - if (ASSERT_NOT_EQUALS_FLOATING_DESCRIPTION.matches(tree, state)) { - return withAssertThat(tree, state, 2, (assertThat, fix) -> fix - .addStaticImport("org.assertj.core.api.Assertions.within") - .replace(tree, String.format("%s.describedAs(%s)%s", - assertThat, - argSource(tree, state, 0), - isConstantZero(tree.getArguments().get(3)) - ? String.format(".isNotEqualTo(%s)", argSource(tree, state, 1)) - : String.format(".isNotCloseTo(%s, within(%s))", - argSource(tree, state, 1), argSource(tree, state, 3))))); - } - if (ASSERT_THAT.matches(tree, state)) { - Optional replacement = tree.getArguments().get(1) - .accept(HamcrestVisitor.INSTANCE, state); - return withAssertThat(tree, state, 0, (assertThat, fix) -> - fix.replace(tree, assertThat - + replacement.orElseGet(() -> - ".is(new " - + MoreSuggestedFixes.qualifyType(state, fix, "org.assertj.core.api.HamcrestCondition") - + "<>(" - + argSource(tree, state, 1) + "))"))); - } - if (ASSERT_THAT_DESCRIPTION.matches(tree, state)) { - Optional replacement = tree.getArguments().get(2) - .accept(HamcrestVisitor.INSTANCE, state); - return withAssertThat(tree, state, 1, (assertThat, fix) -> - fix.replace(tree, assertThat - + ".describedAs(" + argSource(tree, state, 0) + ")" - + replacement.orElseGet(() -> ".is(new " - + MoreSuggestedFixes.qualifyType(state, fix, "org.assertj.core.api.HamcrestCondition") - + "<>(" + argSource(tree, state, 2) + "))"))); - } - if (ASSERT_EQUALS_CATCHALL.matches(tree, state)) { - int parameters = tree.getArguments().size(); - if (parameters == 2) { - return withAssertThat(tree, state, 1, (assertThat, fix) -> - fix.replace(tree, assertThat - + ".isEqualTo(" + argSource(tree, state, 0) + ")")); - } else if (parameters == 3 && ASTHelpers.isSameType( - getParameterType(tree, 0), - state.getTypeFromString(String.class.getName()), - state)) { - return withAssertThat(tree, state, 2, (assertThat, fix) -> - fix.replace(tree, assertThat - + ".describedAs(" + argSource(tree, state, 0) + ").isEqualTo(" - + argSource(tree, state, 1) + ")")); - } else if (parameters == 3 && isFloatingPointArrayEqualsWithZeroDelta(tree, state)) { - return withAssertThat(tree, state, 1, (assertThat, fix) -> - fix.replace(tree, assertThat - + ".isEqualTo(" + argSource(tree, state, 0) + ")")); - } else if (parameters == 4 && isFloatingPointArrayEqualsWithZeroDelta(tree, state)) { - return withAssertThat(tree, state, 2, (assertThat, fix) -> - fix.replace(tree, assertThat - + ".describedAs(" + argSource(tree, state, 0) + ").isEqualTo(" - + argSource(tree, state, 1) + ")")); - } else { - // Does not fix assertArrayEquals(double[], double[], double) - // or assertArrayEquals(float[], float[], float) - return describeMatch(tree); - } - } - if (ASSERT_NOT_EQUALS_CATCHALL.matches(tree, state)) { - int parameters = tree.getArguments().size(); - if (parameters == 2) { - return withAssertThat(tree, state, 1, (assertThat, fix) -> - fix.replace(tree, assertThat - + ".isNotEqualTo(" + argSource(tree, state, 0) + ")")); - } else if (parameters == 3 && ASTHelpers.isSameType( - ASTHelpers.getType(tree.getArguments().get(0)), - state.getTypeFromString(String.class.getName()), - state)) { - return withAssertThat(tree, state, 2, (assertThat, fix) -> - fix.replace(tree, assertThat - + ".describedAs(" + argSource(tree, state, 0) + ").isNotEqualTo(" - + argSource(tree, state, 1) + ")")); - } else { - // I'm not aware of anything that should hit this. - return describeMatch(tree); - } - } - return Description.NO_MATCH; - } - - @Override - public Description matchAssert(AssertTree tree, VisitorState state) { - if (!TestCheckUtils.isTestCode(state)) { - return Description.NO_MATCH; - } - SuggestedFix.Builder fix = SuggestedFix.builder(); - return buildDescription(tree) - .setMessage("Prefer AssertJ fluent assertions instead of the 'assert' keyword in tests. " - + "Assertions can be disabled which is never expected in tests.") - .addFix(fix.replace(tree, String.format("%s(%s)%s.isTrue();", - qualifyAssertThat(fix, state), - state.getSourceForNode(tree.getCondition()), - getAssertDescription(tree.getDetail(), state))) - .build()) - .build(); - } - - /** Returns the describedAs invocation if a detail is present, otherwise an empty string. */ - private static String getAssertDescription(@Nullable ExpressionTree detail, VisitorState state) { - if (detail == null) { - return ""; - } - String detailSource = state.getSourceForNode(detail); - if (Strings.isNullOrEmpty(detailSource)) { - return ""; - } - if (state.getTypes().isAssignable( - ASTHelpers.getResultType(detail), state.getTypeFromString(String.class.getName()))) { - return ".describedAs(" + detailSource + ')'; - } - // Lazily allow the value to be evaluated on failures - return ".describedAs(\"%s\", " + detailSource + ')'; - } - - /** - * Provides a qualified 'assertThat' name. We attempt to use a static import if possible, otherwise fall back - * to as qualified as possible. - */ - private Description withAssertThat( - MethodInvocationTree tree, - VisitorState state, - int actualIndex, - BiConsumer assertThat) { - SuggestedFix.Builder fix = SuggestedFix.builder(); - String qualified = qualifyAssertThat(fix, state); - String actualArgumentString = argSource(tree, state, actualIndex); - ExpressionTree actualArgument = tree.getArguments().get(actualIndex); - if (isIterableMap(actualArgument, state)) { - String qualifiedMap = MoreSuggestedFixes.prettyType( - state, - fix, - state.getTypes().asSuper( - ASTHelpers.getType(actualArgument), - state.getSymbolFromString("java.util.Map"))); - actualArgumentString = String.format("(%s) %s", qualifiedMap, actualArgumentString); - } - assertThat.accept(qualified + '(' + actualArgumentString + ')', fix); - return buildDescription(tree) - .addFix(fix.build()) - .build(); - } - - private static String qualifyAssertThat(SuggestedFix.Builder fix, VisitorState state) { - if (useStaticAssertjImport(state)) { - fix.removeStaticImport("org.junit.Assert.assertThat") - .removeStaticImport("org.hamcrest.MatcherAssert.assertThat") - .addStaticImport("org.assertj.core.api.Assertions.assertThat"); - return "assertThat"; - } else { - return MoreSuggestedFixes.qualifyType(state, fix, "org.assertj.core.api.Assertions.assertThat"); - } - } - - private static boolean isIterableMap(ExpressionTree value, VisitorState state) { - return isSubtype(value, "java.lang.Iterable", state) - && isSubtype(value, "java.util.Map", state); - } - - private static boolean isSubtype(ExpressionTree value, String castableTo, VisitorState state) { - return ASTHelpers.isSubtype( - ASTHelpers.getType(value), - state.getTypeFromString(castableTo), - state); - } - - private static boolean useStaticAssertjImport(VisitorState state) { - for (ImportTree importTree : state.getPath().getCompilationUnit().getImports()) { - if (!importTree.isStatic()) { - continue; - } - Tree identifier = importTree.getQualifiedIdentifier(); - if (!(identifier instanceof MemberSelectTree)) { - continue; - } - MemberSelectTree memberSelectTree = (MemberSelectTree) identifier; - if (!memberSelectTree.getIdentifier().contentEquals("assertThat")) { - continue; - } - // if an 'assertThat' is already imported, and it's neither assertj nor org.junit.assert, use - // the qualified name. - return isExpressionSameType(state, memberSelectTree, "org.assertj.core.api.Assertions") - // if an 'assertThat' is already imported, and it's from (known) legacy Assert, - // we remove the static import and add assertj. - || isExpressionSameType(state, memberSelectTree, "org.junit.Assert") - || isExpressionSameType(state, memberSelectTree, "org.hamcrest.MatcherAssert"); - } - // If we did not encounter an assertThat static import, we can import and use it. - return true; - } - - private static boolean isConstantZero(Tree tree) { - Object constantValue = ASTHelpers.constValue(tree); - return constantValue instanceof Number && ((Number) constantValue).doubleValue() == 0D; - } - - private static boolean isExpressionSameType(VisitorState state, MemberSelectTree memberSelectTree, String type) { - return ASTHelpers.isSameType( - ASTHelpers.getType(memberSelectTree.getExpression()), - state.getTypeFromString(type), - state); - } - - private static String argSource( - MethodInvocationTree invocation, - VisitorState state, - int index) { - checkArgument(index >= 0, "Index must be non-negative"); - List arguments = checkNotNull(invocation, "MethodInvocationTree").getArguments(); - checkArgument(index < arguments.size(), "Index is out of bounds"); - ExpressionTree argument = arguments.get(index); - Symbol.VarSymbol symbol = checkNotNull(ASTHelpers.getSymbol(invocation), "symbol").getParameters().get(index); - String argumentSource = checkNotNull(state.getSourceForNode(argument), "Failed to find argument source"); - if (symbol.type.isPrimitive() - // Limit to only float and double because assertEquals for ints uses assertEquals(long, long), - // we don't want to cast everything to long unnecessarily. - && (symbol.type.getKind() == TypeKind.FLOAT || symbol.type.getKind() == TypeKind.DOUBLE) - && !ASTHelpers.isSameType(symbol.type, ASTHelpers.getType(argument), state)) { - return String.format("(%s) %s", symbol.type.toString(), argumentSource); - } - return argumentSource; - } - - private static final class HamcrestVisitor extends SimpleTreeVisitor, VisitorState> { - private static final HamcrestVisitor INSTANCE = new HamcrestVisitor(false); - - private static final HamcrestVisitor NEGATED = new HamcrestVisitor(true); - - private static final TypePredicate MATCHERS = new TypePredicate() { - - private final TypePredicate matcherPredicate = TypePredicates.isDescendantOf("org.hamcrest.Matcher"); - private final TypePredicate[] predicates = new TypePredicate[] { - TypePredicates.isExactType("org.hamcrest.Matchers"), - TypePredicates.isExactType("org.hamcrest.CoreMatchers"), - // Allows uses of direct imports to be migrated as well, - // e.g. 'org.hamcrest.core.Is.is'. - (TypePredicate) (type, state) -> matcherPredicate.apply(type, state) - // Limit to Hamcrest packages to avoid interaction with non-standard library code - && type.toString().startsWith("org.hamcrest.") - }; - - @Override - public boolean apply(Type type, VisitorState state) { - for (TypePredicate predicate : predicates) { - if (predicate.apply(type, state)) { - return true; - } - } - return false; - } - }; - - private static final Matcher IS_MATCHER = MethodMatchers.staticMethod() - .onClass(MATCHERS) - .named("is") - .withParameters("org.hamcrest.Matcher"); - - private static final Matcher NOT_MATCHER = MethodMatchers.staticMethod() - .onClass(MATCHERS) - .named("not") - .withParameters("org.hamcrest.Matcher"); - - private static final Matcher EQUALS = MethodMatchers.staticMethod() - .onClass(MATCHERS) - .namedAnyOf("is", "equalTo", "equalToObject") - .withParameters(Object.class.getName()); - - private static final Matcher INSTANCE_OF = MethodMatchers.staticMethod() - .onClass(MATCHERS) - .namedAnyOf("isA", "instanceOf") - .withParameters("java.lang.Class"); - - private static final Matcher NULL = Matchers.anyOf( - MethodMatchers.staticMethod() - .onClass(MATCHERS) - .named("nullValue") - .withParameters(), - MethodMatchers.staticMethod() - .onClass(MATCHERS) - .named("nullValue") - .withParameters("java.lang.Class")); - - private static final Matcher NOT_NULL = Matchers.anyOf( - MethodMatchers.staticMethod() - .onClass(MATCHERS) - .named("notNullValue") - .withParameters(), - MethodMatchers.staticMethod() - .onClass(MATCHERS) - .named("notNullValue") - .withParameters("java.lang.Class")); - - private static final Matcher CONTAINS = Matchers.anyOf( - MethodMatchers.staticMethod() - .onClass(MATCHERS) - .namedAnyOf("hasItem", "hasItemInArray") - .withParameters(Object.class.getName()), - MethodMatchers.staticMethod() - .onClass(MATCHERS) - .named("containsString") - .withParameters(String.class.getName())); - - // Note: cannot match array/vararg arguments - private static final Matcher HAS_ITEMS = MethodMatchers.staticMethod() - .onClass(MATCHERS) - .named("hasItems"); - - private static final Matcher CONTAINS_EXACTLY_ANY_ORDER = MethodMatchers.staticMethod() - .onClass(MATCHERS) - .namedAnyOf("arrayContainingInAnyOrder", "containsInAnyOrder"); - - private static final Matcher CONTAINS_EXACTLY_ORDERED = MethodMatchers.staticMethod() - .onClass(MATCHERS) - .named("contains"); - - private static final Matcher IS_EMPTY = Matchers.anyOf( - MethodMatchers.staticMethod() - .onClass(MATCHERS) - .namedAnyOf("empty", "emptyIterable", "emptyArray", "anEmptyMap") - .withParameters(), - MethodMatchers.staticMethod() - .onClass(MATCHERS) - .namedAnyOf("emptyCollectionOf", "emptyIterableOf") - .withParameters(Class.class.getName())); - - private static final Matcher HAS_SIZE = MethodMatchers.staticMethod() - .onClass(MATCHERS) - .namedAnyOf("hasSize", "aMapWithSize", "arrayWithSize", "iterableWithSize") - .withParameters(int.class.getName()); - - private static final Matcher SAME_INSTANCE = MethodMatchers.staticMethod() - .onClass(MATCHERS) - .namedAnyOf("sameInstance", "theInstance") - .withParameters(Object.class.getName()); - - private static final Matcher STARTS_WITH = MethodMatchers.staticMethod() - .onClass(MATCHERS) - .namedAnyOf("startsWith") - .withParameters(String.class.getName()); - - private static final Matcher ENDS_WITH = MethodMatchers.staticMethod() - .onClass(MATCHERS) - .namedAnyOf("endsWith") - .withParameters(String.class.getName()); - - private final boolean negated; - - private HamcrestVisitor(boolean negated) { - super(Optional.empty()); - this.negated = negated; - } - - @Override - @SuppressWarnings("CyclomaticComplexity") - public Optional visitMethodInvocation(MethodInvocationTree node, VisitorState state) { - // is(Matcher) is for readability, fall through to the next matcher - if (IS_MATCHER.matches(node, state)) { - return node.getArguments().get(0).accept(this, state); - } - if (NOT_MATCHER.matches(node, state)) { - return node.getArguments().get(0).accept(this.negated ? INSTANCE : NEGATED, state); - } - if (EQUALS.matches(node, state)) { - return Optional.of((negated ? ".isNotEqualTo(" : ".isEqualTo(") - + argSource(node, state, 0) + ")"); - } - if (INSTANCE_OF.matches(node, state)) { - return Optional.of((negated ? ".isNotInstanceOf(" : ".isInstanceOf(") - + argSource(node, state, 0) + ")"); - } - if (NULL.matches(node, state)) { - return Optional.of(negated ? ".isNotNull()" : ".isNull()"); - } - if (NOT_NULL.matches(node, state)) { - return Optional.of(negated ? ".isNull()" : ".isNotNull()"); - } - if (CONTAINS.matches(node, state)) { - return Optional.of((negated ? ".doesNotContain(" : ".contains(") + argSource(node, state, 0) + ')'); - } - if (IS_EMPTY.matches(node, state)) { - return Optional.of(negated ? ".isNotEmpty()" : ".isEmpty()"); - } - if (SAME_INSTANCE.matches(node, state)) { - return Optional.of((negated ? ".isNotSameAs(" : ".isSameAs(") + argSource(node, state, 0) + ')'); - } - if (STARTS_WITH.matches(node, state)) { - return Optional.of((negated ? ".doesNotStartWith(" : ".startsWith(") + argSource(node, state, 0) + ')'); - } - if (ENDS_WITH.matches(node, state)) { - return Optional.of((negated ? ".doesNotEndWith(" : ".endsWith(") + argSource(node, state, 0) + ')'); - } - if (HAS_SIZE.matches(node, state)) { - if (negated) { - // No top level method for negated size assertions - return Optional.empty(); - } - - return Optional.of(".hasSize(" + argSource(node, state, 0) + ')'); - } - if (HAS_ITEMS.matches(node, state) && isObjectVarArgs(node, state)) { - if (negated) { - // this negates to 'doesNotContainAll' which doesn't exist. AssertJ doesNotContain - // evaluates as 'does not contain any'. - return Optional.empty(); - } - return Optional.of(".contains(" + node.getArguments().stream() - .map(state::getSourceForNode) - .collect(Collectors.joining(", ")) + ')'); - } - if (CONTAINS_EXACTLY_ANY_ORDER.matches(node, state) && isObjectVarArgs(node, state)) { - if (negated) { - // this negates to 'doesNotContainExactlyInAnyOrder' which doesn't exist. - return Optional.empty(); - } - return Optional.of(".containsExactlyInAnyOrder(" + node.getArguments().stream() - .map(state::getSourceForNode) - .collect(Collectors.joining(", ")) + ')'); - } - if (CONTAINS_EXACTLY_ORDERED.matches(node, state) && isObjectVarArgs(node, state)) { - if (negated) { - // this negates to 'doesNotContainExactly' which doesn't exist. - return Optional.empty(); - } - return Optional.of(".containsExactly(" + node.getArguments().stream() - .map(state::getSourceForNode) - .collect(Collectors.joining(", ")) + ')'); - } - return Optional.empty(); - } - } - - private static boolean isObjectVarArgs(MethodInvocationTree tree, VisitorState state) { - Symbol.MethodSymbol methodSymbol = checkNotNull(ASTHelpers.getSymbol(tree), "symbol"); - if (!methodSymbol.isVarArgs()) { - return false; - } - Symbol.VarSymbol varSymbol = Iterables.getLast(methodSymbol.getParameters()); - checkState(varSymbol.type instanceof Type.ArrayType, "Expected an array as last argument of a vararg method"); - Type.ArrayType arrayType = (Type.ArrayType) varSymbol.type; - return ASTHelpers.isSameType( - arrayType.getComponentType(), - state.getTypeFromString(Object.class.getName()), - state); - } - - private static Type getParameterType(MethodInvocationTree tree, int parameterIndex) { - Symbol.MethodSymbol methodSymbol = checkNotNull(ASTHelpers.getSymbol(tree), "symbol"); - List parameters = methodSymbol.getParameters(); - checkArgument(parameterIndex >= 0, "index must be greater than zero, was %s", parameterIndex); - checkArgument(parameterIndex < parameters.size(), - "index '%s' is out of bounds for collection %s", parameterIndex, parameters); - return methodSymbol.getParameters().get(parameterIndex).type; - } - - private static boolean isFloatingPointArrayEqualsWithZeroDelta(MethodInvocationTree tree, VisitorState state) { - if (!ASSERT_ARRAY_EQUALS_CATCHALL.matches(tree, state)) { - return false; - } - int parameters = tree.getArguments().size(); - Type floatType = state.getTypeFromString("float"); - Type doubleType = state.getTypeFromString("double"); - int deltaParameterIndex = parameters - 1; - return (ASTHelpers.isSameType(getParameterType(tree, deltaParameterIndex), floatType, state) - || ASTHelpers.isSameType(getParameterType(tree, deltaParameterIndex), doubleType, state)) - && isConstantZero(tree.getArguments().get(deltaParameterIndex)); - } -} diff --git a/baseline-error-prone/src/test/java/com/palantir/baseline/errorprone/AssertjPrimitiveComparisonTest.java b/baseline-error-prone/src/test/java/com/palantir/baseline/errorprone/AssertjPrimitiveComparisonTest.java deleted file mode 100644 index b22b0dfc6..000000000 --- a/baseline-error-prone/src/test/java/com/palantir/baseline/errorprone/AssertjPrimitiveComparisonTest.java +++ /dev/null @@ -1,447 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.errorprone; - -import com.google.errorprone.BugCheckerRefactoringTestHelper; -import org.junit.jupiter.api.Test; - -class AssertjPrimitiveComparisonTest { - - @Test - void testComparisons() { - fix() - .addInputLines("Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "class Test {", - " void f() {", - " assertThat(1 == 2).isTrue();", - " assertThat(1 == 2).isFalse();", - " assertThat(1 != 2).as(\"desc\").isTrue();", - " assertThat(1 != 2).describedAs(\"desc\").withThreadDumpOnError().isFalse();", - " assertThat(1 > 2).withRepresentation(null).isTrue();", - " assertThat(1 > 2).withFailMessage(\"fail\").isFalse();", - " assertThat(1 >= 2).overridingErrorMessage(\"fail\").isTrue();", - " assertThat(1 >= 2).isFalse();", - " assertThat(1 < 2).isTrue();", - " assertThat(1 < 2).isFalse();", - " assertThat(1 <= 2).isTrue();", - " assertThat(1 <= 2).isFalse();", - " assertThat(1 > 2L).isTrue();", - " assertThat(1 > 2).isFalse().isEqualTo(2 > 3);", - " Long first = 1L;", - " Long second = 2L;", - " assertThat(first < second).isTrue();", - " assertThat(first < 2L).isTrue();", - " assertThat(1L < 2).isTrue();", - " assertThat(1L + 2f < 2 + 3D).isTrue();", - " assertThat(3D > 1).isTrue();", - " }", - "}") - .addOutputLines("Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "class Test {", - " void f() {", - " assertThat(1).isEqualTo(2);", - " assertThat(1).isNotEqualTo(2);", - " assertThat(1).as(\"desc\").isNotEqualTo(2);", - " assertThat(1).describedAs(\"desc\").withThreadDumpOnError().isEqualTo(2);", - " assertThat(1).withRepresentation(null).isGreaterThan(2);", - " assertThat(1).withFailMessage(\"fail\").isLessThanOrEqualTo(2);", - " assertThat(1).overridingErrorMessage(\"fail\").isGreaterThanOrEqualTo(2);", - " assertThat(1).isLessThan(2);", - " assertThat(1).isLessThan(2);", - " assertThat(1).isGreaterThanOrEqualTo(2);", - " assertThat(1).isLessThanOrEqualTo(2);", - " assertThat(1).isGreaterThan(2);", - " assertThat((long) 1).isGreaterThan(2L);", - " assertThat(1 > 2).isFalse().isEqualTo(2 > 3);", - " Long first = 1L;", - " Long second = 2L;", - " assertThat(first).isLessThan(second);", - " assertThat(first).isLessThan(2L);", - " assertThat(1L).isLessThan(2);", - " assertThat((double) (1L + 2f)).isLessThan(2 + 3D);", - " assertThat(3D).isGreaterThan(1);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void less_than() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b) {", - " assertThat(a < b).isTrue();", - " assertThat(a >= b).isFalse();", - " }", - "}") - .addOutputLines("Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b) {", - " assertThat(a).isLessThan(b);", - " assertThat(a).isLessThan(b);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void less_than_with_description() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b, String desc) {", - " assertThat(a < b).describedAs(desc).isTrue();", - " assertThat(a >= b).describedAs(desc).isFalse();", - " }", - "}") - .addOutputLines("Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b, String desc) {", - " assertThat(a).describedAs(desc).isLessThan(b);", - " assertThat(a).describedAs(desc).isLessThan(b);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void greater_than() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b) {", - " assertThat(a > b).isTrue();", - " assertThat(a <= b).isFalse();", - " }", - "}") - .addOutputLines("Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b) {", - " assertThat(a).isGreaterThan(b);", - " assertThat(a).isGreaterThan(b);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void greater_than_with_description() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b, String desc) {", - " assertThat(a > b).describedAs(desc).isTrue();", - " assertThat(a <= b).describedAs(desc).isFalse();", - " }", - "}") - .addOutputLines("Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b, String desc) {", - " assertThat(a).describedAs(desc).isGreaterThan(b);", - " assertThat(a).describedAs(desc).isGreaterThan(b);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void less_than_or_equal_to() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b) {", - " assertThat(a <= b).isTrue();", - " assertThat(a > b).isFalse();", - " }", - "}") - .addOutputLines("Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b) {", - " assertThat(a).isLessThanOrEqualTo(b);", - " assertThat(a).isLessThanOrEqualTo(b);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void less_than_or_equal_to_with_description() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b, String desc) {", - " assertThat(a <= b).describedAs(desc).isTrue();", - " assertThat(a > b).describedAs(desc).isFalse();", - " }", - "}") - .addOutputLines("Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b, String desc) {", - " assertThat(a).describedAs(desc).isLessThanOrEqualTo(b);", - " assertThat(a).describedAs(desc).isLessThanOrEqualTo(b);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void greater_than_or_equal_to() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b) {", - " assertThat(a >= b).isTrue();", - " assertThat(a < b).isFalse();", - " }", - "}") - .addOutputLines("Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b) {", - " assertThat(a).isGreaterThanOrEqualTo(b);", - " assertThat(a).isGreaterThanOrEqualTo(b);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void greater_than_or_equal_to_with_description() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b, String desc) {", - " assertThat(a >= b).describedAs(desc).isTrue();", - " assertThat(a < b).describedAs(desc).isFalse();", - " }", - "}") - .addOutputLines("Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void test(int a, int b, String desc) {", - " assertThat(a).describedAs(desc).isGreaterThanOrEqualTo(b);", - " assertThat(a).describedAs(desc).isGreaterThanOrEqualTo(b);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void bytes() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(byte a, byte b) { assertThat(a == b).isTrue(); }", - " void g(byte a, byte b) { assertThat(a == b).describedAs(\"desc\").isTrue(); }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(byte a, byte b) { assertThat(a).isEqualTo(b); }", - " void g(byte a, byte b) { assertThat(a).describedAs(\"desc\").isEqualTo(b); }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void shorts() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(short a, short b) { assertThat(a == b).isTrue(); }", - " void g(short a, short b) { assertThat(a == b).describedAs(\"desc\").isTrue(); }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(short a, short b) { assertThat(a).isEqualTo(b); }", - " void g(short a, short b) { assertThat(a).describedAs(\"desc\").isEqualTo(b); }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void ints() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(int a, int b) { assertThat(a == b).isTrue(); }", - " void g(int a, int b) { assertThat(a == b).describedAs(\"desc\").isTrue(); }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(int a, int b) { assertThat(a).isEqualTo(b); }", - " void g(int a, int b) { assertThat(a).describedAs(\"desc\").isEqualTo(b); }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void longs() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(long a, long b) { assertThat(a == b).isTrue(); }", - " void g(long a, long b) { assertThat(a == b).describedAs(\"desc\").isTrue(); }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(long a, long b) { assertThat(a).isEqualTo(b); }", - " void g(long a, long b) { assertThat(a).describedAs(\"desc\").isEqualTo(b); }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void floats() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(float a, float b) { assertThat(a == b).isTrue(); }", - " void g(float a, float b) { assertThat(a == b).describedAs(\"desc\").isTrue(); }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(float a, float b) { assertThat(a).isEqualTo(b); }", - " void g(float a, float b) { assertThat(a).describedAs(\"desc\").isEqualTo(b); }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void doubles() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(double a, double b) { assertThat(a == b).isTrue(); }", - " void g(double a, double b) { assertThat(a == b).describedAs(\"desc\").isTrue(); }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(double a, double b) { assertThat(a).isEqualTo(b); }", - " void g(double a, double b) { assertThat(a).describedAs(\"desc\").isEqualTo(b); }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void chars() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(char a, char b) { assertThat(a == b).isTrue(); }", - " void g(char a, char b) { assertThat(a == b).describedAs(\"desc\").isTrue(); }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(char a, char b) { assertThat(a).isEqualTo(b); }", - " void g(char a, char b) { assertThat(a).describedAs(\"desc\").isEqualTo(b); }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - void booleans() { - fix() - .addInputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(boolean a, boolean b) { assertThat(a == b).isTrue(); }", - " void g(boolean a, boolean b) { assertThat(a == b).describedAs(\"desc\").isTrue(); }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(boolean a, boolean b) { assertThat(a).isEqualTo(b); }", - " void g(boolean a, boolean b) { assertThat(a).describedAs(\"desc\").isEqualTo(b); }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - private RefactoringValidator fix() { - return RefactoringValidator.of(new AssertjPrimitiveComparison(), getClass()); - } -} diff --git a/baseline-error-prone/src/test/java/com/palantir/baseline/errorprone/PreferAssertjTests.java b/baseline-error-prone/src/test/java/com/palantir/baseline/errorprone/PreferAssertjTests.java deleted file mode 100644 index 5d8d07a3c..000000000 --- a/baseline-error-prone/src/test/java/com/palantir/baseline/errorprone/PreferAssertjTests.java +++ /dev/null @@ -1,975 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.errorprone; - -import com.google.errorprone.BugCheckerRefactoringTestHelper; -import com.google.errorprone.CompilationTestHelper; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.parallel.Execution; -import org.junit.jupiter.api.parallel.ExecutionMode; - -@SuppressWarnings("RegexpSinglelineJava") // Testing against assertions that aren't allowed -@Execution(ExecutionMode.CONCURRENT) -public class PreferAssertjTests { - - @Test - public void fix_booleanAsserts() { - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "", - "import org.junit.Assert;", - "class Test {", - " void foo(boolean b) {", - " Assert.assertFalse(b);", - " Assert.assertFalse(\"desc\", b);", - " Assert.assertTrue(b);", - " Assert.assertTrue(\"desc\", b);", - " assertThat(\"desc\", b);", - " assert b;", - " assert b : \"desc\";", - " assert b : 123;", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "", - "import org.junit.Assert;", - "class Test {", - " void foo(boolean b) {", - " assertThat(b).isFalse();", - " assertThat(b).describedAs(\"desc\").isFalse();", - " assertThat(b).isTrue();", - " assertThat(b).describedAs(\"desc\").isTrue();", - " assertThat(b).describedAs(\"desc\").isTrue();", - " assertThat(b).isTrue();", - " assertThat(b).describedAs(\"desc\").isTrue();", - " assertThat(b).describedAs(\"%s\", 123).isTrue();", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fixAssertFalse_existingAssertThat() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertThat;", - "", - "import org.junit.Assert;", - "class Test {", - " void foo(boolean b) {", - " assertThat(true, org.hamcrest.CoreMatchers.equalTo(false));", - " Assert.assertFalse(b);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "", - "import org.junit.Assert;", - "class Test {", - " void foo(boolean b) {", - " assertThat(true).isEqualTo(false);", - " assertThat(b).isFalse();", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertNull() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertNull;", - "import static org.junit.Assert.assertNotNull;", - "class Test {", - " void foo(String s) {", - " assertNull(s);", - " assertNull(\"desc\", s);", - " assertNotNull(s);", - " assertNotNull(\"desc\", s);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.junit.Assert.assertNotNull;", - "import static org.junit.Assert.assertNull;", - "class Test {", - " void foo(String s) {", - " assertThat(s).isNull();", - " assertThat(s).describedAs(\"desc\").isNull();", - " assertThat(s).isNotNull();", - " assertThat(s).describedAs(\"desc\").isNotNull();", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertSame() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertSame;", - "import static org.junit.Assert.assertNotSame;", - "class Test {", - " void foo(String a, String b) {", - " assertSame(a, b);", - " assertSame(\"desc\", a, b);", - " assertNotSame(a, b);", - " assertNotSame(\"desc\", a, b);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.junit.Assert.assertNotSame;", - "import static org.junit.Assert.assertSame;", - "class Test {", - " void foo(String a, String b) {", - " assertThat(b).isSameAs(a);", - " assertThat(b).describedAs(\"desc\").isSameAs(a);", - " assertThat(b).isNotSameAs(a);", - " assertThat(b).describedAs(\"desc\").isNotSameAs(a);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_fail() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.fail;", - "", - "import org.junit.Assert;", - "class Test {", - " void foo() {", - " fail();", - " fail(\"desc\");", - " Assert.fail(\"desc\");", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.fail;", - "", - "import org.junit.Assert;", - "class Test {", - " void foo() {", - " fail(\"fail\");", - " fail(\"desc\");", - " fail(\"desc\");", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertEqualsFloating() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertEquals;", - "import static org.junit.Assert.assertNotEquals;", - "class Test {", - " void foo(float fl, double db) {", - " assertEquals(.1f, fl, .01f);", - " assertEquals(\"desc\", .1f, fl, .01f);", - " assertEquals(.1D, db, .01D);", - " assertEquals(\"desc\", .1D, db, .01D);", - " assertEquals(\"desc\", .1D, db, 0);", - " assertEquals(.1D, db, 0D);", - " assertNotEquals(.1f, fl, .01f);", - " assertNotEquals(\"desc\", .1f, fl, .01f);", - " assertNotEquals(.1D, db, .01D);", - " assertNotEquals(\"desc\", .1D, db, .01D);", - " assertNotEquals(\"desc\", .1D, db, 0.0);", - " assertNotEquals(.1D, db, 0D);", - " assertEquals(1D, db, 1);", - " assertEquals(1, db, 1D);", - " assertEquals(1D, db, 1f);", - " assertNotEquals(\"desc\", 1f, db, 1D);", - " assertEquals(1f, fl, 1);", - " assertNotEquals(1, fl, 1f);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.assertj.core.api.Assertions.within;", - "import static org.junit.Assert.assertEquals;", - "import static org.junit.Assert.assertNotEquals;", - "class Test {", - " void foo(float fl, double db) {", - " assertThat(fl).isCloseTo(.1f, within(.01f));", - " assertThat(fl).describedAs(\"desc\").isCloseTo(.1f, within(.01f));", - " assertThat(db).isCloseTo(.1D, within(.01D));", - " assertThat(db).describedAs(\"desc\").isCloseTo(.1D, within(.01D));", - " assertThat(db).describedAs(\"desc\").isEqualTo(.1D);", - " assertThat(db).isEqualTo(.1D);", - " assertThat(fl).isNotCloseTo(.1f, within(.01f));", - " assertThat(fl).describedAs(\"desc\").isNotCloseTo(.1f, within(.01f));", - " assertThat(db).isNotCloseTo(.1D, within(.01D));", - " assertThat(db).describedAs(\"desc\").isNotCloseTo(.1D, within(.01D));", - " assertThat(db).describedAs(\"desc\").isNotEqualTo(.1D);", - " assertThat(db).isNotEqualTo(.1D);", - " assertThat(db).isCloseTo(1D, within((double) 1));", - " assertThat(db).isCloseTo((double) 1, within(1D));", - " assertThat(db).isCloseTo(1D, within((double) 1f));", - " assertThat(db).describedAs(\"desc\").isNotCloseTo((double) 1f, within(1D));", - " assertThat(fl).isCloseTo(1f, within((float) 1));", - " assertThat(fl).isNotCloseTo((float) 1, within(1f));", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertEqualsInt() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertEquals;", - "class Test {", - " void foo(int value) {", - " assertEquals(1, value);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.junit.Assert.assertEquals;", - "class Test {", - " void foo(int value) {", - " assertThat(value).isEqualTo(1);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertEqualsString() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertEquals;", - "import static org.junit.Assert.assertNotEquals;", - "class Test {", - " void foo(String value) {", - " assertEquals(\"1\", value);", - " assertEquals(\"desc\", \"1\", value);", - " assertNotEquals(\"1\", value);", - " assertNotEquals(\"desc\", \"1\", value);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.junit.Assert.assertEquals;", - "import static org.junit.Assert.assertNotEquals;", - "class Test {", - " void foo(String value) {", - " assertThat(value).isEqualTo(\"1\");", - " assertThat(value).describedAs(\"desc\").isEqualTo(\"1\");", - " assertThat(value).isNotEqualTo(\"1\");", - " assertThat(value).describedAs(\"desc\").isNotEqualTo(\"1\");", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertEqualsString_testcase() { - test() - .addInputLines( - "Test.java", - "import static junit.framework.TestCase.assertEquals;", - "class Test {", - " void foo(String value) {", - " assertEquals(\"1\", value);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static junit.framework.TestCase.assertEquals;", - "import static org.assertj.core.api.Assertions.assertThat;", - "class Test {", - " void foo(String value) {", - " assertThat(value).isEqualTo(\"1\");", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertEqualsString_frameworkAssert() { - test() - .addInputLines( - "Test.java", - "import static junit.framework.Assert.assertEquals;", - "class Test {", - " void foo(String value) {", - " assertEquals(\"1\", value);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static junit.framework.Assert.assertEquals;", - "import static org.assertj.core.api.Assertions.assertThat;", - "class Test {", - " void foo(String value) {", - " assertThat(value).isEqualTo(\"1\");", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertEqualsIntDescription() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertEquals;", - "class Test {", - " void foo(int value) {", - " assertEquals(\"desc\", 1, value);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.junit.Assert.assertEquals;", - "class Test {", - " void foo(int value) {", - " assertThat(value).describedAs(\"desc\").isEqualTo(1);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertArrayEqualsInt() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertArrayEquals;", - "class Test {", - " void foo(int[] value) {", - " assertArrayEquals(new int[] { 1 }, value);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.junit.Assert.assertArrayEquals;", - "class Test {", - " void foo(int[] value) {", - " assertThat(value).isEqualTo(new int[] { 1 });", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertArrayEqualsIntDescription() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertArrayEquals;", - "class Test {", - " void foo(int[] value) {", - " assertArrayEquals(\"desc\", new int[] { 1 }, value);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.junit.Assert.assertArrayEquals;", - "class Test {", - " void foo(int[] value) {", - " assertThat(value).describedAs(\"desc\").isEqualTo(new int[] { 1 });", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fails_assertArrayEqualsDelta_double() { - CompilationTestHelper.newInstance(PreferAssertj.class, getClass()).addSourceLines( - "Test.java", - "import static org.junit.Assert.assertArrayEquals;", - "class Test {", - " void f(double[] param) {", - " // BUG: Diagnostic contains: Prefer AssertJ", - " assertArrayEquals(param, new double[] { 1D }, .1D);", - " // BUG: Diagnostic contains: Prefer AssertJ", - " assertArrayEquals(\"desc\", param, new double[] { 1D }, .1D);", - " }", - "}") - .doTest(); - } - - @Test - public void fails_assertArrayEqualsDelta_float() { - CompilationTestHelper.newInstance(PreferAssertj.class, getClass()).addSourceLines( - "Test.java", - "import static org.junit.Assert.assertArrayEquals;", - "class Test {", - " void f(float[] param) {", - " // BUG: Diagnostic contains: Prefer AssertJ", - " assertArrayEquals(param, new float[] { 1f }, .1f);", - " // BUG: Diagnostic contains: Prefer AssertJ", - " assertArrayEquals(\"desc\", param, new float[] { 1f }, .1f);", - " }", - "}") - .doTest(); - } - - @Test - public void fix_assertArrayEqualsDelta() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertArrayEquals;", - "class Test {", - " void foo(float[] floatArray, double[] doubleArray) {", - " assertArrayEquals(\"desc\", new float[] { 1f }, floatArray, 0);", - " assertArrayEquals(new float[] { 1f }, floatArray, 0);", - " assertArrayEquals(\"desc\", new double[] { 1D }, doubleArray, 0);", - " assertArrayEquals(new double[] { 1D }, doubleArray, 0);", - // nonzero delta doesn't have a migration path - " assertArrayEquals(\"desc\", new float[] { 1f }, floatArray, .1f);", - " assertArrayEquals(\"desc\", new double[] { 1D }, doubleArray, .1D);", - " assertArrayEquals(new float[] { 1f }, floatArray, .1f);", - " assertArrayEquals(new double[] { 1D }, doubleArray, .1D);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.junit.Assert.assertArrayEquals;", - "class Test {", - " void foo(float[] floatArray, double[] doubleArray) {", - " assertThat(floatArray).describedAs(\"desc\").isEqualTo(new float[] { 1f });", - " assertThat(floatArray).isEqualTo(new float[] { 1f });", - " assertThat(doubleArray).describedAs(\"desc\").isEqualTo(new double[] { 1D });", - " assertThat(doubleArray).isEqualTo(new double[] { 1D });", - " assertArrayEquals(\"desc\", new float[] { 1f }, floatArray, .1f);", - " assertArrayEquals(\"desc\", new double[] { 1D }, doubleArray, .1D);", - " assertArrayEquals(new float[] { 1f }, floatArray, .1f);", - " assertArrayEquals(new double[] { 1D }, doubleArray, .1D);", - " }", - "}") - .doTestExpectingFailure(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertNotEqualsInt() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertNotEquals;", - "class Test {", - " void foo(int value) {", - " assertNotEquals(1, value);", - " assertNotEquals(\"desc\", 1, value);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.junit.Assert.assertNotEquals;", - "class Test {", - " void foo(int value) {", - " assertThat(value).isNotEqualTo(1);", - " assertThat(value).describedAs(\"desc\").isNotEqualTo(1);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertThatInt() { - test() - .addInputLines( - "Test.java", - "import static org.junit.Assert.assertThat;", - "import static org.hamcrest.Matchers.is;", - "class Test {", - " void foo(int value) {", - " assertThat(value, is(1));", - " assertThat(\"desc\", value, is(1));", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.Matchers.is;", - "class Test {", - " void foo(int value) {", - " assertThat(value).isEqualTo(1);", - " assertThat(value).describedAs(\"desc\").isEqualTo(1);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_matcherAssertThatString_fallback() { - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(String value) {", - " assertThat(value, hasToString(\"str\"));", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.Matchers.*;", - "", - "import org.assertj.core.api.HamcrestCondition;", - "class Test {", - " void foo(String value) {", - " assertThat(value).is(new HamcrestCondition<>(hasToString(\"str\")));", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertThat_is_instanceOf() { - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(String value) {", - " assertThat(value, is(instanceOf(String.class)));", - " assertThat(value, instanceOf(String.class));", - " assertThat(value, is(not(instanceOf(String.class))));", - " assertThat(value, not(instanceOf(String.class)));", - " assertThat(\"desc\", value, is(instanceOf(String.class)));", - " assertThat(\"desc\", value, instanceOf(String.class));", - " assertThat(\"desc\", value, is(not(instanceOf(String.class))));", - " assertThat(\"desc\", value, not(instanceOf(String.class)));", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(String value) {", - " assertThat(value).isInstanceOf(String.class);", - " assertThat(value).isInstanceOf(String.class);", - " assertThat(value).isNotInstanceOf(String.class);", - " assertThat(value).isNotInstanceOf(String.class);", - " assertThat(value).describedAs(\"desc\").isInstanceOf(String.class);", - " assertThat(value).describedAs(\"desc\").isInstanceOf(String.class);", - " assertThat(value).describedAs(\"desc\").isNotInstanceOf(String.class);", - " assertThat(value).describedAs(\"desc\").isNotInstanceOf(String.class);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertThat_equality() { - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(String value) {", - " assertThat(value, is(\"str\"));", - " assertThat(value, equalTo(\"str\"));", - " assertThat(value, is(equalTo(\"str\")));", - " assertThat(value, org.hamcrest.CoreMatchers.equalToObject(\"str\"));", - " assertThat(value, not(not(equalTo(\"str\"))));", - " assertThat(value, not(is(\"str\")));", - " assertThat(value, not(equalTo(\"str\")));", - " assertThat(value, is(not(equalTo(\"str\"))));", - " assertThat(value, not(org.hamcrest.CoreMatchers.equalToObject(\"str\")));", - " assertThat(value, not(not(not(equalTo(\"str\")))));", - " assertThat(\"desc\", value, not(not(not(equalTo(\"str\")))));", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(String value) {", - " assertThat(value).isEqualTo(\"str\");", - " assertThat(value).isEqualTo(\"str\");", - " assertThat(value).isEqualTo(\"str\");", - " assertThat(value).isEqualTo(\"str\");", - " assertThat(value).isEqualTo(\"str\");", - " assertThat(value).isNotEqualTo(\"str\");", - " assertThat(value).isNotEqualTo(\"str\");", - " assertThat(value).isNotEqualTo(\"str\");", - " assertThat(value).isNotEqualTo(\"str\");", - " assertThat(value).isNotEqualTo(\"str\");", - " assertThat(value).describedAs(\"desc\").isNotEqualTo(\"str\");", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertThat_nullness() { - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(String value) {", - " assertThat(value, is(not(is(notNullValue(String.class)))));", - " assertThat(value, is(not(is(nullValue(String.class)))));", - " assertThat(value, is(nullValue(String.class)));", - " assertThat(value, nullValue());", - " assertThat(value, is(notNullValue(String.class)));", - " assertThat(value, notNullValue());", - " assertThat(\"desc\", value, is(not(is(notNullValue(String.class)))));", - " assertThat(\"desc\", value, is(not(is(nullValue(String.class)))));", - " assertThat(\"desc\", value, is(nullValue(String.class)));", - " assertThat(\"desc\", value, nullValue());", - " assertThat(\"desc\", value, is(notNullValue(String.class)));", - " assertThat(\"desc\", value, notNullValue());", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(String value) {", - " assertThat(value).isNull();", - " assertThat(value).isNotNull();", - " assertThat(value).isNull();", - " assertThat(value).isNull();", - " assertThat(value).isNotNull();", - " assertThat(value).isNotNull();", - " assertThat(value).describedAs(\"desc\").isNull();", - " assertThat(value).describedAs(\"desc\").isNotNull();", - " assertThat(value).describedAs(\"desc\").isNull();", - " assertThat(value).describedAs(\"desc\").isNull();", - " assertThat(value).describedAs(\"desc\").isNotNull();", - " assertThat(value).describedAs(\"desc\").isNotNull();", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertThat_contains() { - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(Iterable value, String[] arrayValue) {", - " assertThat(value, hasItem(\"str\"));", - " assertThat(arrayValue, hasItemInArray(\"str\"));", - " assertThat(value, hasItems(\"one\", \"two\"));", - " assertThat(arrayValue, arrayContainingInAnyOrder(\"one\", \"two\"));", - " assertThat(value, containsInAnyOrder(\"one\", \"two\"));", - " assertThat(value, contains(\"one\", \"two\"));", - " assertThat(value, not(hasItem(\"str\")));", - " assertThat(arrayValue, not(hasItemInArray(\"str\")));", - " assertThat(arrayValue[0], containsString(\"str\"));", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(Iterable value, String[] arrayValue) {", - " assertThat(value).contains(\"str\");", - " assertThat(arrayValue).contains(\"str\");", - " assertThat(value).contains(\"one\", \"two\");", - " assertThat(arrayValue).containsExactlyInAnyOrder(\"one\", \"two\");", - " assertThat(value).containsExactlyInAnyOrder(\"one\", \"two\");", - " assertThat(value).containsExactly(\"one\", \"two\");", - " assertThat(value).doesNotContain(\"str\");", - " assertThat(arrayValue).doesNotContain(\"str\");", - " assertThat(arrayValue[0]).contains(\"str\");", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertThat_empty() { - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.hamcrest.Matchers.*;", - "", - "import java.util.*;", - "class Test {", - " void foo(Iterable it, String[] ar, List li) {", - " assertThat(li, empty());", - " assertThat(li, emptyIterable());", - " assertThat(li, emptyCollectionOf(String.class));", - " assertThat(it, emptyIterable());", - " assertThat(it, emptyIterableOf(String.class));", - " assertThat(ar, emptyArray());", - " assertThat(li, is(not(empty())));", - " assertThat(li, not(emptyIterable()));", - " assertThat(li, not(emptyCollectionOf(String.class)));", - " assertThat(it, not(emptyIterable()));", - " assertThat(it, not(emptyIterableOf(String.class)));", - " assertThat(ar, not(emptyArray()));", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.Matchers.*;", - "", - "import java.util.*;", - "class Test {", - " void foo(Iterable it, String[] ar, List li) {", - " assertThat(li).isEmpty();", - " assertThat(li).isEmpty();", - " assertThat(li).isEmpty();", - " assertThat(it).isEmpty();", - " assertThat(it).isEmpty();", - " assertThat(ar).isEmpty();", - " assertThat(li).isNotEmpty();", - " assertThat(li).isNotEmpty();", - " assertThat(li).isNotEmpty();", - " assertThat(it).isNotEmpty();", - " assertThat(it).isNotEmpty();", - " assertThat(ar).isNotEmpty();", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertThat_size() { - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.hamcrest.Matchers.*;", - "", - "import java.util.*;", - "class Test {", - " void foo(Iterable it, String[] ar, List li) {", - " assertThat(li, hasSize(3));", - " assertThat(li, iterableWithSize(3));", - " assertThat(it, iterableWithSize(3));", - " assertThat(ar, arrayWithSize(3));", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.Matchers.*;", - "", - "import java.util.*;", - "class Test {", - " void foo(Iterable it, String[] ar, List li) {", - " assertThat(li).hasSize(3);", - " assertThat(li).hasSize(3);", - " assertThat(it).hasSize(3);", - " assertThat(ar).hasSize(3);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertThat_same() { - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(Object a, Object b) {", - " assertThat(a, theInstance(b));", - " assertThat(a, sameInstance(b));", - " assertThat(a, is(not(theInstance(b))));", - " assertThat(a, not(sameInstance(b)));", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(Object a, Object b) {", - " assertThat(a).isSameAs(b);", - " assertThat(a).isSameAs(b);", - " assertThat(a).isNotSameAs(b);", - " assertThat(a).isNotSameAs(b);", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertThat_strings() { - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(String value) {", - " assertThat(value, containsString(\"str\"));", - " assertThat(value, not(containsString(\"str\")));", - " assertThat(value, startsWith(\"str\"));", - " assertThat(value, not(startsWith(\"str\")));", - " assertThat(value, endsWith(\"str\"));", - " assertThat(value, not(endsWith(\"str\")));", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.Matchers.*;", - "class Test {", - " void foo(String value) {", - " assertThat(value).contains(\"str\");", - " assertThat(value).doesNotContain(\"str\");", - " assertThat(value).startsWith(\"str\");", - " assertThat(value).doesNotStartWith(\"str\");", - " assertThat(value).endsWith(\"str\");", - " assertThat(value).doesNotEndWith(\"str\");", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assertThat_wrongImport() { - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.hamcrest.core.Is.is;", - "import static org.hamcrest.core.IsEqual.equalTo;", - "import static org.hamcrest.core.IsNot.not;", - "class Test {", - " void foo(String value) {", - " assertThat(value, is(\"str\"));", - " assertThat(value, equalTo(\"str\"));", - " assertThat(value, not(is(\"str\")));", - " assertThat(value, not(equalTo(\"str\")));", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.core.Is.is;", - "import static org.hamcrest.core.IsEqual.equalTo;", - "import static org.hamcrest.core.IsNot.not;", - "class Test {", - " void foo(String value) {", - " assertThat(value).isEqualTo(\"str\");", - " assertThat(value).isEqualTo(\"str\");", - " assertThat(value).isNotEqualTo(\"str\");", - " assertThat(value).isNotEqualTo(\"str\");", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void fix_assert_iterableMap() { - // Iterable Maps result in ambiguous assertThat references - // to to both assertThat(Iterable) and assertThat(Map) - test() - .addInputLines( - "Test.java", - "import static org.hamcrest.MatcherAssert.assertThat;", - "import static org.hamcrest.Matchers.*;", - "import static org.junit.Assert.assertEquals;", - "import static org.junit.Assert.assertNull;", - "", - "import java.util.Map;", - "class Test {", - " interface IMap extends Map, Iterable> {}", - " void foo(IMap expected, IMap actual) {", - " assertThat(actual, equalTo(expected));", - " assertEquals(expected, actual);", - " assertEquals(\"desc\", expected, actual);", - " assertNull(actual);", - " assertNull(\"desc\", actual);", - " }", - "}") - .addOutputLines( - "Test.java", - "import static org.assertj.core.api.Assertions.assertThat;", - "import static org.hamcrest.Matchers.*;", - "import static org.junit.Assert.assertEquals;", - "import static org.junit.Assert.assertNull;", - "", - "import java.util.Map;", - "class Test {", - " interface IMap extends Map, Iterable> {}", - " void foo(IMap expected, IMap actual) {", - " assertThat((Map) actual).isEqualTo(expected);", - " assertThat((Map) actual).isEqualTo(expected);", - " assertThat((Map) actual).describedAs(\"desc\").isEqualTo(expected);", - " assertThat((Map) actual).isNull();", - " assertThat((Map) actual).describedAs(\"desc\").isNull();", - " }", - "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - @Test - public void assertsIgnoredInProductionCode() { - test().addInputLines("Test.java", - "class Test {", - " void execute(String input) {", - " assert input != null : \"input should not be null\";", - " assert input.length() == 5;", - " }", - "}") - .expectUnchanged() - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); - } - - private RefactoringValidator test() { - return RefactoringValidator.of(new PreferAssertj(), getClass()); - } -} diff --git a/baseline-refaster-rules/build.gradle b/baseline-refaster-rules/build.gradle index 5b1e6ee3e..560110f99 100644 --- a/baseline-refaster-rules/build.gradle +++ b/baseline-refaster-rules/build.gradle @@ -5,7 +5,6 @@ apply from: "${rootDir}/gradle/publish-jar.gradle" dependencies { implementation 'com.google.errorprone:error_prone_refaster' - implementation 'org.assertj:assertj-core' implementation 'org.mockito:mockito-core' testCompile 'junit:junit' diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjArrayEquals.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjArrayEquals.java deleted file mode 100644 index 0e6890967..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjArrayEquals.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Arrays; - -public final class AssertjArrayEquals { - - @BeforeTemplate - void bytes(byte[] actual, byte[] expected) { - assertThat(Arrays.equals(actual, expected)).isTrue(); - } - - @BeforeTemplate - void shorts(short[] actual, short[] expected) { - assertThat(Arrays.equals(actual, expected)).isTrue(); - } - - @BeforeTemplate - void ints(int[] actual, int[] expected) { - assertThat(Arrays.equals(actual, expected)).isTrue(); - } - - @BeforeTemplate - void longs(long[] actual, long[] expected) { - assertThat(Arrays.equals(actual, expected)).isTrue(); - } - - @BeforeTemplate - void floats(float[] actual, float[] expected) { - assertThat(Arrays.equals(actual, expected)).isTrue(); - } - - @BeforeTemplate - void doubles(double[] actual, double[] expected) { - assertThat(Arrays.equals(actual, expected)).isTrue(); - } - - @BeforeTemplate - void chars(char[] actual, char[] expected) { - assertThat(Arrays.equals(actual, expected)).isTrue(); - } - - @BeforeTemplate - void booleans(boolean[] actual, boolean[] expected) { - assertThat(Arrays.equals(actual, expected)).isTrue(); - } - - @BeforeTemplate - void arbitraryObjects(T[] actual, T[] expected) { - assertThat(Arrays.equals(actual, expected)).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(T[] actual, T[] expected) { - assertThat(actual).isEqualTo(expected); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanConjunction.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanConjunction.java deleted file mode 100644 index 279d11aaa..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanConjunction.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjBooleanConjunction { - - @BeforeTemplate - void before(boolean input1, boolean input2) { - assertThat(input1 && input2).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(boolean input1, boolean input2) { - assertThat(input1).isTrue(); - assertThat(input2).isTrue(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanConjunctionWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanConjunctionWithDescription.java deleted file mode 100644 index 9f6629379..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanConjunctionWithDescription.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjBooleanConjunctionWithDescription { - - @BeforeTemplate - void before(boolean input1, boolean input2, String description, @Repeated Object descriptionArgs) { - assertThat(input1 && input2).describedAs(description, descriptionArgs).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(boolean input1, boolean input2, String description, @Repeated Object descriptionArgs) { - assertThat(input1).describedAs(description, descriptionArgs).isTrue(); - assertThat(input2).describedAs(description, descriptionArgs).isTrue(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsFalse.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsFalse.java deleted file mode 100644 index 882bc1a09..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsFalse.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjBooleanNegationIsFalse { - - @BeforeTemplate - void before(boolean input) { - assertThat(!input).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(boolean input) { - assertThat(input).isTrue(); - } - -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsFalseWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsFalseWithDescription.java deleted file mode 100644 index 5592d45a6..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsFalseWithDescription.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjBooleanNegationIsFalseWithDescription { - - @BeforeTemplate - void before(boolean input, String description, @Repeated Object descriptionArgs) { - assertThat(!input).describedAs(description, descriptionArgs).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(boolean input, String description, @Repeated Object descriptionArgs) { - assertThat(input).describedAs(description, descriptionArgs).isTrue(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsTrue.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsTrue.java deleted file mode 100644 index 86e842000..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsTrue.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjBooleanNegationIsTrue { - - @BeforeTemplate - void before(boolean input) { - assertThat(!input).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(boolean input) { - assertThat(input).isFalse(); - } - -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsTrueWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsTrueWithDescription.java deleted file mode 100644 index 360d588dc..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjBooleanNegationIsTrueWithDescription.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjBooleanNegationIsTrueWithDescription { - - @BeforeTemplate - void before(boolean input, String description, @Repeated Object descriptionArgs) { - assertThat(!input).describedAs(description, descriptionArgs).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(boolean input, String description, @Repeated Object descriptionArgs) { - assertThat(input).describedAs(description, descriptionArgs).isFalse(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSameSizeAs.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSameSizeAs.java deleted file mode 100644 index ede04f835..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSameSizeAs.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Collection; -import org.assertj.core.api.IterableAssert; -import org.assertj.core.api.ListAssert; - -public final class AssertjCollectionHasSameSizeAs { - - @BeforeTemplate - IterableAssert before(IterableAssert assertInProgress, Collection expected) { - return assertInProgress.hasSize(expected.size()); - } - - @BeforeTemplate - ListAssert before(ListAssert assertInProgress, Collection expected) { - return assertInProgress.hasSize(expected.size()); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - IterableAssert after(IterableAssert assertInProgress, Collection expected) { - return assertInProgress.hasSameSizeAs(expected); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSameSizeAsArray.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSameSizeAsArray.java deleted file mode 100644 index 5cdc6f09c..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSameSizeAsArray.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import org.assertj.core.api.IterableAssert; -import org.assertj.core.api.ListAssert; - - -public final class AssertjCollectionHasSameSizeAsArray { - - @BeforeTemplate - IterableAssert before(IterableAssert assertInProgress, U[] expected) { - return assertInProgress.hasSize(expected.length); - } - - @BeforeTemplate - ListAssert before(ListAssert assertInProgress, U[] expected) { - return assertInProgress.hasSize(expected.length); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - IterableAssert after(IterableAssert assertInProgress, U[] expected) { - return assertInProgress.hasSameSizeAs(expected); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeExactly.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeExactly.java deleted file mode 100644 index 47df1e693..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeExactly.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Collection; - -public final class AssertjCollectionHasSizeExactly { - - @BeforeTemplate - void bad1(Collection things, int size) { - assertThat(things.size() == size).isTrue(); - } - - @BeforeTemplate - void bad2(Collection things, int size) { - assertThat(things.size()).isEqualTo(size); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Collection things, int size) { - assertThat(things).hasSize(size); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeExactlyWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeExactlyWithDescription.java deleted file mode 100644 index d5f6bbc85..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeExactlyWithDescription.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Collection; - -public final class AssertjCollectionHasSizeExactlyWithDescription { - - @BeforeTemplate - void bad1(Collection things, int size, String description, @Repeated Object descriptionArgs) { - assertThat(things.size() == size).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void bad2(Collection things, int size, String description, @Repeated Object descriptionArgs) { - assertThat(things.size()).describedAs(description, descriptionArgs).isEqualTo(size); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Collection things, int size, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).hasSize(size); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeGreaterThan.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeGreaterThan.java deleted file mode 100644 index 5ad513fa9..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeGreaterThan.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Collection; - -public final class AssertjCollectionHasSizeGreaterThan { - - @BeforeTemplate - void before1(Collection things, int size) { - assertThat(things.size() > size).isTrue(); - } - - @BeforeTemplate - void before2(Collection things, int size) { - assertThat(things.size()).isGreaterThan(size); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Collection things, int size) { - assertThat(things).hasSizeGreaterThan(size); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeGreaterThanWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeGreaterThanWithDescription.java deleted file mode 100644 index 619fcea0b..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeGreaterThanWithDescription.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Collection; - -public final class AssertjCollectionHasSizeGreaterThanWithDescription { - - @BeforeTemplate - void before1(Collection things, int size, String description, @Repeated Object descriptionArgs) { - assertThat(things.size() > size).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before2(Collection things, int size, String description, @Repeated Object descriptionArgs) { - assertThat(things.size()).describedAs(description, descriptionArgs).isGreaterThan(size); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Collection things, int size, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).hasSizeGreaterThan(size); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsEmpty.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsEmpty.java deleted file mode 100644 index 833f6ac38..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsEmpty.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Collection; - -public final class AssertjCollectionIsEmpty { - - @BeforeTemplate - void bad1(Collection things) { - assertThat(things.size() == 0).isTrue(); - } - - @BeforeTemplate - void bad2(Collection things) { - assertThat(things.isEmpty()).isTrue(); - } - - @BeforeTemplate - void bad3(Collection things) { - assertThat(things.size()).isZero(); - } - - @BeforeTemplate - void bad4(Collection things) { - assertThat(things.size()).isEqualTo(0); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Iterable things) { - assertThat(things).isEmpty(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsEmpty2.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsEmpty2.java deleted file mode 100644 index 126681621..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsEmpty2.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.errorprone.refaster.Refaster; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import java.util.Collections; -import org.assertj.core.api.AbstractAssert; -import org.assertj.core.api.AbstractIterableAssert; - -public final class AssertjCollectionIsEmpty2, - I extends Iterable, T, E extends AbstractAssert> { - - @BeforeTemplate - void before1(A in) { - in.hasSize(0); - } - - @BeforeTemplate - void before2(A in) { - in.isEqualTo(Refaster.anyOf( - ImmutableList.of(), - ImmutableSet.of(), - Collections.emptySet(), - Collections.emptyList())); - } - - @AfterTemplate - void after(A in) { - in.isEmpty(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsEmptyWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsEmptyWithDescription.java deleted file mode 100644 index e1b9b5fd1..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsEmptyWithDescription.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Collection; - -public final class AssertjCollectionIsEmptyWithDescription { - - @BeforeTemplate - void bad1(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things.size() == 0).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void bad2(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things.isEmpty()).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void bad3(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things.size()).describedAs(description, descriptionArgs).isZero(); - } - - @BeforeTemplate - void bad4(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things.size()).describedAs(description, descriptionArgs).isEqualTo(0); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Iterable things, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).isEmpty(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsNotEmpty.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsNotEmpty.java deleted file mode 100644 index 6c08e8b65..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsNotEmpty.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Collection; -import java.util.Collections; - -public final class AssertjCollectionIsNotEmpty { - - @BeforeTemplate - void bad1(Collection things) { - assertThat(things.size() != 0).isTrue(); - } - - @BeforeTemplate - void bad2(Collection things) { - assertThat(things.size() == 0).isFalse(); - } - - @BeforeTemplate - void bad3(Collection things) { - assertThat(things.size()).isNotEqualTo(0); - } - - @BeforeTemplate - void bad4(Collection things) { - assertThat(things.isEmpty()).isFalse(); - } - - @BeforeTemplate - void bad5(Collection things) { - assertThat(!things.isEmpty()).isTrue(); - } - - @BeforeTemplate - void bad6(Collection things) { - assertThat(things).isNotEqualTo(Collections.emptyList()); - } - - @BeforeTemplate - void bad7(Collection things) { - assertThat(things).isNotEqualTo(Collections.emptySet()); - } - - @BeforeTemplate - void bad8(Collection things) { - assertThat(things).isNotEqualTo(ImmutableList.of()); - } - - @BeforeTemplate - void bad9(Collection things) { - assertThat(things).isNotEqualTo(ImmutableSet.of()); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Collection things) { - assertThat(things).isNotEmpty(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsNotEmptyWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsNotEmptyWithDescription.java deleted file mode 100644 index c64f3166b..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjCollectionIsNotEmptyWithDescription.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Collection; -import java.util.Collections; - -public final class AssertjCollectionIsNotEmptyWithDescription { - - @BeforeTemplate - void bad1(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things.size() != 0).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void bad2(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things.size() == 0).describedAs(description, descriptionArgs).isFalse(); - } - - @BeforeTemplate - void bad3(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things.size()).describedAs(description, descriptionArgs).isNotEqualTo(0); - } - - @BeforeTemplate - void bad4(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things.isEmpty()).describedAs(description, descriptionArgs).isFalse(); - } - - @BeforeTemplate - void bad5(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(!things.isEmpty()).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void bad6(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).isNotEqualTo(Collections.emptyList()); - } - - @BeforeTemplate - void bad7(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).isNotEqualTo(Collections.emptySet()); - } - - @BeforeTemplate - void bad8(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).isNotEqualTo(ImmutableList.of()); - } - - @BeforeTemplate - void bad9(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).isNotEqualTo(ImmutableSet.of()); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Collection things, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).isNotEmpty(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjDescribedAsFormat.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjDescribedAsFormat.java deleted file mode 100644 index de4e975de..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjDescribedAsFormat.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import org.assertj.core.api.Descriptable; - -public final class AssertjDescribedAsFormat> { - - @BeforeTemplate - public T before(T assertion, String format, @Repeated Object formatArgs) { - return assertion.describedAs(String.format(format, formatArgs)); - } - - @AfterTemplate - public T after(T assertion, String format, @Repeated Object formatArgs) { - return assertion.describedAs(format, formatArgs); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjEquals.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjEquals.java deleted file mode 100644 index fd4ffde4f..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjEquals.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Objects; - -/** - * We have to guess as to which value is expected and which is the actual result, but either way failures will - * produce significantly more helpful output. - */ -public final class AssertjEquals { - - @BeforeTemplate - void before1(T expected, T actual) { - assertThat(actual.equals(expected)).isTrue(); - } - - @BeforeTemplate - void before2(T expected, T actual) { - assertThat(Objects.equals(actual, expected)).isTrue(); - } - - @BeforeTemplate - void before3(T expected, T actual) { - assertThat(!actual.equals(expected)).isFalse(); - } - - @BeforeTemplate - void before4(T expected, T actual) { - assertThat(!Objects.equals(actual, expected)).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(T expected, T actual) { - assertThat(actual).isEqualTo(expected); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjEqualsWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjEqualsWithDescription.java deleted file mode 100644 index a88511822..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjEqualsWithDescription.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Objects; - -/** - * We have to guess as to which value is expected and which is the actual result, but either way failures will - * produce significantly more helpful output. - */ -public final class AssertjEqualsWithDescription { - - @BeforeTemplate - void before1(T expected, T actual, String description, @Repeated Object descriptionArgs) { - assertThat(actual.equals(expected)).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before2(T expected, T actual, String description, @Repeated Object descriptionArgs) { - assertThat(Objects.equals(actual, expected)).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before3(T expected, T actual, String description, @Repeated Object descriptionArgs) { - assertThat(!actual.equals(expected)).describedAs(description, descriptionArgs).isFalse(); - } - - @BeforeTemplate - void before4(T expected, T actual, String description, @Repeated Object descriptionArgs) { - assertThat(!Objects.equals(actual, expected)).describedAs(description, descriptionArgs).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(T expected, T actual, String description, @Repeated Object descriptionArgs) { - assertThat(actual).describedAs(description, descriptionArgs).isEqualTo(expected); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjFileContent.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjFileContent.java deleted file mode 100644 index d466f7cb4..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjFileContent.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.common.io.Files; -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - -public final class AssertjFileContent { - - @BeforeTemplate - void before(File file, String expected) throws IOException { - assertThat(new String(Files.toByteArray(file), StandardCharsets.UTF_8)).isEqualTo(expected); - } - - @BeforeTemplate - @SuppressWarnings("deprecation") // we're migrating people off a deprecated method - void before2(File file, String expected) throws IOException { - assertThat(Files.toString(file, StandardCharsets.UTF_8)).isEqualTo(expected); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(File file, String expected) { - assertThat(file).hasContent(expected); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjInstanceOf.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjInstanceOf.java deleted file mode 100644 index 65b6fb5dc..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjInstanceOf.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.Refaster; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -/** - * We have to guess as to which value is expected and which is the actual result, but either way failures will - * produce significantly more helpful output. - */ -public final class AssertjInstanceOf { - - @BeforeTemplate - void before(T input) { - assertThat(Refaster.isInstance(input)).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(T input) { - assertThat(input).isInstanceOf(Refaster.clazz()); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjInstanceOfWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjInstanceOfWithDescription.java deleted file mode 100644 index 723b6ef1c..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjInstanceOfWithDescription.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.Refaster; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjInstanceOfWithDescription { - - @BeforeTemplate - void before(T input, String description, @Repeated Object descriptionArgs) { - assertThat(Refaster.isInstance(input)).describedAs(description, descriptionArgs).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(T input, String description, @Repeated Object descriptionArgs) { - assertThat(input).describedAs(description, descriptionArgs).isInstanceOf(Refaster.clazz()); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsFalse.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsFalse.java deleted file mode 100644 index 9e46effed..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsFalse.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjIsFalse { - - @BeforeTemplate - void before(boolean bool) { - assertThat(bool).isEqualTo(false); - } - - @BeforeTemplate - void before2(boolean bool) { - assertThat(false).isEqualTo(bool); - } - - @BeforeTemplate - void before3(boolean bool) { - assertThat(bool).isEqualTo(Boolean.FALSE); - } - - @BeforeTemplate - void before4(boolean bool) { - assertThat(Boolean.FALSE).isEqualTo(bool); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(boolean bool) { - assertThat(bool).isFalse(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsFalseWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsFalseWithDescription.java deleted file mode 100644 index d449629a8..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsFalseWithDescription.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjIsFalseWithDescription { - - @BeforeTemplate - void before(boolean bool, String description, @Repeated Object descriptionArgs) { - assertThat(bool).describedAs(description, descriptionArgs).isEqualTo(false); - } - - @BeforeTemplate - void before2(boolean bool, String description, @Repeated Object descriptionArgs) { - assertThat(false).describedAs(description, descriptionArgs).isEqualTo(bool); - } - - @BeforeTemplate - void before3(boolean bool, String description, @Repeated Object descriptionArgs) { - assertThat(bool).describedAs(description, descriptionArgs).isEqualTo(Boolean.FALSE); - } - - @BeforeTemplate - void before4(boolean bool, String description, @Repeated Object descriptionArgs) { - assertThat(Boolean.FALSE).describedAs(description, descriptionArgs).isEqualTo(bool); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(boolean bool, String description, @Repeated Object descriptionArgs) { - assertThat(bool).describedAs(description, descriptionArgs).isFalse(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsNotZero.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsNotZero.java deleted file mode 100644 index 897880389..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsNotZero.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import org.assertj.core.api.AbstractDoubleAssert; -import org.assertj.core.api.AbstractFloatAssert; -import org.assertj.core.api.AbstractIntegerAssert; -import org.assertj.core.api.AbstractLongAssert; -import org.assertj.core.api.NumberAssert; - -public final class AssertjIsNotZero { - - @BeforeTemplate - public AbstractIntegerAssert before(AbstractIntegerAssert input) { - return input.isNotEqualTo(0); - } - - @BeforeTemplate - public AbstractLongAssert before(AbstractLongAssert input) { - return input.isNotEqualTo(0L); - } - - @BeforeTemplate - public AbstractDoubleAssert before(AbstractDoubleAssert input) { - return input.isNotEqualTo(0D); - } - - @BeforeTemplate - public AbstractFloatAssert before(AbstractFloatAssert input) { - return input.isNotEqualTo(0f); - } - - @BeforeTemplate - public AbstractDoubleAssert beforeWithDecimal(AbstractDoubleAssert input) { - return input.isNotEqualTo(0.0D); - } - - @BeforeTemplate - public AbstractFloatAssert beforeWithDecimal(AbstractFloatAssert input) { - return input.isNotEqualTo(0.0); - } - - @AfterTemplate - public NumberAssert after(NumberAssert input) { - return input.isNotZero(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsNull.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsNull.java deleted file mode 100644 index fab49ddf3..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsNull.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Objects; - -public final class AssertjIsNull { - - @BeforeTemplate - void before1(Object input) { - assertThat(input == null).isTrue(); - } - - @BeforeTemplate - void before2(Object input) { - assertThat(input != null).isFalse(); - } - - @BeforeTemplate - void before3(Object input) { - assertThat(Objects.isNull(input)).isTrue(); - } - - @BeforeTemplate - void before4(Object input) { - assertThat(Objects.nonNull(input)).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Object input) { - assertThat(input).isNull(); - } - -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsNullWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsNullWithDescription.java deleted file mode 100644 index a4a0a10d3..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsNullWithDescription.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Objects; - -public final class AssertjIsNullWithDescription { - - @BeforeTemplate - void before1(Object input, String description, @Repeated Object descriptionArgs) { - assertThat(input == null).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before2(Object input, String description, @Repeated Object descriptionArgs) { - assertThat(input != null).describedAs(description, descriptionArgs).isFalse(); - } - - @BeforeTemplate - void before3(Object input, String description, @Repeated Object descriptionArgs) { - assertThat(Objects.isNull(input)).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before4(Object input, String description, @Repeated Object descriptionArgs) { - assertThat(Objects.nonNull(input)).describedAs(description, descriptionArgs).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Object input, String description, @Repeated Object descriptionArgs) { - assertThat(input).describedAs(description, descriptionArgs).isNull(); - } - -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsTrue.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsTrue.java deleted file mode 100644 index 7f425844e..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsTrue.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjIsTrue { - - @BeforeTemplate - void before(boolean bool) { - assertThat(bool).isEqualTo(true); - } - - @BeforeTemplate - void before2(boolean bool) { - assertThat(true).isEqualTo(bool); - } - - @BeforeTemplate - void before3(boolean bool) { - assertThat(bool).isEqualTo(Boolean.TRUE); - } - - @BeforeTemplate - void before4(boolean bool) { - assertThat(Boolean.TRUE).isEqualTo(bool); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(boolean bool) { - assertThat(bool).isTrue(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsTrueWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsTrueWithDescription.java deleted file mode 100644 index d70358e77..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsTrueWithDescription.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjIsTrueWithDescription { - - @BeforeTemplate - void before(boolean bool, String description, @Repeated Object descriptionArgs) { - assertThat(bool).describedAs(description, descriptionArgs).isEqualTo(true); - } - - @BeforeTemplate - void before2(boolean bool, String description, @Repeated Object descriptionArgs) { - assertThat(true).describedAs(description, descriptionArgs).isEqualTo(bool); - } - - @BeforeTemplate - void before3(boolean bool, String description, @Repeated Object descriptionArgs) { - assertThat(bool).describedAs(description, descriptionArgs).isEqualTo(Boolean.TRUE); - } - - @BeforeTemplate - void before4(boolean bool, String description, @Repeated Object descriptionArgs) { - assertThat(Boolean.TRUE).describedAs(description, descriptionArgs).isEqualTo(bool); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(boolean bool, String description, @Repeated Object descriptionArgs) { - assertThat(bool).describedAs(description, descriptionArgs).isTrue(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsZero.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsZero.java deleted file mode 100644 index 97d862699..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjIsZero.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import org.assertj.core.api.AbstractDoubleAssert; -import org.assertj.core.api.AbstractFloatAssert; -import org.assertj.core.api.AbstractIntegerAssert; -import org.assertj.core.api.AbstractLongAssert; -import org.assertj.core.api.NumberAssert; - -public final class AssertjIsZero { - - @BeforeTemplate - public AbstractIntegerAssert before(AbstractIntegerAssert input) { - return input.isEqualTo(0); - } - - @BeforeTemplate - public AbstractLongAssert before(AbstractLongAssert input) { - return input.isEqualTo(0L); - } - - @BeforeTemplate - public AbstractDoubleAssert before(AbstractDoubleAssert input) { - return input.isEqualTo(0D); - } - - @BeforeTemplate - public AbstractFloatAssert before(AbstractFloatAssert input) { - return input.isEqualTo(0f); - } - - @BeforeTemplate - public AbstractDoubleAssert beforeWithDecimal(AbstractDoubleAssert input) { - return input.isEqualTo(0.0D); - } - - @BeforeTemplate - public AbstractFloatAssert beforeWithDecimal(AbstractFloatAssert input) { - return input.isEqualTo(0.0); - } - - @AfterTemplate - public NumberAssert after(NumberAssert input) { - return input.isZero(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsEntry.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsEntry.java deleted file mode 100644 index 8ee828a99..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsEntry.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Map; - -public final class AssertjMapContainsEntry { - - @BeforeTemplate - void before(Map things, K key, V expectedValue) { - assertThat(things.get(key)).isEqualTo(expectedValue); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Map things, K key, V expectedValue) { - assertThat(things).containsEntry(key, expectedValue); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsEntryWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsEntryWithDescription.java deleted file mode 100644 index 438dbde11..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsEntryWithDescription.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Map; - -public final class AssertjMapContainsEntryWithDescription { - - @BeforeTemplate - void before(Map things, K key, V expectedValue, String description, @Repeated Object descriptionArgs) { - assertThat(things.get(key)).describedAs(description, descriptionArgs).isEqualTo(expectedValue); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Map things, K key, V expectedValue, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).containsEntry(key, expectedValue); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsKey.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsKey.java deleted file mode 100644 index 8042ea7a1..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsKey.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Map; - -public final class AssertjMapContainsKey { - - @BeforeTemplate - void before1(Map things, K key) { - assertThat(things.containsKey(key)).isTrue(); - } - - @BeforeTemplate - @SuppressWarnings("RedundantCollectionOperation") // It's what we're fixing - void before2(Map things, K key) { - assertThat(things.keySet().contains(key)).isTrue(); - } - - @BeforeTemplate - void before3(Map things, K key) { - assertThat(things.get(key)).isNotNull(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Map things, K key) { - assertThat(things).containsKey(key); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsKeyWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsKeyWithDescription.java deleted file mode 100644 index a38963908..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapContainsKeyWithDescription.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Map; - -public final class AssertjMapContainsKeyWithDescription { - - @BeforeTemplate - void before1(Map things, K key, String description, @Repeated Object descriptionArgs) { - assertThat(things.containsKey(key)).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - @SuppressWarnings("RedundantCollectionOperation") // It's what we're fixing - void before2(Map things, K key, String description, @Repeated Object descriptionArgs) { - assertThat(things.keySet().contains(key)).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before3(Map things, K key, String description, @Repeated Object descriptionArgs) { - assertThat(things.get(key)).describedAs(description, descriptionArgs).isNotNull(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Map things, K key, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).containsKey(key); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapDoesNotContainKey.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapDoesNotContainKey.java deleted file mode 100644 index 7c5749b5e..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapDoesNotContainKey.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Map; - -public final class AssertjMapDoesNotContainKey { - - @BeforeTemplate - void before1(Map things, K key) { - assertThat(things.containsKey(key)).isFalse(); - } - - @BeforeTemplate - void before2(Map things, K key) { - assertThat(things.get(key)).isNull(); - } - - @BeforeTemplate - @SuppressWarnings("RedundantCollectionOperation") // It's what we're fixing - void before3(Map things, K key) { - assertThat(things.keySet().contains(key)).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Map things, K key) { - assertThat(things).doesNotContainKey(key); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapDoesNotContainKeyWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapDoesNotContainKeyWithDescription.java deleted file mode 100644 index a1ec57df4..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapDoesNotContainKeyWithDescription.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Map; - -public final class AssertjMapDoesNotContainKeyWithDescription { - - @BeforeTemplate - void before1(Map things, K key, String description, @Repeated Object descriptionArgs) { - assertThat(things.containsKey(key)).describedAs(description, descriptionArgs).isFalse(); - } - - @BeforeTemplate - void before2(Map things, K key, String description, @Repeated Object descriptionArgs) { - assertThat(things.get(key)).describedAs(description, descriptionArgs).isNull(); - } - - @BeforeTemplate - @SuppressWarnings("RedundantCollectionOperation") // It's what we're fixing - void before3(Map things, K key, String description, @Repeated Object descriptionArgs) { - assertThat(things.keySet().contains(key)).describedAs(description, descriptionArgs).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Map things, K key, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).doesNotContainKey(key); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapHasSizeExactly.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapHasSizeExactly.java deleted file mode 100644 index fbd6997f6..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapHasSizeExactly.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Map; - -public final class AssertjMapHasSizeExactly { - - @BeforeTemplate - void before1(Map things, int size) { - assertThat(things.size() == size).isTrue(); - } - - @BeforeTemplate - void before2(Map things, int size) { - assertThat(things.size()).isEqualTo(size); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Map things, int size) { - assertThat(things).hasSize(size); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapHasSizeExactlyWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapHasSizeExactlyWithDescription.java deleted file mode 100644 index 2e41f72e3..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapHasSizeExactlyWithDescription.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Map; - -public final class AssertjMapHasSizeExactlyWithDescription { - - @BeforeTemplate - void before1(Map things, int size, String description, @Repeated Object descriptionArgs) { - assertThat(things.size() == size).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before2(Map things, int size, String description, @Repeated Object descriptionArgs) { - assertThat(things.size()).describedAs(description, descriptionArgs).isEqualTo(size); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Map things, int size, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).hasSize(size); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapIsEmpty.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapIsEmpty.java deleted file mode 100644 index 429db8848..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapIsEmpty.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Map; - -public final class AssertjMapIsEmpty { - - @BeforeTemplate - void before1(Map things) { - assertThat(things.size() == 0).isTrue(); - } - - @BeforeTemplate - void before2(Map things) { - assertThat(things.isEmpty()).isTrue(); - } - - @BeforeTemplate - void before3(Map things) { - assertThat(things.size()).isZero(); - } - - @BeforeTemplate - void before4(Map things) { - assertThat(things.size()).isEqualTo(0); - } - - @BeforeTemplate - void before5(Map things) { - assertThat(things).hasSize(0); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Map things) { - assertThat(things).isEmpty(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapIsEmpty2.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapIsEmpty2.java deleted file mode 100644 index 4e4656ea0..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapIsEmpty2.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import com.google.common.collect.ImmutableMap; -import com.google.errorprone.refaster.Refaster; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import java.util.Collections; -import org.assertj.core.api.MapAssert; - -public final class AssertjMapIsEmpty2, K, V> { - - @BeforeTemplate - void before1(A in) { - in.hasSize(0); - } - - @BeforeTemplate - void before2(A in) { - in.isEqualTo(Refaster.anyOf( - ImmutableMap.of(), - Collections.emptyMap())); - } - - @AfterTemplate - void after(A in) { - in.isEmpty(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapIsEmptyWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapIsEmptyWithDescription.java deleted file mode 100644 index dcc659950..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjMapIsEmptyWithDescription.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Map; - -public final class AssertjMapIsEmptyWithDescription { - - @BeforeTemplate - void before1(Map things, String description, @Repeated Object descriptionArgs) { - assertThat(things.size() == 0).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before2(Map things, String description, @Repeated Object descriptionArgs) { - assertThat(things.isEmpty()).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before3(Map things, String description, @Repeated Object descriptionArgs) { - assertThat(things.size()).describedAs(description, descriptionArgs).isZero(); - } - - @BeforeTemplate - void before4(Map things, String description, @Repeated Object descriptionArgs) { - assertThat(things.size()).describedAs(description, descriptionArgs).isEqualTo(0); - } - - @BeforeTemplate - void before5(Map things, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).hasSize(0); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Map things, String description, @Repeated Object descriptionArgs) { - assertThat(things).describedAs(description, descriptionArgs).isEmpty(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotEquals.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotEquals.java deleted file mode 100644 index eb2479a8f..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotEquals.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Objects; - -/** - * We have to guess as to which value is expected and which is the actual result, but either way failures will - * produce significantly more helpful output. - */ -public final class AssertjNotEquals { - - @BeforeTemplate - void before1(T expected, T actual) { - assertThat(!actual.equals(expected)).isTrue(); - } - - @BeforeTemplate - void before2(T expected, T actual) { - assertThat(!Objects.equals(actual, expected)).isTrue(); - } - - @BeforeTemplate - void before3(T expected, T actual) { - assertThat(actual.equals(expected)).isFalse(); - } - - @BeforeTemplate - void before4(T expected, T actual) { - assertThat(Objects.equals(actual, expected)).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(T expected, T actual) { - assertThat(actual).isNotEqualTo(expected); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotEqualsWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotEqualsWithDescription.java deleted file mode 100644 index 8417485be..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotEqualsWithDescription.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Objects; - -/** - * We have to guess as to which value is expected and which is the actual result, but either way failures will - * produce significantly more helpful output. - */ -public final class AssertjNotEqualsWithDescription { - - @BeforeTemplate - void before1(T expected, T actual, String description, @Repeated Object descriptionArgs) { - assertThat(!actual.equals(expected)).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before2(T expected, T actual, String description, @Repeated Object descriptionArgs) { - assertThat(!Objects.equals(actual, expected)).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before3(T expected, T actual, String description, @Repeated Object descriptionArgs) { - assertThat(actual.equals(expected)).describedAs(description, descriptionArgs).isFalse(); - } - - @BeforeTemplate - void before4(T expected, T actual, String description, @Repeated Object descriptionArgs) { - assertThat(Objects.equals(actual, expected)).describedAs(description, descriptionArgs).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(T expected, T actual, String description, @Repeated Object descriptionArgs) { - assertThat(actual).describedAs(description, descriptionArgs).isNotEqualTo(expected); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotNull.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotNull.java deleted file mode 100644 index 7a149f47d..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotNull.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Objects; - -public final class AssertjNotNull { - - @BeforeTemplate - void before1(Object input) { - assertThat(input == null).isFalse(); - } - - @BeforeTemplate - void before2(Object input) { - assertThat(input != null).isTrue(); - } - - @BeforeTemplate - void before3(Object input) { - assertThat(Objects.isNull(input)).isFalse(); - } - - @BeforeTemplate - void before4(Object input) { - assertThat(Objects.nonNull(input)).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Object input) { - assertThat(input).isNotNull(); - } - -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotNullWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotNullWithDescription.java deleted file mode 100644 index ea4ef2352..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjNotNullWithDescription.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Objects; - -public final class AssertjNotNullWithDescription { - - @BeforeTemplate - void before1(Object input, String description, @Repeated Object descriptionArgs) { - assertThat(input == null).describedAs(description, descriptionArgs).isFalse(); - } - - @BeforeTemplate - void before2(Object input, String description, @Repeated Object descriptionArgs) { - assertThat(input != null).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before3(Object input, String description, @Repeated Object descriptionArgs) { - assertThat(Objects.isNull(input)).describedAs(description, descriptionArgs).isFalse(); - } - - @BeforeTemplate - void before4(Object input, String description, @Repeated Object descriptionArgs) { - assertThat(Objects.nonNull(input)).describedAs(description, descriptionArgs).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Object input, String description, @Repeated Object descriptionArgs) { - assertThat(input).describedAs(description, descriptionArgs).isNotNull(); - } - -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalHasValue.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalHasValue.java deleted file mode 100644 index 96b3fecdd..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalHasValue.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Optional; - -public final class AssertjOptionalHasValue { - - @BeforeTemplate - void before(Optional optional, T innerValue) { - assertThat(optional.get()).isEqualTo(innerValue); - } - - @BeforeTemplate - void before2(Optional optional, T innerValue) { - assertThat(optional.isPresent() && optional.get().equals(innerValue)).isTrue(); - } - - @BeforeTemplate - void redundantAssertion(Optional optional, T innerValue) { - assertThat(optional).isPresent(); - assertThat(optional).hasValue(innerValue); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Optional optional, T innerValue) { - assertThat(optional).hasValue(innerValue); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalHasValueRedundantWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalHasValueRedundantWithDescription.java deleted file mode 100644 index 62b2a606b..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalHasValueRedundantWithDescription.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Optional; - -public final class AssertjOptionalHasValueRedundantWithDescription { - - @BeforeTemplate - void redundantAssertion( - Optional optional, - T innerValue, - String description1, - @Repeated Object descriptionArgs1, - String description2, - @Repeated Object descriptionArgs2) { - assertThat(optional).describedAs(description1, descriptionArgs1).isPresent(); - assertThat(optional).describedAs(description2, descriptionArgs2).hasValue(innerValue); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after( - Optional optional, - T innerValue, - // The first assertion is unnecessary - String _description1, - @Repeated Object _descriptionArgs1, - String description2, - @Repeated Object descriptionArgs2) { - assertThat(optional).describedAs(description2, descriptionArgs2).hasValue(innerValue); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalHasValueWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalHasValueWithDescription.java deleted file mode 100644 index d26ad9898..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalHasValueWithDescription.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Optional; - -public final class AssertjOptionalHasValueWithDescription { - - @BeforeTemplate - void before(Optional optional, T innerValue, String description, @Repeated Object descriptionArgs) { - assertThat(optional.get()).describedAs(description, descriptionArgs).isEqualTo(innerValue); - } - - @BeforeTemplate - void before2(Optional optional, T innerValue, String description, @Repeated Object descriptionArgs) { - assertThat(optional.isPresent() - && optional.get().equals(innerValue)).describedAs(description, descriptionArgs).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Optional optional, T innerValue, String description, @Repeated Object descriptionArgs) { - assertThat(optional).describedAs(description, descriptionArgs).hasValue(innerValue); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsNotPresent.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsNotPresent.java deleted file mode 100644 index 668e65ef7..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsNotPresent.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Optional; - -public final class AssertjOptionalIsNotPresent { - - @BeforeTemplate - void before1(Optional thing) { - assertThat(thing.isPresent()).isFalse(); - } - - @BeforeTemplate - void before2(Optional thing) { - assertThat(!thing.isPresent()).isTrue(); - } - - @BeforeTemplate - void before3(Optional thing) { - assertThat(thing).isEqualTo(Optional.empty()); - } - - @BeforeTemplate - void before4(Optional thing) { - assertThat(Optional.empty()).isEqualTo(thing); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Optional thing) { - assertThat(thing).isNotPresent(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsNotPresentWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsNotPresentWithDescription.java deleted file mode 100644 index a990b3adf..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsNotPresentWithDescription.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Optional; - -public final class AssertjOptionalIsNotPresentWithDescription { - - @BeforeTemplate - void before1(Optional thing, String description, @Repeated Object descriptionArgs) { - assertThat(thing.isPresent()).describedAs(description, descriptionArgs).isFalse(); - } - - @BeforeTemplate - void before2(Optional thing, String description, @Repeated Object descriptionArgs) { - assertThat(!thing.isPresent()).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before3(Optional thing, String description, @Repeated Object descriptionArgs) { - assertThat(thing).describedAs(description, descriptionArgs).isEqualTo(Optional.empty()); - } - - @BeforeTemplate - void before4(Optional thing, String description, @Repeated Object descriptionArgs) { - assertThat(Optional.empty()).describedAs(description, descriptionArgs).isEqualTo(thing); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Optional thing, String description, @Repeated Object descriptionArgs) { - assertThat(thing).describedAs(description, descriptionArgs).isNotPresent(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsPresent.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsPresent.java deleted file mode 100644 index 831871002..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsPresent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Optional; - -public final class AssertjOptionalIsPresent { - - @BeforeTemplate - void before(Optional thing) { - assertThat(thing.isPresent()).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Optional thing) { - assertThat(thing).isPresent(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsPresentWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsPresentWithDescription.java deleted file mode 100644 index 909bde248..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjOptionalIsPresentWithDescription.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.util.Optional; - -public final class AssertjOptionalIsPresentWithDescription { - - @BeforeTemplate - void before(Optional thing, String description, @Repeated Object descriptionArgs) { - assertThat(thing.isPresent()).describedAs(description, descriptionArgs).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(Optional thing, String description, @Repeated Object descriptionArgs) { - assertThat(thing).describedAs(description, descriptionArgs).isPresent(); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringContains.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringContains.java deleted file mode 100644 index 9a4be3bd8..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringContains.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjStringContains { - - @BeforeTemplate - void before1(String input, CharSequence contains) { - assertThat(input.contains(contains)).isTrue(); - } - - @BeforeTemplate - void before2(String input, CharSequence contains) { - assertThat(!input.contains(contains)).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(String input, CharSequence contains) { - assertThat(input).contains(contains); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringContainsWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringContainsWithDescription.java deleted file mode 100644 index 3809c0441..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringContainsWithDescription.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjStringContainsWithDescription { - - @BeforeTemplate - void before1(String input, CharSequence contains, String description, @Repeated Object descriptionArgs) { - assertThat(input.contains(contains)).describedAs(description, descriptionArgs).isTrue(); - } - - @BeforeTemplate - void before2(String input, CharSequence contains, String description, @Repeated Object descriptionArgs) { - assertThat(!input.contains(contains)).describedAs(description, descriptionArgs).isFalse(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(String input, CharSequence contains, String description, @Repeated Object descriptionArgs) { - assertThat(input).describedAs(description, descriptionArgs).contains(contains); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringDoesNotContain.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringDoesNotContain.java deleted file mode 100644 index 0026a2f6d..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringDoesNotContain.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjStringDoesNotContain { - - @BeforeTemplate - void before1(String input, CharSequence contains) { - assertThat(input.contains(contains)).isFalse(); - } - - @BeforeTemplate - void before2(String input, CharSequence contains) { - assertThat(!input.contains(contains)).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(String input, CharSequence contains) { - assertThat(input).doesNotContain(contains); - } -} diff --git a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringDoesNotContainWithDescription.java b/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringDoesNotContainWithDescription.java deleted file mode 100644 index e8c0b22e7..000000000 --- a/baseline-refaster-rules/src/main/java/com/palantir/baseline/refaster/AssertjStringDoesNotContainWithDescription.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.errorprone.refaster.ImportPolicy; -import com.google.errorprone.refaster.annotation.AfterTemplate; -import com.google.errorprone.refaster.annotation.BeforeTemplate; -import com.google.errorprone.refaster.annotation.Repeated; -import com.google.errorprone.refaster.annotation.UseImportPolicy; - -public final class AssertjStringDoesNotContainWithDescription { - - @BeforeTemplate - void before1(String input, CharSequence contains, String description, @Repeated Object descriptionArgs) { - assertThat(input.contains(contains)).describedAs(description, descriptionArgs).isFalse(); - } - - @BeforeTemplate - void before2(String input, CharSequence contains, String description, @Repeated Object descriptionArgs) { - assertThat(!input.contains(contains)).describedAs(description, descriptionArgs).isTrue(); - } - - @AfterTemplate - @UseImportPolicy(ImportPolicy.STATIC_IMPORT_ALWAYS) - void after(String input, CharSequence contains, String description, @Repeated Object descriptionArgs) { - assertThat(input).describedAs(description, descriptionArgs).doesNotContain(contains); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjArrayEqualsTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjArrayEqualsTest.java deleted file mode 100644 index f5d8ebba0..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjArrayEqualsTest.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; - -public class AssertjArrayEqualsTest { - @Test - public void sanity_check() { - byte[] bytes = {1, 2, 3}; - // both of these work, but I think isEqualTo reads a bit more nicely - assertThat(bytes).isEqualTo(new byte[]{1, 2, 3}); - assertThat(bytes).containsExactly(new byte[]{1, 2, 3}); - } - - @Test - public void bytes() { - RefasterTestHelper - .forRefactoring(AssertjArrayEquals.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(byte[] a, byte[] b) { assertThat(Arrays.equals(a,b)).isTrue(); }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(byte[] a, byte[] b) { assertThat(a).isEqualTo(b); }", - "}"); - } - - @Test - public void shorts() { - RefasterTestHelper - .forRefactoring(AssertjArrayEquals.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(short[] a, short[] b) { assertThat(Arrays.equals(a,b)).isTrue(); }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(short[] a, short[] b) { assertThat(a).isEqualTo(b); }", - "}"); - } - - @Test - public void ints() { - RefasterTestHelper - .forRefactoring(AssertjArrayEquals.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(int[] a, int[] b) { assertThat(Arrays.equals(a,b)).isTrue(); }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(int[] a, int[] b) { assertThat(a).isEqualTo(b); }", - "}"); - } - - @Test - public void longs() { - RefasterTestHelper - .forRefactoring(AssertjArrayEquals.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(long[] a, long[] b) { assertThat(Arrays.equals(a,b)).isTrue(); }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(long[] a, long[] b) { assertThat(a).isEqualTo(b); }", - "}"); - } - - @Test - public void floats() { - RefasterTestHelper - .forRefactoring(AssertjArrayEquals.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(float[] a, float[] b) { assertThat(Arrays.equals(a,b)).isTrue(); }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(float[] a, float[] b) { assertThat(a).isEqualTo(b); }", - "}"); - } - - @Test - public void doubles() { - RefasterTestHelper - .forRefactoring(AssertjArrayEquals.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(double[] a, double[] b) { assertThat(Arrays.equals(a,b)).isTrue(); }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(double[] a, double[] b) { assertThat(a).isEqualTo(b); }", - "}"); - } - - @Test - public void chars() { - RefasterTestHelper - .forRefactoring(AssertjArrayEquals.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(char[] a, char[] b) { assertThat(Arrays.equals(a,b)).isTrue(); }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(char[] a, char[] b) { assertThat(a).isEqualTo(b); }", - "}"); - } - - @Test - public void booleans() { - RefasterTestHelper - .forRefactoring(AssertjArrayEquals.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(boolean[] a, boolean[] b) { assertThat(Arrays.equals(a,b)).isTrue(); }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(boolean[] a, boolean[] b) { assertThat(a).isEqualTo(b); }", - "}"); - } - - @Test - public void strings() { - RefasterTestHelper - .forRefactoring(AssertjArrayEquals.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(String[] a, String[] b) { assertThat(Arrays.equals(a,b)).isTrue(); }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Arrays;", - "public class Test {", - " void f(String[] a, String[] b) { assertThat(a).isEqualTo(b); }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjBooleanConjunctionTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjBooleanConjunctionTest.java deleted file mode 100644 index eaa827dc5..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjBooleanConjunctionTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import org.junit.Test; - -public class AssertjBooleanConjunctionTest { - - @Test - public void test() { - RefasterTestHelper - .forRefactoring( - AssertjBooleanConjunction.class, - AssertjBooleanConjunctionWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(boolean bool1, boolean bool2) {", - " assertThat(bool1 && bool2).isTrue();", - " }", - " void g(boolean bool1, boolean bool2) {", - " assertThat(bool1 && bool2).describedAs(\"desc\").isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(boolean bool1, boolean bool2) {", - " assertThat(bool1).isTrue();", - "assertThat(bool2).isTrue();", - " }", - " void g(boolean bool1, boolean bool2) {", - " assertThat(bool1).describedAs(\"desc\").isTrue();", - "assertThat(bool2).describedAs(\"desc\").isTrue();", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjBooleanNegationTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjBooleanNegationTest.java deleted file mode 100644 index ffee277c7..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjBooleanNegationTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import org.junit.Test; - - -public class AssertjBooleanNegationTest { - - @Test - public void test() { - RefasterTestHelper - .forRefactoring( - AssertjBooleanNegationIsFalse.class, - AssertjBooleanNegationIsFalseWithDescription.class, - AssertjBooleanNegationIsTrue.class, - AssertjBooleanNegationIsTrueWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(Object a, Object b, boolean bool) {", - " assertThat(!bool).isTrue();", - " assertThat(!a.equals(b)).isTrue();", - " assertThat(!bool).isFalse();", - " assertThat(!a.equals(b)).isFalse();", - " assertThat(!bool).describedAs(\"desc\").isTrue();", - " assertThat(!a.equals(b)).describedAs(\"desc\").isTrue();", - " assertThat(!bool).describedAs(\"desc\").isFalse();", - " assertThat(!a.equals(b)).describedAs(\"desc\").isFalse();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(Object a, Object b, boolean bool) {", - " assertThat(bool).isFalse();", - " assertThat(a.equals(b)).isFalse();", - " assertThat(bool).isTrue();", - " assertThat(a.equals(b)).isTrue();", - " assertThat(bool).describedAs(\"desc\").isFalse();", - " assertThat(a.equals(b)).describedAs(\"desc\").isFalse();", - " assertThat(bool).describedAs(\"desc\").isTrue();", - " assertThat(a.equals(b)).describedAs(\"desc\").isTrue();", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionHasSameSizeAsTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionHasSameSizeAsTest.java deleted file mode 100644 index b4c509c65..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionHasSameSizeAsTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assumptions.assumeThat; - -import org.junit.Test; - -public class AssertjCollectionHasSameSizeAsTest { - - @Test - public void test() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjCollectionHasSameSizeAs.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "import java.util.Collection;", - "public class Test {", - " void f(List a, Collection b, Iterable c, List target) {", - " assertThat(a).hasSize(target.size());", - " assertThat(b).hasSize(target.size());", - " assertThat(c).hasSize(target.size());", - " assertThat(a).describedAs(\"desc\").hasSize(target.size());", - " assertThat(b).describedAs(\"desc\").hasSize(target.size());", - " assertThat(c).describedAs(\"desc\").hasSize(target.size());", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "import java.util.Collection;", - "public class Test {", - " void f(List a, Collection b, Iterable c, List target) {", - " assertThat(a).hasSameSizeAs(target);", - " assertThat(b).hasSameSizeAs(target);", - " assertThat(c).hasSameSizeAs(target);", - " assertThat(a).describedAs(\"desc\").hasSameSizeAs(target);", - " assertThat(b).describedAs(\"desc\").hasSameSizeAs(target);", - " assertThat(c).describedAs(\"desc\").hasSameSizeAs(target);", - " }", - "}"); - } - - @Test - public void testArray() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjCollectionHasSameSizeAsArray.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "import java.util.Collection;", - "public class Test {", - " void f(List a, Collection b, Iterable c, String[] target) {", - " assertThat(a).hasSize(target.length);", - " assertThat(b).hasSize(target.length);", - " assertThat(c).hasSize(target.length);", - " assertThat(a).describedAs(\"desc\").hasSize(target.length);", - " assertThat(b).describedAs(\"desc\").hasSize(target.length);", - " assertThat(c).describedAs(\"desc\").hasSize(target.length);", - " assertThat(c).describedAs(\"foo %s\", \"bar\").hasSize(target.length);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "import java.util.Collection;", - "public class Test {", - " void f(List a, Collection b, Iterable c, String[] target) {", - " assertThat(a).hasSameSizeAs(target);", - " assertThat(b).hasSameSizeAs(target);", - " assertThat(c).hasSameSizeAs(target);", - " assertThat(a).describedAs(\"desc\").hasSameSizeAs(target);", - " assertThat(b).describedAs(\"desc\").hasSameSizeAs(target);", - " assertThat(c).describedAs(\"desc\").hasSameSizeAs(target);", - " assertThat(c).describedAs(\"foo %s\", \"bar\").hasSameSizeAs(target);", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeTest.java deleted file mode 100644 index 7403a8611..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionHasSizeTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import org.junit.Test; - -public class AssertjCollectionHasSizeTest { - - @Test - public void exactSize_simple() { - RefasterTestHelper - .forRefactoring(AssertjCollectionHasSizeExactly.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in.size() == 2).isTrue();", - " assertThat(in.size()).isEqualTo(2);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in).hasSize(2);", - " assertThat(in).hasSize(2);", - " }", - "}"); - } - - @Test - public void exactSize_description() { - RefasterTestHelper - .forRefactoring(AssertjCollectionHasSizeExactlyWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableList;", - "import java.util.Collections;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in.size() == 2).describedAs(\"desc\").isTrue();", - " assertThat(in.size()).describedAs(\"desc\").isEqualTo(2);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableList;", - "import java.util.Collections;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in).describedAs(\"desc\").hasSize(2);", - " assertThat(in).describedAs(\"desc\").hasSize(2);", - " }", - "}"); - } - - @Test - public void greaterThan_simple() { - RefasterTestHelper - .forRefactoring(AssertjCollectionHasSizeGreaterThan.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in.size() > 2).isTrue();", - " assertThat(in.size()).isGreaterThan(2);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in).hasSizeGreaterThan(2);", - " assertThat(in).hasSizeGreaterThan(2);", - " }", - "}"); - } - - @Test - public void greaterThan_description() { - RefasterTestHelper - .forRefactoring(AssertjCollectionHasSizeGreaterThanWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in.size() > 2).describedAs(\"desc\").isTrue();", - " assertThat(in.size()).describedAs(\"desc\").isGreaterThan(2);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in).describedAs(\"desc\").hasSizeGreaterThan(2);", - " assertThat(in).describedAs(\"desc\").hasSizeGreaterThan(2);", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionIsEmptyTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionIsEmptyTest.java deleted file mode 100644 index 4cfd239af..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionIsEmptyTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assumptions.assumeThat; - -import org.junit.Test; - -public class AssertjCollectionIsEmptyTest { - - @Test - public void simple() { - RefasterTestHelper - .forRefactoring(AssertjCollectionIsEmpty.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in.size() == 0).isTrue();", - " assertThat(in.isEmpty()).isTrue();", - " assertThat(in.size()).isEqualTo(0);", - " assertThat(in.size()).isZero();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in).isEmpty();", - " assertThat(in).isEmpty();", - " assertThat(in).isEmpty();", - " assertThat(in).isEmpty();", - " }", - "}"); - } - - @Test - public void description() { - RefasterTestHelper - .forRefactoring(AssertjCollectionIsEmptyWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in.size() == 0).describedAs(\"desc\").isTrue();", - " assertThat(in.isEmpty()).describedAs(\"desc\").isTrue();", - " assertThat(in.size()).describedAs(\"desc\").isEqualTo(0);", - " assertThat(in.size()).describedAs(\"desc\").isZero();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " }", - "}"); - } - - @Test - public void test2() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjCollectionIsEmpty2.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableList;", - "import java.util.Collections;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in).hasSize(0);", - " assertThat(in).isEqualTo(ImmutableList.of());", - " assertThat(in).isEqualTo(Collections.emptyList());", - " assertThat(in).describedAs(\"desc\").hasSize(0);", - " assertThat(in).describedAs(\"desc\").isEqualTo(ImmutableList.of());", - " assertThat(in).describedAs(\"desc\").isEqualTo(Collections.emptyList());", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableList;", - "import java.util.Collections;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in).isEmpty();", - " assertThat(in).isEmpty();", - " assertThat(in).isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " }", - "}"); - } - -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionIsNotEmptyTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionIsNotEmptyTest.java deleted file mode 100644 index f5c72bc36..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjCollectionIsNotEmptyTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import org.junit.Test; - -public class AssertjCollectionIsNotEmptyTest { - - @Test - public void simple() { - RefasterTestHelper - .forRefactoring(AssertjCollectionIsNotEmpty.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in.size() != 0).isTrue();", - " assertThat(in.size() == 0).isFalse();", - " assertThat(in.isEmpty()).isFalse();", - " assertThat(!in.isEmpty()).isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in).isNotEmpty();", - " assertThat(in).isNotEmpty();", - " assertThat(in).isNotEmpty();", - " assertThat(in).isNotEmpty();", - " }", - "}"); - } - - @Test - public void description() { - RefasterTestHelper - .forRefactoring(AssertjCollectionIsNotEmptyWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in.size() != 0).describedAs(\"desc\").isTrue();", - " assertThat(in.size() == 0).describedAs(\"desc\").isFalse();", - " assertThat(in.isEmpty()).describedAs(\"desc\").isFalse();", - " assertThat(!in.isEmpty()).describedAs(\"desc\").isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in) {", - " assertThat(in).describedAs(\"desc\").isNotEmpty();", - " assertThat(in).describedAs(\"desc\").isNotEmpty();", - " assertThat(in).describedAs(\"desc\").isNotEmpty();", - " assertThat(in).describedAs(\"desc\").isNotEmpty();", - " }", - "}"); - } - -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjDescribedAsFormatTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjDescribedAsFormatTest.java deleted file mode 100644 index 86f869cb8..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjDescribedAsFormatTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assumptions.assumeThat; - -import org.junit.Test; - -public class AssertjDescribedAsFormatTest { - - @Test - public void test() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjDescribedAsFormat.class) - .withInputLines( - "Test", - "import static java.lang.String.format;", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj).isEqualTo(\"foo\");", - " assertThat(obj).describedAs(\"desc\").isEqualTo(\"foo\");", - " assertThat(obj).describedAs(\"desc %s\", \"arg\").isEqualTo(\"foo\");", - " assertThat(obj).describedAs(String.format(\"desc %s\", \"arg\")).isEqualTo(\"foo\");", - " assertThat(obj).describedAs(format(\"desc %s\", \"arg\")).isEqualTo(\"foo\");", - " }", - "}") - .hasOutputLines( - "import static java.lang.String.format;", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj).isEqualTo(\"foo\");", - " assertThat(obj).describedAs(\"desc\").isEqualTo(\"foo\");", - " assertThat(obj).describedAs(\"desc %s\", \"arg\").isEqualTo(\"foo\");", - " assertThat(obj).describedAs(\"desc %s\", \"arg\").isEqualTo(\"foo\");", - " assertThat(obj).describedAs(\"desc %s\", \"arg\").isEqualTo(\"foo\");", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjEqualityTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjEqualityTest.java deleted file mode 100644 index 14c8bb715..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjEqualityTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import org.junit.Test; - -public class AssertjEqualityTest { - - @Test - public void equals_simple() { - RefasterTestHelper - .forRefactoring(AssertjEquals.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Objects;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj.equals(\"foo\")).isTrue();", - " assertThat(!obj.equals(\"foo\")).isFalse();", - " assertThat(Objects.equals(obj, \"foo\")).isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Objects;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj).isEqualTo(\"foo\");", - " assertThat(obj).isEqualTo(\"foo\");", - " assertThat(obj).isEqualTo(\"foo\");", - " }", - "}"); - } - - @Test - public void equals_description() { - RefasterTestHelper - .forRefactoring(AssertjEqualsWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Objects;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj.equals(\"foo\")).describedAs(\"desc\").isTrue();", - " assertThat(!obj.equals(\"foo\")).describedAs(\"desc\").isFalse();", - " assertThat(Objects.equals(obj, \"foo\")).describedAs(\"desc\").isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Objects;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj).describedAs(\"desc\").isEqualTo(\"foo\");", - " assertThat(obj).describedAs(\"desc\").isEqualTo(\"foo\");", - " assertThat(obj).describedAs(\"desc\").isEqualTo(\"foo\");", - " }", - "}"); - } - - @Test - public void notEquals_simple() { - RefasterTestHelper - .forRefactoring(AssertjNotEquals.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Objects;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj.equals(\"foo\")).isFalse();", - " assertThat(!obj.equals(\"foo\")).isTrue();", - " assertThat(Objects.equals(obj, \"foo\")).isFalse();", - " assertThat(!Objects.equals(obj, \"foo\")).isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Objects;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj).isNotEqualTo(\"foo\");", - " assertThat(obj).isNotEqualTo(\"foo\");", - " assertThat(obj).isNotEqualTo(\"foo\");", - " assertThat(obj).isNotEqualTo(\"foo\");", - " }", - "}"); - } - - @Test - public void notEquals_description() { - RefasterTestHelper - .forRefactoring(AssertjNotEqualsWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Objects;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj.equals(\"foo\")).describedAs(\"desc\").isFalse();", - " assertThat(!obj.equals(\"foo\")).describedAs(\"desc\").isTrue();", - " assertThat(Objects.equals(obj, \"foo\")).describedAs(\"desc\").isFalse();", - " assertThat(!Objects.equals(obj, \"foo\")).describedAs(\"desc\").isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Objects;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj).describedAs(\"desc\").isNotEqualTo(\"foo\");", - " assertThat(obj).describedAs(\"desc\").isNotEqualTo(\"foo\");", - " assertThat(obj).describedAs(\"desc\").isNotEqualTo(\"foo\");", - " assertThat(obj).describedAs(\"desc\").isNotEqualTo(\"foo\");", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjInstanceOfTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjInstanceOfTest.java deleted file mode 100644 index eac81417a..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjInstanceOfTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import org.junit.Test; - -public class AssertjInstanceOfTest { - - @Test - public void simple() { - RefasterTestHelper - .forRefactoring(AssertjInstanceOf.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableList;", - "import java.util.List;", - "public class Test {", - " void f(List in, Object obj) {", - " assertThat(in instanceof ImmutableList).isTrue();", - " assertThat(obj instanceof String).isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableList;", - "import java.util.List;", - "public class Test {", - " void f(List in, Object obj) {", - " assertThat(in).isInstanceOf(ImmutableList.class);", - " assertThat(obj).isInstanceOf(String.class);", - " }", - "}"); - } - - @Test - public void description() { - RefasterTestHelper - .forRefactoring(AssertjInstanceOfWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableList;", - "import java.util.List;", - "public class Test {", - " void f(List in, Object obj) {", - " assertThat(in instanceof ImmutableList).describedAs(\"desc\").isTrue();", - " assertThat(obj instanceof String).describedAs(\"desc\").isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableList;", - "import java.util.List;", - "public class Test {", - " void f(List in, Object obj) {", - " assertThat(in).describedAs(\"desc\").isInstanceOf(ImmutableList.class);", - " assertThat(obj).describedAs(\"desc\").isInstanceOf(String.class);", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsFalseTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsFalseTest.java deleted file mode 100644 index 572def851..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsFalseTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import org.junit.Test; - -public class AssertjIsFalseTest { - - @Test - public void test() { - RefasterTestHelper - .forRefactoring( - AssertjIsFalse.class, - AssertjIsFalseWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(boolean bool) {", - " assertThat(bool).isEqualTo(false);", - " assertThat(bool).isEqualTo(Boolean.FALSE);", - " assertThat(false).isEqualTo(bool);", - " assertThat(Boolean.FALSE).isEqualTo(bool);", - " assertThat(bool).describedAs(\"desc\").isEqualTo(false);", - " assertThat(bool).describedAs(\"desc\").isEqualTo(false);", - " assertThat(false).describedAs(\"desc\").isEqualTo(bool);", - " assertThat(Boolean.FALSE).describedAs(\"desc\").isEqualTo(bool);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(boolean bool) {", - " assertThat(bool).isFalse();", - " assertThat(bool).isFalse();", - " assertThat(bool).isFalse();", - " assertThat(bool).isFalse();", - " assertThat(bool).describedAs(\"desc\").isFalse();", - " assertThat(bool).describedAs(\"desc\").isFalse();", - " assertThat(bool).describedAs(\"desc\").isFalse();", - " assertThat(bool).describedAs(\"desc\").isFalse();", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsNotZeroTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsNotZeroTest.java deleted file mode 100644 index 5f6cef94b..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsNotZeroTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assumptions.assumeThat; - -import org.junit.Test; - -public class AssertjIsNotZeroTest { - - @Test - public void test() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjIsNotZero.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in, int i, double d, float f, long l) {", - " assertThat(in.size()).isNotEqualTo(0);", - " assertThat(i).isNotEqualTo(0);", - " assertThat(d).isNotEqualTo(0);", - " assertThat(d).isNotEqualTo(0D);", - " assertThat(d).isNotEqualTo(0.0D);", - " assertThat(f).isNotEqualTo(0);", - " assertThat(f).isNotEqualTo(0.0);", - " assertThat(l).isNotEqualTo(0);", - " assertThat(l).isNotEqualTo(0L);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in, int i, double d, float f, long l) {", - " assertThat(in.size()).isNotZero();", - " assertThat(i).isNotZero();", - " assertThat(d).isNotZero();", - " assertThat(d).isNotZero();", - " assertThat(d).isNotZero();", - " assertThat(f).isNotZero();", - " assertThat(f).isNotZero();", - " assertThat(l).isNotZero();", - " assertThat(l).isNotZero();", - " }", - "}"); - } - -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsTrueTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsTrueTest.java deleted file mode 100644 index 71e59f686..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsTrueTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import org.junit.Test; - -public class AssertjIsTrueTest { - - @Test - public void test() { - RefasterTestHelper - .forRefactoring( - AssertjIsTrue.class, - AssertjIsTrueWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(boolean bool) {", - " assertThat(bool).isEqualTo(true);", - " assertThat(bool).isEqualTo(Boolean.TRUE);", - " assertThat(true).isEqualTo(bool);", - " assertThat(Boolean.TRUE).isEqualTo(bool);", - " assertThat(bool).describedAs(\"desc\").isEqualTo(true);", - " assertThat(bool).describedAs(\"desc\").isEqualTo(Boolean.TRUE);", - " assertThat(true).describedAs(\"desc\").isEqualTo(bool);", - " assertThat(Boolean.TRUE).describedAs(\"desc\").isEqualTo(bool);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(boolean bool) {", - " assertThat(bool).isTrue();", - " assertThat(bool).isTrue();", - " assertThat(bool).isTrue();", - " assertThat(bool).isTrue();", - " assertThat(bool).describedAs(\"desc\").isTrue();", - " assertThat(bool).describedAs(\"desc\").isTrue();", - " assertThat(bool).describedAs(\"desc\").isTrue();", - " assertThat(bool).describedAs(\"desc\").isTrue();", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsZeroTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsZeroTest.java deleted file mode 100644 index bde85ff26..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjIsZeroTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assumptions.assumeThat; - -import org.junit.Test; - -public class AssertjIsZeroTest { - - @Test - public void test() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjIsZero.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in, int i, double d, float f, long l) {", - " assertThat(in.size()).isEqualTo(0);", - " assertThat(i).isEqualTo(0);", - " assertThat(d).isEqualTo(0);", - " assertThat(d).isEqualTo(0D);", - " assertThat(d).isEqualTo(0.0D);", - " assertThat(f).isEqualTo(0);", - " assertThat(f).isEqualTo(0.0);", - " assertThat(l).isEqualTo(0);", - " assertThat(l).isEqualTo(0L);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.List;", - "public class Test {", - " void f(List in, int i, double d, float f, long l) {", - " assertThat(in.size()).isZero();", - " assertThat(i).isZero();", - " assertThat(d).isZero();", - " assertThat(d).isZero();", - " assertThat(d).isZero();", - " assertThat(f).isZero();", - " assertThat(f).isZero();", - " assertThat(l).isZero();", - " assertThat(l).isZero();", - " }", - "}"); - } - -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapContainsEntryTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapContainsEntryTest.java deleted file mode 100644 index 73d803365..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapContainsEntryTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assumptions.assumeThat; - -import org.junit.Test; - -public class AssertjMapContainsEntryTest { - - @Test - public void simple() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjMapContainsEntry.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in, String key, Object expected) {", - " assertThat(in.get(key)).isEqualTo(expected);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in, String key, Object expected) {", - " assertThat(in).containsEntry(key, expected);", - " }", - "}"); - } - - @Test - public void description() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjMapContainsEntryWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in, String key, Object expected) {", - " assertThat(in.get(key)).describedAs(\"desc\").isEqualTo(expected);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in, String key, Object expected) {", - " assertThat(in).describedAs(\"desc\").containsEntry(key, expected);", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapContainsKeyTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapContainsKeyTest.java deleted file mode 100644 index c5c70135e..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapContainsKeyTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assumptions.assumeThat; - -import org.junit.Test; - -public class AssertjMapContainsKeyTest { - - @Test - public void contains_simple() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjMapContainsKey.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in.keySet().contains(\"foo\")).isTrue();", - " assertThat(in.containsKey(\"foo\")).isTrue();", - " assertThat(in.get(\"foo\")).isNotNull();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in).containsKey(\"foo\");", - " assertThat(in).containsKey(\"foo\");", - " assertThat(in).containsKey(\"foo\");", - " }", - "}"); - } - - @Test - public void contains_description() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjMapContainsKeyWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in.keySet().contains(\"foo\")).describedAs(\"desc\").isTrue();", - " assertThat(in.containsKey(\"foo\")).describedAs(\"desc\").isTrue();", - " assertThat(in.get(\"foo\")).describedAs(\"desc\").isNotNull();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in).describedAs(\"desc\").containsKey(\"foo\");", - " assertThat(in).describedAs(\"desc\").containsKey(\"foo\");", - " assertThat(in).describedAs(\"desc\").containsKey(\"foo\");", - " }", - "}"); - } - - @Test - public void notContain_simple() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjMapDoesNotContainKey.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in.keySet().contains(\"foo\")).isFalse();", - " assertThat(in.containsKey(\"foo\")).isFalse();", - " assertThat(in.get(\"foo\")).isNull();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in).doesNotContainKey(\"foo\");", - " assertThat(in).doesNotContainKey(\"foo\");", - " assertThat(in).doesNotContainKey(\"foo\");", - " }", - "}"); - } - - @Test - public void notContain_description() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjMapDoesNotContainKeyWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in.keySet().contains(\"foo\")).describedAs(\"desc\").isFalse();", - " assertThat(in.containsKey(\"foo\")).describedAs(\"desc\").isFalse();", - " assertThat(in.get(\"foo\")).describedAs(\"desc\").isNull();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in).describedAs(\"desc\").doesNotContainKey(\"foo\");", - " assertThat(in).describedAs(\"desc\").doesNotContainKey(\"foo\");", - " assertThat(in).describedAs(\"desc\").doesNotContainKey(\"foo\");", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapHasSizeTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapHasSizeTest.java deleted file mode 100644 index 84edce169..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapHasSizeTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import org.junit.Test; - -public class AssertjMapHasSizeTest { - - @Test - public void exactSize_simple() { - RefasterTestHelper - .forRefactoring(AssertjMapHasSizeExactly.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in.size() == 2).isTrue();", - " assertThat(in.size()).isEqualTo(2);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in).hasSize(2);", - " assertThat(in).hasSize(2);", - " }", - "}"); - } - - @Test - public void exactSize_description() { - RefasterTestHelper - .forRefactoring(AssertjMapHasSizeExactlyWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableList;", - "import java.util.Collections;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in.size() == 2).describedAs(\"desc\").isTrue();", - " assertThat(in.size()).describedAs(\"desc\").isEqualTo(2);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableList;", - "import java.util.Collections;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in).describedAs(\"desc\").hasSize(2);", - " assertThat(in).describedAs(\"desc\").hasSize(2);", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapIsEmptyTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapIsEmptyTest.java deleted file mode 100644 index d6cb339ba..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjMapIsEmptyTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assumptions.assumeThat; - -import org.junit.Test; - -public class AssertjMapIsEmptyTest { - - @Test - public void simple() { - RefasterTestHelper - .forRefactoring(AssertjMapIsEmpty.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in.size() == 0).isTrue();", - " assertThat(in.isEmpty()).isTrue();", - " assertThat(in.size()).isEqualTo(0);", - " assertThat(in.size()).isZero();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in).isEmpty();", - " assertThat(in).isEmpty();", - " assertThat(in).isEmpty();", - " assertThat(in).isEmpty();", - " }", - "}"); - } - - @Test - public void description() { - RefasterTestHelper - .forRefactoring(AssertjMapIsEmptyWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in.size() == 0).describedAs(\"desc\").isTrue();", - " assertThat(in.isEmpty()).describedAs(\"desc\").isTrue();", - " assertThat(in.size()).describedAs(\"desc\").isEqualTo(0);", - " assertThat(in.size()).describedAs(\"desc\").isZero();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " }", - "}"); - } - - @Test - public void test2() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjMapIsEmpty2.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableMap;", - "import java.util.Collections;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in).hasSize(0);", - " assertThat(in).isEqualTo(ImmutableMap.of());", - " assertThat(in).isEqualTo(Collections.emptyMap());", - " assertThat(in).describedAs(\"desc\").hasSize(0);", - " assertThat(in).describedAs(\"desc\").isEqualTo(ImmutableMap.of());", - " assertThat(in).describedAs(\"desc\").isEqualTo(Collections.emptyMap());", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import com.google.common.collect.ImmutableMap;", - "import java.util.Collections;", - "import java.util.Map;", - "public class Test {", - " void f(Map in) {", - " assertThat(in).isEmpty();", - " assertThat(in).isEmpty();", - " assertThat(in).isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " assertThat(in).describedAs(\"desc\").isEmpty();", - " }", - "}"); - } - -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjNullTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjNullTest.java deleted file mode 100644 index 7133f6287..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjNullTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import org.junit.Test; - -public class AssertjNullTest { - - @Test - public void test() { - RefasterTestHelper - .forRefactoring( - AssertjIsNull.class, - AssertjIsNullWithDescription.class, - AssertjNotNull.class, - AssertjNotNullWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Objects;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj == null).isTrue();", - " assertThat(obj != null).isFalse();", - " assertThat(Objects.isNull(obj)).isTrue();", - " assertThat(Objects.nonNull(obj)).isFalse();", - " assertThat(obj == null).isFalse();", - " assertThat(obj != null).isTrue();", - " assertThat(Objects.isNull(obj)).isFalse();", - " assertThat(Objects.nonNull(obj)).isTrue();", - " assertThat(obj == null).describedAs(\"desc\").isTrue();", - " assertThat(obj != null).describedAs(\"desc\").isFalse();", - " assertThat(Objects.isNull(obj)).describedAs(\"desc\").isTrue();", - " assertThat(Objects.nonNull(obj)).describedAs(\"desc\").isFalse();", - " assertThat(obj == null).describedAs(\"desc\").isFalse();", - " assertThat(obj != null).describedAs(\"desc\").isTrue();", - " assertThat(Objects.isNull(obj)).describedAs(\"desc\").isFalse();", - " assertThat(Objects.nonNull(obj)).describedAs(\"desc\").isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Objects;", - "public class Test {", - " void f(Object obj) {", - " assertThat(obj).isNull();", - " assertThat(obj).isNull();", - " assertThat(obj).isNull();", - " assertThat(obj).isNull();", - " assertThat(obj).isNotNull();", - " assertThat(obj).isNotNull();", - " assertThat(obj).isNotNull();", - " assertThat(obj).isNotNull();", - " assertThat(obj).describedAs(\"desc\").isNull();", - " assertThat(obj).describedAs(\"desc\").isNull();", - " assertThat(obj).describedAs(\"desc\").isNull();", - " assertThat(obj).describedAs(\"desc\").isNull();", - " assertThat(obj).describedAs(\"desc\").isNotNull();", - " assertThat(obj).describedAs(\"desc\").isNotNull();", - " assertThat(obj).describedAs(\"desc\").isNotNull();", - " assertThat(obj).describedAs(\"desc\").isNotNull();", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjOptionalHasValueTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjOptionalHasValueTest.java deleted file mode 100644 index 9831dd5bd..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjOptionalHasValueTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assumptions.assumeThat; - -import org.junit.Test; - -public final class AssertjOptionalHasValueTest { - - @Test - public void test() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjOptionalHasValue.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in, String out) {", - " assertThat(in.get()).isEqualTo(out);", - " assertThat(in.isPresent() && in.get().equals(out)).isTrue();", - " }", - " void g(Optional in, String out) {", - " assertThat(in).isPresent();", - " assertThat(in).hasValue(out);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in, String out) {", - " assertThat(in).hasValue(out);", - " assertThat(in).hasValue(out);", - " }", - " void g(Optional in, String out) {", - " assertThat(in).hasValue(out);", - " ", - " }", - "}"); - } - - @Test - public void testWithDescription() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjOptionalHasValueWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in, String out) {", - " assertThat(in.get()).describedAs(\"desc\").isEqualTo(out);", - " assertThat(in.isPresent() && in.get().equals(out)).describedAs(\"desc\").isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in, String out) {", - " assertThat(in).describedAs(\"desc\").hasValue(out);", - " assertThat(in).describedAs(\"desc\").hasValue(out);", - " }", - "}"); - } - - @Test - public void testWithDescriptionRedundant() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjOptionalHasValueRedundantWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void g(Optional in, String out) {", - " assertThat(in).describedAs(\"a\").isPresent();", - " assertThat(in).describedAs(\"b\").hasValue(out);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void g(Optional in, String out) {", - " assertThat(in).describedAs(\"b\").hasValue(out);", - " ", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjOptionalPresenceTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjOptionalPresenceTest.java deleted file mode 100644 index 2b43bd35c..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjOptionalPresenceTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import static org.assertj.core.api.Assumptions.assumeThat; - -import org.junit.Test; - -public class AssertjOptionalPresenceTest { - - @Test - public void isPresent_simple() { - RefasterTestHelper - .forRefactoring(AssertjOptionalIsPresent.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in) {", - " assertThat(in.isPresent()).isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in) {", - " assertThat(in).isPresent();", - " }", - "}"); - } - - @Test - public void isPresent_description() { - RefasterTestHelper - .forRefactoring(AssertjOptionalIsPresentWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in) {", - " assertThat(in.isPresent()).describedAs(\"desc\").isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in) {", - " assertThat(in).describedAs(\"desc\").isPresent();", - " }", - "}"); - } - - @Test - public void isNotPresent_simple() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjOptionalIsNotPresent.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in) {", - " assertThat(in.isPresent()).isFalse();", - " assertThat(!in.isPresent()).isTrue();", - " assertThat(in).isEqualTo(Optional.empty());", - " assertThat(Optional.empty()).isEqualTo(in);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in) {", - " assertThat(in).isNotPresent();", - " assertThat(in).isNotPresent();", - " assertThat(in).isNotPresent();", - " assertThat(in).isNotPresent();", - " }", - "}"); - } - - @Test - public void isNotPresent_description() { - assumeThat(System.getProperty("java.specification.version")) - .describedAs("Refaster does not currently support fluent refactors on java 11") - .isEqualTo("1.8"); - RefasterTestHelper - .forRefactoring(AssertjOptionalIsNotPresentWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in) {", - " assertThat(in.isPresent()).describedAs(\"desc\").isFalse();", - " assertThat(!in.isPresent()).describedAs(\"desc\").isTrue();", - " assertThat(in).describedAs(\"desc\").isEqualTo(Optional.empty());", - " assertThat(Optional.empty()).describedAs(\"desc\").isEqualTo(in);", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "import java.util.Optional;", - "public class Test {", - " void f(Optional in) {", - " assertThat(in).describedAs(\"desc\").isNotPresent();", - " assertThat(in).describedAs(\"desc\").isNotPresent();", - " assertThat(in).describedAs(\"desc\").isNotPresent();", - " assertThat(in).describedAs(\"desc\").isNotPresent();", - " }", - "}"); - } -} diff --git a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjStringContentTest.java b/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjStringContentTest.java deleted file mode 100644 index 7bd3ccdaf..000000000 --- a/baseline-refaster-rules/src/test/java/com/palantir/baseline/refaster/AssertjStringContentTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. - * - * 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.palantir.baseline.refaster; - -import org.junit.Test; - -public class AssertjStringContentTest { - - @Test - public void contains_simple() { - RefasterTestHelper - .forRefactoring(AssertjStringContains.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(String str) {", - " assertThat(str.contains(\"foo\")).isTrue();", - " assertThat(!str.contains(\"foo\")).isFalse();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(String str) {", - " assertThat(str).contains(\"foo\");", - " assertThat(str).contains(\"foo\");", - " }", - "}"); - } - - @Test - public void contains_description() { - RefasterTestHelper - .forRefactoring(AssertjStringContainsWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(String str) {", - " assertThat(str.contains(\"foo\")).describedAs(\"desc\").isTrue();", - " assertThat(!str.contains(\"foo\")).describedAs(\"desc\").isFalse();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(String str) {", - " assertThat(str).describedAs(\"desc\").contains(\"foo\");", - " assertThat(str).describedAs(\"desc\").contains(\"foo\");", - " }", - "}"); - } - - @Test - public void notContain_simple() { - RefasterTestHelper - .forRefactoring(AssertjStringDoesNotContain.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(String str) {", - " assertThat(str.contains(\"foo\")).isFalse();", - " assertThat(!str.contains(\"foo\")).isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(String str) {", - " assertThat(str).doesNotContain(\"foo\");", - " assertThat(str).doesNotContain(\"foo\");", - " }", - "}"); - } - - @Test - public void notContain_description() { - RefasterTestHelper - .forRefactoring(AssertjStringDoesNotContainWithDescription.class) - .withInputLines( - "Test", - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(String str) {", - " assertThat(str.contains(\"foo\")).describedAs(\"desc\").isFalse();", - " assertThat(!str.contains(\"foo\")).describedAs(\"desc\").isTrue();", - " }", - "}") - .hasOutputLines( - "import static org.assertj.core.api.Assertions.assertThat;", - "public class Test {", - " void f(String str) {", - " assertThat(str).describedAs(\"desc\").doesNotContain(\"foo\");", - " assertThat(str).describedAs(\"desc\").doesNotContain(\"foo\");", - " }", - "}"); - } -} diff --git a/changelog/@unreleased/pr-1125.v2.yml b/changelog/@unreleased/pr-1125.v2.yml new file mode 100644 index 000000000..c313038c4 --- /dev/null +++ b/changelog/@unreleased/pr-1125.v2.yml @@ -0,0 +1,6 @@ +type: migration +migration: + description: All assertj-related code-rewriting now lives in the https://github.com/palantir/assertj-automation + repo. + links: + - https://github.com/palantir/gradle-baseline/pull/1125