From 683314518c2646dd3e15e2f39fb883714d62c915 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Mon, 11 Nov 2024 19:46:13 +0100 Subject: [PATCH] Format tests --- .../jenkins/AddPluginsBomTest.java | 895 +++++++++--------- .../org/openrewrite/jenkins/JenkinsTest.java | 10 +- 2 files changed, 463 insertions(+), 442 deletions(-) diff --git a/src/test/java/org/openrewrite/jenkins/AddPluginsBomTest.java b/src/test/java/org/openrewrite/jenkins/AddPluginsBomTest.java index 343558e..6e435e0 100644 --- a/src/test/java/org/openrewrite/jenkins/AddPluginsBomTest.java +++ b/src/test/java/org/openrewrite/jenkins/AddPluginsBomTest.java @@ -27,240 +27,253 @@ class AddPluginsBomTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { - spec.recipe(new AddPluginsBom()); + spec.recipe(new AddPluginsBom() + ); } @Test void shouldNotAddBomIfNoDependencies() { // language=xml - rewriteRun(pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - foo - - 2.440.3 - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - + rewriteRun( + pomXml( """ - )); + + + org.jenkins-ci.plugins + plugin + 4.86 + + + foo + + 2.440.3 + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """ + ) + ); } @Test void shouldNotAddBomIfNoManagedDependencies() { // language=xml - rewriteRun(pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - foo - - 2.440.3 - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - com.lmax - disruptor - 3.4.4 - - - + rewriteRun( + pomXml( """ - )); + + + org.jenkins-ci.plugins + plugin + 4.86 + + + foo + + 2.440.3 + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + com.lmax + disruptor + 3.4.4 + + + + """ + ) + ); } @Test @DocumentExample void shouldAddBomIfManagedDependencies() { // language=xml - rewriteRun(pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - foo - - 2.440.3 - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - org.jenkins-ci.plugins - ant - 1.9 - - - - """, - spec -> spec.after(after -> { - ModernizePluginTest.Versions versionsAfter = ModernizePluginTest.Versions.parse(after); - assertThat(versionsAfter.bomArtifactId()).isNotEmpty(); - assertThat(versionsAfter.bomVersion()).isNotEmpty(); - return after; - }) - )); + rewriteRun( + pomXml( + """ + + + org.jenkins-ci.plugins + plugin + 4.86 + + + foo + + 2.440.3 + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + org.jenkins-ci.plugins + ant + 1.9 + + + + """, + spec -> spec.after(after -> { + ModernizePluginTest.Versions versionsAfter = ModernizePluginTest.Versions.parse(after); + assertThat(versionsAfter.bomArtifactId()).isNotEmpty(); + assertThat(versionsAfter.bomVersion()).isNotEmpty(); + return after; + }) + ) + ); } @Test void shouldAddBomWithBaselineIfManagedDependencies() { // language=xml - rewriteRun(pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - foo - - 2.440 - ${jenkins.baseline}.3 - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - org.jenkins-ci.plugins - ant - 1.9 - - - - """, - spec -> spec.after(after -> { - ModernizePluginTest.Versions versionsAfter = ModernizePluginTest.Versions.parse(after); - assertThat(versionsAfter.bomArtifactId()).isEqualTo("bom-${jenkins.baseline}.x"); - assertThat(versionsAfter.bomVersion()).isNotEmpty(); - return after; - }) - )); + rewriteRun( + pomXml( + """ + + + org.jenkins-ci.plugins + plugin + 4.86 + + + foo + + 2.440 + ${jenkins.baseline}.3 + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + org.jenkins-ci.plugins + ant + 1.9 + + + + """, + spec -> spec.after(after -> { + ModernizePluginTest.Versions versionsAfter = ModernizePluginTest.Versions.parse(after); + assertThat(versionsAfter.bomArtifactId()).isEqualTo("bom-${jenkins.baseline}.x"); + assertThat(versionsAfter.bomVersion()).isNotEmpty(); + return after; + }) + ) + ); } @Test void shouldLeaveBomVersionIfAlreadyPresent() { // language=xml - rewriteRun(pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - foo - - 2.440.3 - - - - - io.jenkins.tools.bom - bom-2.440.x - 3221.ve8f7b_fdd149d - pom - import - - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - org.jenkins-ci.plugins - ant - - - + rewriteRun( + pomXml( """ - )); + + + org.jenkins-ci.plugins + plugin + 4.86 + + + foo + + 2.440.3 + + + + + io.jenkins.tools.bom + bom-2.440.x + 3221.ve8f7b_fdd149d + pom + import + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + org.jenkins-ci.plugins + ant + + + + """ + ) + ); } @Test void shouldLeaveBomWithBaselineVersionIfAlreadyPresent() { // language=xml - rewriteRun(pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 5.2 - - - foo - - 2.479 - ${jenkins.baseline}.1 - - - - - io.jenkins.tools.bom - bom-${jenkins.baseline}.x - 3613.v584fca_12cf5c - pom - import - - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - io.jenkins.plugins - commons-text-api - test - - - + rewriteRun( + pomXml( """ - )); + + + org.jenkins-ci.plugins + plugin + 5.2 + + + foo + + 2.479 + ${jenkins.baseline}.1 + + + + + io.jenkins.tools.bom + bom-${jenkins.baseline}.x + 3613.v584fca_12cf5c + pom + import + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + io.jenkins.plugins + commons-text-api + test + + + + """ + ) + ); } @Test @@ -268,58 +281,60 @@ void shouldFixOutdatedPluginsBom() { String bomArtifactId = "bom-2.346.x"; String bomVersion = "1706.vc166d5f429f8"; // language=xml - rewriteRun(pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - foo - - 2.440.3 - - - - - io.jenkins.tools.bom - %s - %s - pom - import - - - io.jenkins.tools.bom - bom-2.319.x - 1135.va_4eeca_ea_21c1 - pom - import - - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - org.jenkins-ci.plugins - ant - - - - """.formatted(bomArtifactId, bomVersion), - spec -> spec.after(after -> { - ModernizePluginTest.Versions versionsAfter = ModernizePluginTest.Versions.parse(after); - assertThat(versionsAfter.bomArtifactId()).isGreaterThan(bomArtifactId); - assertThat(versionsAfter.bomVersion()).isGreaterThan(bomVersion); - return after; - }) - )); + rewriteRun( + pomXml( + """ + + + org.jenkins-ci.plugins + plugin + 4.86 + + + foo + + 2.440.3 + + + + + io.jenkins.tools.bom + %s + %s + pom + import + + + io.jenkins.tools.bom + bom-2.319.x + 1135.va_4eeca_ea_21c1 + pom + import + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + org.jenkins-ci.plugins + ant + + + + """.formatted(bomArtifactId, bomVersion), + spec -> spec.after(after -> { + ModernizePluginTest.Versions versionsAfter = ModernizePluginTest.Versions.parse(after); + assertThat(versionsAfter.bomArtifactId()).isGreaterThan(bomArtifactId); + assertThat(versionsAfter.bomVersion()).isGreaterThan(bomVersion); + return after; + }) + ) + ); } @Test @@ -331,14 +346,19 @@ void shouldFixOutdatedPluginsBomPropertiesBelowManagedDependencies() { "1706.vc166d5f429f8" ); // language=xml - rewriteRun(pomXml( + rewriteRun( + pomXml( versionsBefore.asPomXml(), spec -> spec.after(after -> { ModernizePluginTest.Versions versionsAfter = ModernizePluginTest.Versions.parse(after); - assertThat(versionsAfter.parentVersion()).isGreaterThanOrEqualTo(versionsBefore.parentVersion()); - assertThat(versionsAfter.propertyVersion()).isGreaterThanOrEqualTo(versionsBefore.propertyVersion()); - assertThat(versionsAfter.bomArtifactId()).isGreaterThan(versionsBefore.bomArtifactId()); - assertThat(versionsAfter.bomVersion()).isGreaterThan(versionsBefore.bomVersion()); + assertThat(versionsAfter.parentVersion()).isGreaterThanOrEqualTo(versionsBefore.parentVersion() + ); + assertThat(versionsAfter.propertyVersion()).isGreaterThanOrEqualTo(versionsBefore.propertyVersion() + ); + assertThat(versionsAfter.bomArtifactId()).isGreaterThan(versionsBefore.bomArtifactId() + ); + assertThat(versionsAfter.bomVersion()).isGreaterThan(versionsBefore.bomVersion() + ); return versionsAfter.asPomXml(); }) ) @@ -350,215 +370,220 @@ void shouldFixOutdatedPluginsBomEvenIfUnused() { String bomArtifactId = "bom-2.346.x"; String bomVersion = "1706.vc166d5f429f8"; // language=xml - rewriteRun(pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - foo - - 2.440.3 - - - - - io.jenkins.tools.bom - %s - %s - pom - import - - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - com.lmax - disruptor - 3.4.4 - - - - """.formatted(bomArtifactId, bomVersion), - spec -> spec.after(after -> { - ModernizePluginTest.Versions versionsAfter = ModernizePluginTest.Versions.parse(after); - assertThat(versionsAfter.bomArtifactId()).isGreaterThan(bomArtifactId); - assertThat(versionsAfter.bomVersion()).isGreaterThan(bomVersion); - return after; - }) - )); + rewriteRun( + pomXml( + """ + + + org.jenkins-ci.plugins + plugin + 4.86 + + + foo + + 2.440.3 + + + + + io.jenkins.tools.bom + %s + %s + pom + import + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + com.lmax + disruptor + 3.4.4 + + + + """.formatted(bomArtifactId, bomVersion), + spec -> spec.after(after -> { + ModernizePluginTest.Versions versionsAfter = ModernizePluginTest.Versions.parse(after); + assertThat(versionsAfter.bomArtifactId()).isGreaterThan(bomArtifactId); + assertThat(versionsAfter.bomVersion()).isGreaterThan(bomVersion); + return after; + }) + ) + ); } @Test void shouldLeaveOtherBomsAlone() { // language=xml - rewriteRun(pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - foo - - 2.440.3 - - - - - org.testcontainers - testcontainers-bom - 1.18.3 - pom - import - - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - org.testcontainers - testcontainers - test - - - + rewriteRun( + pomXml( """ - )); + + + org.jenkins-ci.plugins + plugin + 4.86 + + + foo + + 2.440.3 + + + + + org.testcontainers + testcontainers-bom + 1.18.3 + pom + import + + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + org.testcontainers + testcontainers + test + + + + """ + ) + ); } @Test void shouldHandleCommentsInManagedDependency() { // language=xml - rewriteRun(pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - - golang - 1.5-SNAPSHOT - hpi + rewriteRun( + pomXml( + """ + + + org.jenkins-ci.plugins + plugin + 4.86 + + - - 2.346.3 - + golang + 1.5-SNAPSHOT + hpi - - - - org.jenkins-ci.plugins.workflow - workflow-api - 2.6 - test - - + + 2.346.3 + - - + - io.jenkins.tools.bom - bom-2.190.x - 16 - pom - import + org.jenkins-ci.plugins.workflow + workflow-api + 2.6 + test - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - + + + + + io.jenkins.tools.bom + bom-2.190.x + 16 + pom + import + + + - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - """, - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + - golang - 1.5-SNAPSHOT - hpi + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """, + """ + + + org.jenkins-ci.plugins + plugin + 4.86 + + - - 2.346.3 - + golang + 1.5-SNAPSHOT + hpi - - - - org.jenkins-ci.plugins.workflow - workflow-api - test - - + + 2.346.3 + - - + - io.jenkins.tools.bom - bom-2.346.x - 1763.v092b_8980a_f5e - pom - import + org.jenkins-ci.plugins.workflow + workflow-api + test - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - + + + + + io.jenkins.tools.bom + bom-2.346.x + 1763.v092b_8980a_f5e + pom + import + + + - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - """ + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + - )); + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """ + ) + ); } } diff --git a/src/test/java/org/openrewrite/jenkins/JenkinsTest.java b/src/test/java/org/openrewrite/jenkins/JenkinsTest.java index 3134d46..1a4ae21 100644 --- a/src/test/java/org/openrewrite/jenkins/JenkinsTest.java +++ b/src/test/java/org/openrewrite/jenkins/JenkinsTest.java @@ -34,17 +34,13 @@ class JenkinsTest { @ParameterizedTest @MethodSource("versionToBom") void shouldGenerateBomNameFromJenkinsVersion(String jenkinsVersion, String bomVersion) { - String actual = Jenkins.bomNameForJenkinsVersion(jenkinsVersion); - - assertThat(actual).isEqualTo(bomVersion); + assertThat(Jenkins.bomNameForJenkinsVersion(jenkinsVersion)).isEqualTo(bomVersion); } @Test void shouldGenerateBomNameWithBaseline() { - String actual = Jenkins.bomNameForJenkinsVersion("${jenkins.baseline}.3"); - assertThat(actual).isEqualTo("bom-${jenkins.baseline}.x"); - actual = Jenkins.bomNameForJenkinsVersion("${jenkins.baseline}.1"); - assertThat(actual).isEqualTo("bom-${jenkins.baseline}.x"); + assertThat(Jenkins.bomNameForJenkinsVersion("${jenkins.baseline}.3")).isEqualTo("bom-${jenkins.baseline}.x"); + assertThat(Jenkins.bomNameForJenkinsVersion("${jenkins.baseline}.1")).isEqualTo("bom-${jenkins.baseline}.x"); } static Stream versionToBom() {