17
17
18
18
import org .junit .jupiter .api .Test ;
19
19
import org .junit .jupiter .params .ParameterizedTest ;
20
- import org .junit .jupiter .params .provider .ValueSource ;
20
+ import org .junit .jupiter .params .provider .MethodSource ;
21
21
import org .openrewrite .DocumentExample ;
22
22
import org .openrewrite .maven .tree .MavenResolutionResult ;
23
23
import org .openrewrite .maven .tree .Scope ;
24
- import org .openrewrite .test .RecipeSpec ;
25
24
import org .openrewrite .test .RewriteTest ;
26
25
26
+ import java .util .Arrays ;
27
+ import java .util .List ;
28
+
27
29
import static java .util .function .UnaryOperator .identity ;
28
30
import static org .assertj .core .api .Assertions .assertThat ;
29
31
import static org .openrewrite .java .Assertions .mavenProject ;
30
32
import static org .openrewrite .maven .Assertions .pomXml ;
31
33
32
34
class BouncyCastleTest implements RewriteTest {
33
35
34
- @ Override
35
- public void defaults (RecipeSpec spec ) {
36
- spec .recipeFromResource (
37
- "/META-INF/rewrite/bouncycastle-jdk18on.yml" ,
38
- "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On" );
36
+ static List <String > artifactBaseNames () {
37
+ return Arrays .asList ("bcprov" , "bcutil" , "bcpkix" , "bcmail" , "bcjmail" , "bcpg" , "bctls" );
39
38
}
40
39
41
40
@ DocumentExample
42
41
@ Test
43
42
void document () {
44
43
rewriteRun (
44
+ spec -> spec .recipeFromResource (
45
+ "/META-INF/rewrite/bouncycastle-jdk18on.yml" ,
46
+ "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On" ),
45
47
mavenProject ("project" ,
46
48
//language=xml
47
49
pomXml (
48
50
"""
49
51
<project>
50
52
<modelVersion>4.0.0</modelVersion>
51
-
52
53
<groupId>com.mycompany.app</groupId>
53
54
<artifactId>my-app</artifactId>
54
55
<version>1</version>
55
-
56
56
<dependencies>
57
57
<dependency>
58
58
<groupId>org.bouncycastle</groupId>
@@ -86,31 +86,68 @@ void document() {
86
86
);
87
87
}
88
88
89
+ @ ParameterizedTest
90
+ @ MethodSource ("artifactBaseNames" )
91
+ void jdk15onToJdk18on (String artifactBaseName ) {
92
+ runBouncyCastleArtifactUpgradeRecipe (
93
+ "/META-INF/rewrite/bouncycastle-jdk18on.yml" ,
94
+ "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On" ,
95
+ artifactBaseName ,
96
+ "jdk15on" ,
97
+ "jdk18on"
98
+ );
99
+ }
89
100
90
101
@ ParameterizedTest
91
- @ ValueSource (strings = {"bcprov" , "bcutil" , "bcpkix" , "bcmail" , "bcjmail" , "bcpg" , "bctls" })
92
- void updateBouncyCastle (String value ) {
102
+ @ MethodSource ("artifactBaseNames" )
103
+ void jdk15to18ToJdk18on (String artifactBaseName ) {
104
+ runBouncyCastleArtifactUpgradeRecipe (
105
+ "/META-INF/rewrite/bouncycastle-jdk18on.yml" ,
106
+ "org.openrewrite.java.migrate.BounceCastleFromJdk15OntoJdk18On" ,
107
+ artifactBaseName ,
108
+ "jdk15to18" ,
109
+ "jdk18on"
110
+ );
111
+ }
112
+
113
+ @ ParameterizedTest
114
+ @ MethodSource ("artifactBaseNames" )
115
+ void jdk15onToJdk15To18 (String artifactBaseName ) {
116
+ runBouncyCastleArtifactUpgradeRecipe (
117
+ "/META-INF/rewrite/bouncycastle-jdk15to18.yml" ,
118
+ "org.openrewrite.java.migrate.BouncyCastleFromJdk15OnToJdk15to18" ,
119
+ artifactBaseName ,
120
+ "jdk15on" ,
121
+ "jdk15to18"
122
+ );
123
+ }
124
+
125
+ void runBouncyCastleArtifactUpgradeRecipe (
126
+ String yamlFile ,
127
+ String recipe ,
128
+ String baseArtifactId ,
129
+ String originalArtifactSuffix ,
130
+ String expectedArtifactSuffix ) {
93
131
rewriteRun (
132
+ recipeSpec -> recipeSpec .recipeFromResource (yamlFile , recipe ),
94
133
mavenProject ("project" ,
95
134
//language=xml
96
135
pomXml (
97
- """
136
+ """
98
137
<project>
99
138
<modelVersion>4.0.0</modelVersion>
100
-
101
139
<groupId>com.mycompany.app</groupId>
102
140
<artifactId>my-app</artifactId>
103
141
<version>1</version>
104
-
105
142
<dependencies>
106
143
<dependency>
107
144
<groupId>org.bouncycastle</groupId>
108
- <artifactId>%s-jdk15on </artifactId>
145
+ <artifactId>%s-%s </artifactId>
109
146
<version>1.70</version>
110
147
</dependency>
111
148
</dependencies>
112
149
</project>
113
- """ .formatted (value ),
150
+ """ .formatted (baseArtifactId , originalArtifactSuffix ),
114
151
spec -> spec
115
152
.after (identity ())
116
153
.afterRecipe (doc -> assertThat (doc .getMarkers ().findFirst (MavenResolutionResult .class )
@@ -119,7 +156,7 @@ void updateBouncyCastle(String value) {
119
156
.singleElement ()
120
157
.satisfies (rd -> {
121
158
assertThat (rd .getGroupId ()).isEqualTo ("org.bouncycastle" );
122
- assertThat (rd .getArtifactId ()).isEqualTo (value + "-jdk18on" );
159
+ assertThat (rd .getArtifactId ()).isEqualTo (String . format ( "%s-%s" , baseArtifactId , expectedArtifactSuffix ) );
123
160
}))
124
161
)
125
162
)
0 commit comments