Class AssertEqualsToAssertThat

  • All Implemented Interfaces:
    org.openrewrite.java.JavaSourceVisitor<org.openrewrite.java.tree.J>, org.openrewrite.RefactorVisitor<org.openrewrite.java.tree.J>, org.openrewrite.SourceVisitor<org.openrewrite.java.tree.J>

    public class AssertEqualsToAssertThat
    extends org.openrewrite.java.JavaIsoRefactorVisitor
    This is a refactoring visitor that will convert JUnit-style assertEquals() to assertJ's assertThat().isEqualTo(). This visitor has to convert a surprisingly large number (93 methods) of JUnit's assertEquals to assertThat().
      Two parameter variants:
    
      assertEquals(expected,actual) -> assertThat(actual).isEqualTo(expected)
    
      Three parameter variant where the third argument is a String:
    
      assertEquals(expected, actual, "message") -> assertThat(actual).as("message").isEqualTo(expected)
    
      Three parameter variant where the third argument is a String supplier:
    
      assertEquals(expected, actual, () -> "message") -> assertThat(actual).withFailureMessage("message").isEqualTo(expected)
    
      Three parameter variant where args are all floating point numbers.
    
      assertEquals(expected, actual, delta) -> assertThat(actual).isCloseTo(expected, within(delta));
    
      Four parameter variant when comparing floating point numbers with a delta and a message:
    
      assertEquals(expected, actual, delta, "message") -> assertThat(actual).withFailureMessage("message").isCloseTo(expected, within(delta));
    
     
    • Field Summary

      • Fields inherited from class org.openrewrite.java.JavaRefactorVisitor

        formatter, treeBuilder
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.openrewrite.java.tree.J.MethodInvocation visitMethodInvocation​(org.openrewrite.java.tree.J.MethodInvocation method)  
      • Methods inherited from class org.openrewrite.java.JavaIsoRefactorVisitor

        visitAnnotatedType, visitAnnotation, visitArrayAccess, visitArrayType, visitAssert, visitAssign, visitAssignOp, visitBinary, visitBlock, visitBreak, visitCase, visitCatch, visitClassDecl, visitCompilationUnit, visitContinue, visitDoWhileLoop, visitElse, visitEmpty, visitEnumValue, visitEnumValueSet, visitFieldAccess, visitFinally, visitForEachLoop, visitForLoop, visitIdentifier, visitIf, visitImport, visitInstanceOf, visitLabel, visitLambda, visitLiteral, visitMemberReference, visitMethod, visitMultiCatch, visitMultiVariable, visitNewArray, visitNewClass, visitPackage, visitParameterizedType, visitParentheses, visitPrimitive, visitReturn, visitStatement, visitSwitch, visitSynchronized, visitTernary, visitThrow, visitTry, visitTypeCast, visitTypeName, visitTypeParameter, visitTypeParameters, visitUnary, visitUnparsedSource, visitVariable, visitWhileLoop, visitWildcard
      • Methods inherited from class org.openrewrite.java.JavaRefactorVisitor

        addImport, addImport, maybeAddImport, maybeAddImport, maybeAddImport, maybeRemoveImport, maybeRemoveImport, maybeUnwrapParentheses
      • Methods inherited from class org.openrewrite.AbstractRefactorVisitor

        andThen, andThen, next, refactor, refactor, refactor
      • Methods inherited from class org.openrewrite.AbstractSourceVisitor

        getCursor, setCursoringOn, visit, visitAfter, visitAfter
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.openrewrite.java.JavaSourceVisitor

        enclosingBlock, enclosingClass, enclosingCompilationUnit, enclosingMethod, isInSameNameScope, isInSameNameScope, visitExpression
      • Methods inherited from interface org.openrewrite.RefactorVisitor

        defaultTo, generate, isIdempotent, nextCycle
      • Methods inherited from interface org.openrewrite.SourceVisitor

        getCursor, getName, getTags, reduce, validate, visit, visit, visitTree
    • Constructor Detail

      • AssertEqualsToAssertThat

        public AssertEqualsToAssertThat()
    • Method Detail

      • visitMethodInvocation

        public org.openrewrite.java.tree.J.MethodInvocation visitMethodInvocation​(org.openrewrite.java.tree.J.MethodInvocation method)
        Specified by:
        visitMethodInvocation in interface org.openrewrite.java.JavaSourceVisitor<org.openrewrite.java.tree.J>
        Overrides:
        visitMethodInvocation in class org.openrewrite.java.JavaIsoRefactorVisitor