Class JUnitAssertEqualsToAssertThat


  • public class JUnitAssertEqualsToAssertThat
    extends org.openrewrite.Recipe
    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.Recipe

        NOOP
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getDescription()  
      java.lang.String getDisplayName()  
      protected org.openrewrite.TreeVisitor<?,​org.openrewrite.ExecutionContext> getVisitor()  
      • Methods inherited from class org.openrewrite.Recipe

        causesAnotherCycle, doNext, equals, getApplicableTest, getDescriptor, getJacksonPolymorphicTypeTag, getLanguages, getName, getRecipeList, getTags, hashCode, run, run, run, run, validate, validate, validateAll, validateAll, visit
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JUnitAssertEqualsToAssertThat

        public JUnitAssertEqualsToAssertThat()
    • Method Detail

      • getDisplayName

        public java.lang.String getDisplayName()
        Specified by:
        getDisplayName in class org.openrewrite.Recipe
      • getDescription

        public java.lang.String getDescription()
        Overrides:
        getDescription in class org.openrewrite.Recipe
      • getVisitor

        protected org.openrewrite.TreeVisitor<?,​org.openrewrite.ExecutionContext> getVisitor()
        Overrides:
        getVisitor in class org.openrewrite.Recipe