Migrate removed Spring Assert methods

org.openrewrite.java.spring.framework.MigrateSpringAssert

Assert methods without a message argument have been removed in Spring Framework 6.0.

Recipe source

GitHub, Issue Tracker, Maven Central

  • groupId: org.openrewrite.recipe

  • artifactId: rewrite-spring

  • version: 5.9.0

This recipe is composed of more than one recipe. If you want to customize the set of recipes this is composed of, you can find and copy the GitHub source for the recipe from the link above.

Usage

This recipe has no required configuration options. It can be activated by adding a dependency on org.openrewrite.recipe:rewrite-spring:5.9.0 in your build file or by running a shell command (in which case no build changes are needed):

  1. Add the following to your build.gradle file:

build.gradle
plugins {
    id("org.openrewrite.rewrite") version("6.13.0")
}

rewrite {
    activeRecipe("org.openrewrite.java.spring.framework.MigrateSpringAssert")
}

repositories {
    mavenCentral()
}

dependencies {
    rewrite("org.openrewrite.recipe:rewrite-spring:5.9.0")
}
  1. Run gradle rewriteRun to run the recipe.

Definition

  • Add a literal method argument

    • methodPattern: org.springframework.util.Assert state(boolean)

    • argumentIndex: 1

    • literal: must be true

  • Add a literal method argument

    • methodPattern: org.springframework.util.Assert isTrue(boolean)

    • argumentIndex: 1

    • literal: must be true

  • Add a literal method argument

    • methodPattern: org.springframework.util.Assert isNull(java.lang.Object)

    • argumentIndex: 1

    • literal: must be null

  • Add a literal method argument

    • methodPattern: org.springframework.util.Assert notNull(java.lang.Object)

    • argumentIndex: 1

    • literal: must not be null

  • Add a literal method argument

    • methodPattern: org.springframework.util.Assert hasLength(java.lang.String)

    • argumentIndex: 1

    • literal: must have length; it must not be null or empty

  • Add a literal method argument

    • methodPattern: org.springframework.util.Assert hasText(java.lang.String)

    • argumentIndex: 1

    • literal: must have text; it must not be null, empty, or blank

  • Add a literal method argument

    • methodPattern: org.springframework.util.Assert doesNotContain(java.lang.String, java.lang.String)

    • argumentIndex: 2

    • literal: must not contain the substring

  • Add a literal method argument

    • methodPattern: org.springframework.util.Assert notEmpty(java.lang.Object[])

    • argumentIndex: 1

    • literal: must not be empty

  • Add a literal method argument

    • methodPattern: org.springframework.util.Assert noNullElements(java.lang.Object[])

    • argumentIndex: 1

    • literal: must not contain any null elements

  • Add a literal method argument

    • methodPattern: org.springframework.util.Assert noNullElements(java.util.Collection)

    • argumentIndex: 1

    • literal: must not be empty

  • Add a literal method argument

    • methodPattern: org.springframework.util.Assert notEmpty(java.util.Map)

    • argumentIndex: 1

    • literal: must not be empty

See how this recipe works across multiple open-source repositories

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Last updated