Skip to content

Commit 74e5e66

Browse files
committed
add roller pom tests
1 parent 9e68b29 commit 74e5e66

File tree

3 files changed

+1007
-0
lines changed

3 files changed

+1007
-0
lines changed

plugins/codemodder-plugin-maven/src/test/java/io/codemodder/plugins/maven/MavenProviderTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,42 @@ void it_finds_correct_poms() throws IOException {
427427
}
428428
}
429429

430+
@Test
431+
void it_doesnt_butcher_roller_pom(@TempDir Path rollerTmpAppDir) throws IOException {
432+
433+
// copy the test files to temp so we can mess around with them
434+
Path rollerSrcDir = Path.of("src/test/resources/roller");
435+
Files.createDirectories(rollerTmpAppDir.resolve("app"));
436+
Files.copy(rollerSrcDir.resolve("app/pom.xml"), rollerTmpAppDir.resolve("app/pom.xml"));
437+
Files.copy(rollerSrcDir.resolve("pom.xml"), rollerTmpAppDir.resolve("pom.xml"));
438+
Path rollerJavaFile = rollerTmpAppDir.resolve("app/Foo.java");
439+
440+
// confirm we can find deps in the roller project
441+
MavenProvider provider = new MavenProvider();
442+
Collection<DependencyGAV> dependencies =
443+
provider.getAllDependencies(rollerTmpAppDir, rollerJavaFile);
444+
assertThat(dependencies).isNotEmpty();
445+
446+
// confirm it found an existing known dependency in the /app/pom.xml
447+
DependencyGAV mockito = DependencyGAV.createDefault("org.mockito", "mockito-core", "5.12.0");
448+
assertThat(dependencies).contains(mockito);
449+
450+
// add a new dependency and confirm it gets added correctly
451+
DependencyGAV newDep = DependencyGAV.createDefault("com.acme", "acme", "1.0.0");
452+
DependencyUpdateResult dependencyUpdateResult =
453+
provider.updateDependencies(rollerTmpAppDir, rollerJavaFile, List.of(newDep));
454+
List<CodeTFChangesetEntry> changes = dependencyUpdateResult.packageChanges();
455+
assertThat(changes).isNotEmpty();
456+
assertThat(changes.get(0).getPath()).isEqualTo("app/pom.xml");
457+
List<DependencyGAV> injectedPackages = dependencyUpdateResult.injectedPackages();
458+
assertThat(injectedPackages).contains(newDep);
459+
460+
// confirm the new dep is in the pom
461+
Collection<DependencyGAV> newDependencies =
462+
provider.getAllDependencies(rollerTmpAppDir, rollerJavaFile);
463+
assertThat(newDependencies).contains(newDep).contains(mockito);
464+
}
465+
430466
private static final String simplePomWithExistingSections =
431467
"""
432468
<?xml version="1.0" encoding="UTF-8"?>

0 commit comments

Comments
 (0)