Skip to content

Commit 68ea59e

Browse files
BoykoAlextimtebeek
andauthored
Tests for duplicate dependencies (#165)
Co-authored-by: Tim te Beek <[email protected]>
1 parent 71f138b commit 68ea59e

File tree

1 file changed

+55
-12
lines changed

1 file changed

+55
-12
lines changed

src/test/java/org/openrewrite/java/dependencies/ChangeDependencyTest.java

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ void changeGradleDependency() {
4040
plugins {
4141
id "java-library"
4242
}
43-
43+
4444
repositories {
4545
mavenCentral()
4646
}
47-
47+
4848
dependencies {
4949
implementation "commons-lang:commons-lang:2.6"
5050
}
@@ -53,11 +53,11 @@ void changeGradleDependency() {
5353
plugins {
5454
id "java-library"
5555
}
56-
56+
5757
repositories {
5858
mavenCentral()
5959
}
60-
60+
6161
dependencies {
6262
implementation "org.apache.commons:commons-lang3:3.11"
6363
}
@@ -104,6 +104,49 @@ void changeMavenDependency() {
104104
);
105105
}
106106

107+
@Test
108+
void changeMavenDependencyToAlreadyPresent() {
109+
rewriteRun(
110+
spec -> spec.recipe(new ChangeDependency("commons-lang", "commons-lang", "org.apache.commons", "commons-lang3", "3.11.x", null, null, null)),
111+
//language=xml
112+
pomXml(
113+
"""
114+
<project>
115+
<groupId>com.example.app</groupId>
116+
<artifactId>my-app</artifactId>
117+
<version>1</version>
118+
<dependencies>
119+
<dependency>
120+
<groupId>org.apache.commons</groupId>
121+
<artifactId>commons-lang3</artifactId>
122+
<version>3.11</version>
123+
</dependency>
124+
<dependency>
125+
<groupId>commons-lang</groupId>
126+
<artifactId>commons-lang</artifactId>
127+
<version>2.6</version>
128+
</dependency>
129+
</dependencies>
130+
</project>
131+
""",
132+
"""
133+
<project>
134+
<groupId>com.example.app</groupId>
135+
<artifactId>my-app</artifactId>
136+
<version>1</version>
137+
<dependencies>
138+
<dependency>
139+
<groupId>org.apache.commons</groupId>
140+
<artifactId>commons-lang3</artifactId>
141+
<version>3.11</version>
142+
</dependency>
143+
</dependencies>
144+
</project>
145+
"""
146+
)
147+
);
148+
}
149+
107150
@Test
108151
void changeMavenDependencyManagementPomImport() {
109152
rewriteRun(
@@ -182,11 +225,11 @@ void doNotPinWhenNotVersionedGradle() {
182225
id 'org.springframework.boot' version '2.6.1'
183226
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
184227
}
185-
228+
186229
repositories {
187230
mavenCentral()
188231
}
189-
232+
190233
dependencies {
191234
runtimeOnly 'mysql:mysql-connector-java'
192235
}
@@ -197,11 +240,11 @@ void doNotPinWhenNotVersionedGradle() {
197240
id 'org.springframework.boot' version '2.6.1'
198241
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
199242
}
200-
243+
201244
repositories {
202245
mavenCentral()
203246
}
204-
247+
205248
dependencies {
206249
runtimeOnly 'com.mysql:mysql-connector-j'
207250
}
@@ -224,11 +267,11 @@ void pinWhenOverrideManagedVersionGradle() {
224267
id 'org.springframework.boot' version '2.6.1'
225268
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
226269
}
227-
270+
228271
repositories {
229272
mavenCentral()
230273
}
231-
274+
232275
dependencies {
233276
runtimeOnly 'mysql:mysql-connector-java'
234277
}
@@ -239,11 +282,11 @@ void pinWhenOverrideManagedVersionGradle() {
239282
id 'org.springframework.boot' version '2.6.1'
240283
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
241284
}
242-
285+
243286
repositories {
244287
mavenCentral()
245288
}
246-
289+
247290
dependencies {
248291
runtimeOnly 'com.mysql:mysql-connector-j:8.0.33'
249292
}

0 commit comments

Comments
 (0)