-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spring Framework 6.0 recipe with migration for Spring
Assert
(#522)
* Spring Framework 6.0 recipe * Only includes a migration for removed methods in `org.springframework.util.Assert` for now * Add a minimal unit test for MigrateSpringAssert * Add DocumentExample to MigrateSpringAssert --------- Co-authored-by: Tim te Beek <[email protected]>
- Loading branch information
Showing
3 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/resources/META-INF/rewrite/spring-framework-60.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# | ||
# Copyright 2024 the original author or authors. | ||
# <p> | ||
# 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 | ||
# <p> | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# <p> | ||
# 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. | ||
# | ||
|
||
######################################################################################################################## | ||
# Spring Framework 6.0 | ||
--- | ||
type: specs.openrewrite.org/v1beta/recipe | ||
name: org.openrewrite.java.spring.framework.UpgradeSpringFramework_6_0 | ||
displayName: Migrate to Spring Framework 6.0 | ||
description: Migrate applications to the latest Spring Framework 6.0 release. | ||
recipeList: | ||
- org.openrewrite.java.spring.framework.UpgradeSpringFramework_5_3 | ||
- org.openrewrite.java.dependencies.UpgradeDependencyVersion: | ||
groupId: org.springframework | ||
artifactId: "*" | ||
newVersion: 6.0.x | ||
- org.openrewrite.java.spring.framework.MigrateSpringAssert | ||
|
||
--- | ||
type: specs.openrewrite.org/v1beta/recipe | ||
name: org.openrewrite.java.spring.framework.MigrateSpringAssert | ||
displayName: Migrate removed Spring `Assert` methods | ||
description: Assert methods without a message argument have been removed in Spring Framework 6.0. | ||
recipeList: | ||
- org.openrewrite.java.AddLiteralMethodArgument: | ||
methodPattern: org.springframework.util.Assert state(boolean) | ||
argumentIndex: 1 | ||
literal: must be true | ||
- org.openrewrite.java.AddLiteralMethodArgument: | ||
methodPattern: org.springframework.util.Assert isTrue(boolean) | ||
argumentIndex: 1 | ||
literal: must be true | ||
- org.openrewrite.java.AddLiteralMethodArgument: | ||
methodPattern: org.springframework.util.Assert isNull(java.lang.Object) | ||
argumentIndex: 1 | ||
literal: must be null | ||
- org.openrewrite.java.AddLiteralMethodArgument: | ||
methodPattern: org.springframework.util.Assert notNull(java.lang.Object) | ||
argumentIndex: 1 | ||
literal: must not be null | ||
- org.openrewrite.java.AddLiteralMethodArgument: | ||
methodPattern: org.springframework.util.Assert hasLength(java.lang.String) | ||
argumentIndex: 1 | ||
literal: must have length; it must not be null or empty | ||
- org.openrewrite.java.AddLiteralMethodArgument: | ||
methodPattern: org.springframework.util.Assert hasText(java.lang.String) | ||
argumentIndex: 1 | ||
literal: must have text; it must not be null, empty, or blank | ||
- org.openrewrite.java.AddLiteralMethodArgument: | ||
methodPattern: org.springframework.util.Assert doesNotContain(java.lang.String, java.lang.String) | ||
argumentIndex: 2 | ||
literal: must not contain the substring | ||
- org.openrewrite.java.AddLiteralMethodArgument: | ||
methodPattern: org.springframework.util.Assert notEmpty(java.lang.Object[]) | ||
argumentIndex: 1 | ||
literal: must not be empty | ||
- org.openrewrite.java.AddLiteralMethodArgument: | ||
methodPattern: org.springframework.util.Assert noNullElements(java.lang.Object[]) | ||
argumentIndex: 1 | ||
literal: must not contain any null elements | ||
- org.openrewrite.java.AddLiteralMethodArgument: | ||
methodPattern: org.springframework.util.Assert noNullElements(java.util.Collection) | ||
argumentIndex: 1 | ||
literal: must not be empty | ||
- org.openrewrite.java.AddLiteralMethodArgument: | ||
methodPattern: org.springframework.util.Assert notEmpty(java.util.Map) | ||
argumentIndex: 1 | ||
literal: must not be empty |
60 changes: 60 additions & 0 deletions
60
src/test/java/org/openrewrite/java/spring/framework/MigrateSpringAssertTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 org.openrewrite.java.spring.framework; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.openrewrite.DocumentExample; | ||
import org.openrewrite.InMemoryExecutionContext; | ||
import org.openrewrite.java.JavaParser; | ||
import org.openrewrite.test.RecipeSpec; | ||
import org.openrewrite.test.RewriteTest; | ||
|
||
import static org.openrewrite.java.Assertions.java; | ||
|
||
class MigrateSpringAssertTest implements RewriteTest { | ||
|
||
@Override | ||
public void defaults(RecipeSpec spec) { | ||
spec.recipeFromResources("org.openrewrite.java.spring.framework.MigrateSpringAssert") | ||
.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "spring-core-5")); | ||
} | ||
|
||
@Test | ||
@DocumentExample | ||
void migrateSpringAssert() { | ||
rewriteRun( | ||
//language=java | ||
java( | ||
""" | ||
class A { | ||
void test() { | ||
org.springframework.util.Assert.state(true); | ||
org.springframework.util.Assert.isTrue(true); | ||
} | ||
} | ||
""", | ||
""" | ||
class A { | ||
void test() { | ||
org.springframework.util.Assert.state(true, "must be true"); | ||
org.springframework.util.Assert.isTrue(true, "must be true"); | ||
} | ||
} | ||
""" | ||
) | ||
); | ||
} | ||
} |