diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java old mode 100755 new mode 100644 index a8ff06d20..44ae0f426 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java @@ -151,7 +151,7 @@ private static boolean isFloatingPointType(Expression expression) { JavaType.FullyQualified fullyQualified = TypeUtils.asFullyQualified(expression.getType()); if (fullyQualified != null) { String typeName = fullyQualified.getFullyQualifiedName(); - return (typeName.equals("java.lang.Double") || typeName.equals("java.lang.Float")); + return ("java.lang.Double".equals(typeName) || "java.lang.Float".equals(typeName)); } JavaType.Primitive parameterType = TypeUtils.asPrimitive(expression.getType()); diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java old mode 100755 new mode 100644 index fdba84332..c59fac829 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java @@ -145,7 +145,7 @@ private static boolean isFloatingPointType(Expression expression) { JavaType.FullyQualified fullyQualified = TypeUtils.asFullyQualified(expression.getType()); if (fullyQualified != null) { String typeName = fullyQualified.getFullyQualifiedName(); - return (typeName.equals("java.lang.Double") || typeName.equals("java.lang.Float")); + return ("java.lang.Double".equals(typeName) || "java.lang.Float".equals(typeName)); } JavaType.Primitive parameterType = TypeUtils.asPrimitive(expression.getType()); diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java index b79578b63..7d134f164 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java @@ -144,7 +144,7 @@ private static boolean isFloatingPointType(Expression expression) { JavaType.FullyQualified fullyQualified = TypeUtils.asFullyQualified(expression.getType()); if (fullyQualified != null) { String typeName = fullyQualified.getFullyQualifiedName(); - return (typeName.equals("java.lang.Double") || typeName.equals("java.lang.Float")); + return ("java.lang.Double".equals(typeName) || "java.lang.Float".equals(typeName)); } JavaType.Primitive parameterType = TypeUtils.asPrimitive(expression.getType()); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java b/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java old mode 100755 new mode 100644 index ce5ee613a..3f6281ac4 --- a/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java @@ -67,10 +67,10 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu Expression firstArg = args.get(0); // Suppress arg-switching for Assertions.assertEquals(String, String) if (args.size() == 2) { - if (m.getSimpleName().equals("assertSame") - || m.getSimpleName().equals("assertNotSame") - || m.getSimpleName().equals("assertEquals") - || m.getSimpleName().equals("assertNotEquals")) { + if ("assertSame".equals(m.getSimpleName()) + || "assertNotSame".equals(m.getSimpleName()) + || "assertEquals".equals(m.getSimpleName()) + || "assertNotEquals".equals(m.getSimpleName())) { return m; } } @@ -101,7 +101,7 @@ private boolean isStringArgument(Expression arg) { private static boolean isJunitAssertMethod(J.MethodInvocation method) { if (method.getType() != null && TypeUtils.isAssignableTo(ASSERTION_TYPE, method.getType().getDeclaringType())) { - return !method.getSimpleName().equals("assertThat"); + return !"assertThat".equals(method.getSimpleName()); } if (!(method.getSelect() instanceof J.Identifier)) { return false; @@ -111,7 +111,7 @@ private static boolean isJunitAssertMethod(J.MethodInvocation method) { return false; } JavaType.FullyQualified receiverType = (JavaType.FullyQualified) receiver.getType(); - return receiverType.getFullyQualifiedName().equals("org.junit.Assert"); + return "org.junit.Assert".equals(receiverType.getFullyQualifiedName()); } } } diff --git a/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java b/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java old mode 100755 new mode 100644 index 983fe1526..d3560defb --- a/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java @@ -137,7 +137,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl Expression expectMethodArg = args.get(0); isExpectArgAMatcher = isHamcrestMatcher(expectMethodArg); JavaType.FullyQualified argType = TypeUtils.asFullyQualified(expectMethodArg.getType()); - if (!isExpectArgAMatcher && (argType == null || !argType.getFullyQualifiedName().equals("java.lang.Class"))) { + if (!isExpectArgAMatcher && (argType == null || !"java.lang.Class".equals(argType.getFullyQualifiedName()))) { return m; } } @@ -235,7 +235,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { - if (method.getType() != null && method.getType().getDeclaringType().getFullyQualifiedName().equals("org.junit.rules.ExpectedException")) { + if (method.getType() != null && "org.junit.rules.ExpectedException".equals(method.getType().getDeclaringType().getFullyQualifiedName())) { switch (method.getSimpleName()) { case "expect": getCursor().putMessageOnFirstEnclosing(J.MethodDeclaration.class, "expectedExceptionMethodInvocation", method); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java b/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java index 8bb2580e1..8164cc013 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java @@ -99,7 +99,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex Cursor classDeclCursor = getCursor().dropParentUntil(J.ClassDeclaration.class::isInstance); // methods having names starting with parametersFor... are init methods if (m.getSimpleName().startsWith(PARAMETERS_FOR_PREFIX)) { - ((Set) classDeclCursor.computeMessageIfAbsent(INIT_METHOD_REFERENCES, v -> new HashSet())).add(m.getSimpleName()); + classDeclCursor.computeMessageIfAbsent(INIT_METHOD_REFERENCES, v -> new HashSet<>()).add(m.getSimpleName()); } return m; } @@ -112,7 +112,7 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ex String annotationArgumentValue = getAnnotationArgumentForInitMethod(anno, "method", "named"); if (annotationArgumentValue != null) { for (String method : annotationArgumentValue.split(",")) { - ((Set) classDeclCursor.computeMessageIfAbsent(INIT_METHOD_REFERENCES, v -> new HashSet())).add(method); + classDeclCursor.computeMessageIfAbsent(INIT_METHOD_REFERENCES, v -> new HashSet<>()).add(method); } } else if (anno.getArguments() != null && !anno.getArguments().isEmpty()) { // This conversion is not supported add a comment to the annotation and the method name to the not supported list @@ -130,15 +130,15 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ex String namedInitMethod = getLiteralAnnotationArgumentValue(annotation); if (namedInitMethod != null) { J.MethodDeclaration m = getCursor().dropParentUntil(J.MethodDeclaration.class::isInstance).getValue(); - ((Set) classDeclCursor.computeMessageIfAbsent(INIT_METHOD_REFERENCES, v -> new HashSet())).add(m.getSimpleName()); - classDeclCursor.computeMessageIfAbsent(INIT_METHODS_MAP, v -> new HashMap()).put(namedInitMethod, m.getSimpleName()); + classDeclCursor.computeMessageIfAbsent(INIT_METHOD_REFERENCES, v -> new HashSet<>()).add(m.getSimpleName()); + classDeclCursor.computeMessageIfAbsent(INIT_METHODS_MAP, v -> new HashMap<>()).put(namedInitMethod, m.getSimpleName()); } } else if (TEST_CASE_NAME_MATCHER.matches(anno)) { // test name for ParameterizedTest argument Object testNameArg = getLiteralAnnotationArgumentValue(anno); String testName = testNameArg != null ? testNameArg.toString() : "{method}({params}) [{index}]"; J.MethodDeclaration md = getCursor().dropParentUntil(J.MethodDeclaration.class::isInstance).getValue(); - classDeclCursor.computeMessageIfAbsent(INIT_METHODS_MAP, v -> new HashMap()).put(md.getSimpleName(), testName); + classDeclCursor.computeMessageIfAbsent(INIT_METHODS_MAP, v -> new HashMap<>()).put(md.getSimpleName(), testName); } return anno; } diff --git a/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java b/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java index 3ec169063..450913fde 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java @@ -146,9 +146,9 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex J.MethodDeclaration md = super.visitMethodDeclaration(method, executionContext); if (md.getSimpleName().startsWith("test") && md.getLeadingAnnotations().stream().noneMatch(JUNIT_TEST_ANNOTATION_MATCHER::matches)) { md = updateMethodDeclarationAnnotationAndModifier(md, "@Test", "org.junit.jupiter.api.Test"); - } else if (md.getSimpleName().equals("setUp")) { + } else if ("setUp".equals(md.getSimpleName())) { md = updateMethodDeclarationAnnotationAndModifier(md, "@BeforeEach", "org.junit.jupiter.api.BeforeEach"); - } else if (md.getSimpleName().equals("tearDown")) { + } else if ("tearDown".equals(md.getSimpleName())) { md = updateMethodDeclarationAnnotationAndModifier(md, "@AfterEach", "org.junit.jupiter.api.AfterEach"); } return md; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java b/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java index a6357b68b..fa46cefe1 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/ParameterizedRunnerToParameterized.java @@ -131,7 +131,7 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations m variableForInitMethod = variableForInitMethod.withTypeExpression(variableForInitMethod.getTypeExpression().withPrefix(Space.EMPTY).withComments(new ArrayList<>())); } //noinspection unchecked - ((TreeMap) params.computeIfAbsent(FIELD_INJECTION_ARGUMENTS, v -> new TreeMap())).put(position, variableForInitMethod); + ((TreeMap) params.computeIfAbsent(FIELD_INJECTION_ARGUMENTS, v -> new TreeMap<>())).put(position, variableForInitMethod); } return variableDeclarations; diff --git a/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java b/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java index 920e29248..071ee5cf9 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java @@ -161,7 +161,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex JavaType newFolderMethodDeclaration = methods .filter(m -> { List params = m.getParameters(); - return m.getSimpleName().equals("newFolder") + return "newFolder".equals(m.getSimpleName()) && params.size() == 2 && params.get(0).hasClassType(FILE_TYPE) && params.get(1).hasClassType(STRING_TYPE); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java index 95379beee..6c9471125 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java @@ -127,7 +127,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex String assignParamName = ((J.Identifier) assign.getVariable()).getSimpleName(); Expression e = assign.getAssignment(); - if (assignParamName.equals("expected")) { + if ("expected".equals(assignParamName)) { assert e instanceof J.FieldAccess; m = m.withTemplate(JavaTemplate.builder(this::getCursor, "Object o = () -> #{}").build(), @@ -146,7 +146,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex e, lambda); maybeAddImport("org.junit.jupiter.api.Assertions", "assertThrows"); - } else if (assignParamName.equals("timeout")) { + } else if ("timeout".equals(assignParamName)) { doAfterVisit(new AddTimeoutAnnotationStep(m, e)); } }