Skip to content

Commit

Permalink
When upgrading mockito also upgrade potential byte buddy dependencies (
Browse files Browse the repository at this point in the history
…#600)

* Upgrade byte buddy dependency

* Apply glob

* Inline variables and adopt `getFirst()`

---------

Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
Laurens-W and timtebeek authored Sep 12, 2024
1 parent e9497f1 commit 52f5318
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 40 deletions.
16 changes: 14 additions & 2 deletions src/main/resources/META-INF/rewrite/mockito.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ recipeList:
groupId: org.mockito
artifactId: "*"
newVersion: 5.x
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: net.bytebuddy
artifactId: byte-buddy*
newVersion: 1.15.x
- org.openrewrite.maven.RemoveDuplicateDependencies

---
Expand All @@ -59,6 +63,10 @@ recipeList:
groupId: org.mockito
artifactId: "*"
newVersion: 4.x
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: net.bytebuddy
artifactId: byte-buddy*
newVersion: 1.12.19
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.mockito.Mockito1to3Migration
Expand Down Expand Up @@ -143,8 +151,8 @@ recipeList:
- org.openrewrite.java.testing.mockito.CleanupMockitoImports
- org.openrewrite.java.testing.mockito.MockUtilsToStatic
- org.openrewrite.java.testing.junit5.MockitoJUnitToMockitoExtension
# https://github.com/openrewrite/rewrite-testing-frameworks/issues/360
# - org.openrewrite.java.testing.mockito.ReplacePowerMockito
# https://github.com/openrewrite/rewrite-testing-frameworks/issues/360
# - org.openrewrite.java.testing.mockito.ReplacePowerMockito
- org.openrewrite.java.testing.mockito.RetainStrictnessWarn
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.mockito
Expand All @@ -160,3 +168,7 @@ recipeList:
oldGroupId: org.mockito
oldArtifactId: mockito-all
newArtifactId: mockito-core
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: net.bytebuddy
artifactId: byte-buddy*
newVersion: 1.11.13
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.openrewrite.java.testing.mockito;

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

Expand All @@ -29,6 +30,7 @@ public void defaults(RecipeSpec spec) {
spec.recipeFromResources("org.openrewrite.java.testing.mockito.Mockito1to5Migration");
}

@DocumentExample
@Test
void inlineToCore() {
rewriteRun(
Expand All @@ -50,25 +52,22 @@ void inlineToCore() {
</dependencies>
</project>
""",
sourceSpecs -> sourceSpecs.after(after -> {
String version = Pattern.compile("<version>(5.+)</version>").matcher(after).results().reduce((a, b) -> b).orElseThrow().group(1);
return """
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>%s</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""".formatted(version);
})
spec -> spec.after(after -> """
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>%s</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""".formatted(Pattern.compile("<version>(5.+)</version>").matcher(after).results().findFirst().orElseThrow().group(1)))
)
);
}
Expand Down Expand Up @@ -100,25 +99,77 @@ void noDuplicates() {
</dependencies>
</project>
""",
sourceSpecs -> sourceSpecs.after(after -> {
String version = Pattern.compile("<version>(5.+)</version>").matcher(after).results().reduce((a, b) -> b).orElseThrow().group(1);
return """
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>%s</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""".formatted(version);
})
spec -> spec.after(after -> """
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>%s</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""".formatted(Pattern.compile("<version>(5.+)</version>").matcher(after).results().findFirst().orElseThrow().group(1)))
)
);
}

@Test
void shouldUpdateByteBuddy() {
rewriteRun(
//language=xml
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.12.19</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""",
spec -> spec.after(after -> """
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>%s</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>%s</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""".formatted(
Pattern.compile("<version>(5.+)</version>").matcher(after).results().findFirst().orElseThrow().group(1),
Pattern.compile("<version>(1.15.+)</version>").matcher(after).results().findFirst().orElseThrow().group(1)))
)
);
}
Expand Down

0 comments on commit 52f5318

Please sign in to comment.