1616package io .moderne .devcenter ;
1717
1818import io .moderne .devcenter .table .UpgradesAndMigrations ;
19+ import org .intellij .lang .annotations .Language ;
1920import org .junit .jupiter .api .BeforeEach ;
2021import org .junit .jupiter .api .Test ;
2122import org .junit .jupiter .params .ParameterizedTest ;
3738import static io .moderne .devcenter .JavaVersionUpgrade .Measure .Java8Plus ;
3839import static org .assertj .core .api .Assertions .assertThat ;
3940import static org .assertj .core .api .Assertions .assertThatThrownBy ;
41+ import static org .assertj .core .api .Assertions .tuple ;
42+ import static org .openrewrite .gradle .Assertions .buildGradle ;
43+ import static org .openrewrite .gradle .toolingapi .Assertions .withToolingApi ;
4044import static org .openrewrite .java .Assertions .java ;
4145import static org .openrewrite .java .Assertions .version ;
4246
@@ -199,7 +203,7 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
199203 // Load io.moderne.devcenter classes (including UpgradeMigrationCard) in this classloader
200204 // to ensure they are different from the ones in the test classloader
201205 if (name .startsWith ("io.moderne.devcenter." ) &&
202- !name .startsWith ("io.moderne.devcenter.DevCenter" )) {
206+ !name .startsWith ("io.moderne.devcenter.DevCenter" )) {
203207 // Get the resource path for the class
204208 String resourcePath = name .replace ('.' , '/' ) + ".class" ;
205209 try (var inputStream = getClass ().getClassLoader ().getResourceAsStream (resourcePath )) {
@@ -231,7 +235,7 @@ public String getDisplayName() {
231235 @ Override
232236 public String getDescription () {
233237 return "Simulates `DeclarativeRecipe`, which is parent loaded and contains " +
234- "child loaded sub-recipes." ;
238+ "child loaded sub-recipes." ;
235239 }
236240
237241 @ Override
@@ -241,4 +245,68 @@ public List<Recipe> getRecipeList() {
241245 })
242246 );
243247 }
248+
249+ @ Test
250+ void devcenterWithMultipleLibraryUpgradeRecipesHasCorrectData () {
251+ @ Language ("yaml" ) String recipe = """
252+ type: specs.openrewrite.org/v1beta/recipe
253+ name: io.moderne.devcenter.TwoLibraryUpgrades
254+ displayName: Starter DevCenter library version upgrade card
255+ description: Upgrade library versions.
256+ recipeList:
257+ - io.moderne.devcenter.LibraryUpgrade:
258+ cardName: Move to Spring Boot 3.5.0
259+ groupIdPattern: org.springframework.boot
260+ artifactIdPattern: '*'
261+ version: 3.5.0
262+ upgradeRecipe: io.moderne.java.spring.boot3.UpgradeSpringBoot_3_5
263+ - io.moderne.devcenter.LibraryUpgrade:
264+ cardName: Move to commons collections 3.2.2
265+ groupIdPattern: commons-collections
266+ artifactIdPattern: commons-collections
267+ version: 3.2.2
268+ """ ;
269+ rewriteRun (
270+ spec ->
271+ spec .recipeFromYaml (recipe , "io.moderne.devcenter.TwoLibraryUpgrades" )
272+ .beforeRecipe (withToolingApi ())
273+ .afterRecipe (after -> assertThat (after .getDataTableRows ("io.moderne.devcenter.table.UpgradesAndMigrations" ))
274+ .extracting ("card" , "ordinal" , "value" , "currentMinimumVersion" )
275+ .containsExactly (
276+ tuple ("Move to Spring Boot 3.5.0" , 0 , "Major" , "2.7.18" ),
277+ tuple ("Move to commons collections 3.2.2" , 0 , "Major" , "2.0" )
278+ )),
279+ //language=Groovy
280+ buildGradle (
281+ """
282+ plugins {
283+ id "java"
284+ id 'org.springframework.boot' version '2.7.18'
285+ id 'io.spring.dependency-management' version '1.1.7'
286+ }
287+ repositories {
288+ mavenCentral()
289+ }
290+ dependencies {
291+ implementation "org.springframework.boot:spring-boot-starter-web"
292+ implementation "commons-collections:commons-collections:2.0"
293+ }
294+ """ ,
295+ """
296+ plugins {
297+ id "java"
298+ id 'org.springframework.boot' version '2.7.18'
299+ id 'io.spring.dependency-management' version '1.1.7'
300+ }
301+ repositories {
302+ mavenCentral()
303+ }
304+ dependencies {
305+ /*~~(org.springframework.boot:spring-boot:2.7.18,org.springframework.boot:spring-boot-autoconfigure:2.7.18,org.springframework.boot:spring-boot-starter-logging:2.7.18,org.springframework.boot:spring-boot-starter-web:2.7.18,org.springframework.boot:spring-boot-starter:2.7.18,org.springframework.boot:spring-boot-starter-tomcat:2.7.18,org.springframework.boot:spring-boot-starter-json:2.7.18)~~>*/implementation "org.springframework.boot:spring-boot-starter-web"
306+ /*~~(commons-collections:commons-collections:2.0)~~>*/implementation "commons-collections:commons-collections:2.0"
307+ }
308+ """
309+ )
310+ );
311+ }
244312}
0 commit comments