diff --git a/src/test/java/org/openrewrite/jenkins/AddPluginsBomTest.java b/src/test/java/org/openrewrite/jenkins/AddPluginsBomTest.java index a6efc2d..7a71c61 100644 --- a/src/test/java/org/openrewrite/jenkins/AddPluginsBomTest.java +++ b/src/test/java/org/openrewrite/jenkins/AddPluginsBomTest.java @@ -20,6 +20,7 @@ import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; +import static org.assertj.core.api.Assertions.assertThat; import static org.openrewrite.maven.Assertions.pomXml; class AddPluginsBomTest implements RewriteTest { @@ -51,7 +52,7 @@ void shouldNotAddBomIfNoDependencies() { - """.stripIndent() + """ )); } @@ -84,7 +85,7 @@ void shouldNotAddBomIfNoManagedDependencies() { - """.stripIndent() + """ )); } @@ -118,43 +119,13 @@ void shouldAddBomIfManagedDependencies() { - """.stripIndent(), - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - - 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 - - - - """.stripIndent() + """, + spec -> spec.after(after -> { + ModernizePluginTest.Versions versionsAfter = ModernizePluginTest.Versions.parse(after); + assertThat(versionsAfter.bomArtifactId()).isNotEmpty(); + assertThat(versionsAfter.bomVersion()).isNotEmpty(); + return after; + }) )); } @@ -197,12 +168,14 @@ void shouldLeaveBomVersionIfAlreadyPresent() { - """.stripIndent() + """ )); } @Test void shouldFixOutdatedPluginsBom() { + String bomArtifactId = "bom-2.346.x"; + String bomVersion = "1706.vc166d5f429f8"; // language=xml rewriteRun(pomXml( """ @@ -220,8 +193,8 @@ void shouldFixOutdatedPluginsBom() { io.jenkins.tools.bom - bom-2.346.x - 1706.vc166d5f429f8 + %s + %s pom import @@ -247,127 +220,43 @@ void shouldFixOutdatedPluginsBom() { - """.stripIndent(), - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - - 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 - - - - """.stripIndent() + """.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 shouldFixOutdatedPluginsBomPropertiesBelowManagedDependencies() { + ModernizePluginTest.Versions versionsBefore = new ModernizePluginTest.Versions( + "4.86", + "2.440.3", + "bom-2.346.x", + "1706.vc166d5f429f8" + ); // language=xml rewriteRun(pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - - - - io.jenkins.tools.bom - bom-2.346.x - 1706.vc166d5f429f8 - pom - import - - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - org.jenkins-ci.plugins - ant - - - - 2.440.3 - - - """.stripIndent(), - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - - - - 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 - - - - 2.440.3 - - - """.stripIndent() - )); + 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()); + return versionsAfter.asPomXml(); + }) + ) + ); } @Test void shouldFixOutdatedPluginsBomEvenIfUnused() { + String bomArtifactId = "bom-2.346.x"; + String bomVersion = "1706.vc166d5f429f8"; // language=xml rewriteRun(pomXml( """ @@ -385,45 +274,8 @@ void shouldFixOutdatedPluginsBomEvenIfUnused() { io.jenkins.tools.bom - bom-2.346.x - 1706.vc166d5f429f8 - pom - import - - - - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - - com.lmax - disruptor - 3.4.4 - - - - """.stripIndent(), - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - - - 2.440.3 - - - - - io.jenkins.tools.bom - bom-2.440.x - 3221.ve8f7b_fdd149d + %s + %s pom import @@ -443,7 +295,13 @@ void shouldFixOutdatedPluginsBomEvenIfUnused() { - """.stripIndent() + """.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; + }) )); } @@ -487,7 +345,7 @@ void shouldLeaveOtherBomsAlone() { - """.stripIndent() + """ )); } @@ -550,7 +408,7 @@ void shouldHandleCommentsInManagedDependency() { - """.stripIndent(), + """, """ @@ -605,7 +463,7 @@ void shouldHandleCommentsInManagedDependency() { - """.stripIndent() + """ )); } diff --git a/src/test/java/org/openrewrite/jenkins/CreateIndexJellyTest.java b/src/test/java/org/openrewrite/jenkins/CreateIndexJellyTest.java index d77b057..27d7fa0 100644 --- a/src/test/java/org/openrewrite/jenkins/CreateIndexJellyTest.java +++ b/src/test/java/org/openrewrite/jenkins/CreateIndexJellyTest.java @@ -61,7 +61,7 @@ void shouldCreateIndexJellyFromPomDescription() { - """.stripIndent() + """ ), text( null, @@ -70,7 +70,7 @@ void shouldCreateIndexJellyFromPomDescription() {
This is my plugin's description
- """.stripIndent(), + """, s -> s.path("src/main/resources/index.jelly") ) ); @@ -97,7 +97,7 @@ void shouldCreateIndexJellyEmptyDescription() { - """.stripIndent() + """ ), text( null, @@ -106,7 +106,7 @@ void shouldCreateIndexJellyEmptyDescription() {
my-plugin
- """.stripIndent(), + """, s -> s.path("src/main/resources/index.jelly") ) ); @@ -132,7 +132,7 @@ void shouldCreateIndexJellyNoDescription() { - """.stripIndent() + """ ), text( null, @@ -141,7 +141,7 @@ void shouldCreateIndexJellyNoDescription() {
my-plugin
- """.stripIndent(), + """, s -> s.path("src/main/resources/index.jelly") ) ); @@ -163,7 +163,7 @@ void shouldCreateMultipleNestedIndexJellies() { non-plugin - """.stripIndent()), + """), mavenProject("plugin", pomXml(""" @@ -182,7 +182,7 @@ void shouldCreateMultipleNestedIndexJellies() { - """.stripIndent()), + """), srcMainResources( text(null, """ @@ -190,7 +190,7 @@ void shouldCreateMultipleNestedIndexJellies() {
This is my plugin
- """.stripIndent(), + """, s -> s.path("index.jelly")) )), mavenProject("different-plugin", @@ -211,7 +211,7 @@ void shouldCreateMultipleNestedIndexJellies() { - """.stripIndent()), + """), srcMainResources( text(null, """ @@ -219,7 +219,7 @@ void shouldCreateMultipleNestedIndexJellies() {
This is my second, different plugin
- """.stripIndent(), + """, s -> s.path("index.jelly")) )), mavenProject("non-plugin", @@ -230,7 +230,7 @@ void shouldCreateMultipleNestedIndexJellies() { 0.1 This is my non-plugin - """.stripIndent()))) + """))) ); } } diff --git a/src/test/java/org/openrewrite/jenkins/DisableLocalResolutionForParentPomTest.java b/src/test/java/org/openrewrite/jenkins/DisableLocalResolutionForParentPomTest.java index bf59fb5..e3571ab 100644 --- a/src/test/java/org/openrewrite/jenkins/DisableLocalResolutionForParentPomTest.java +++ b/src/test/java/org/openrewrite/jenkins/DisableLocalResolutionForParentPomTest.java @@ -49,7 +49,7 @@ void shouldAddRelativePathIfMissing() { - """.stripIndent(), + """, """ @@ -68,7 +68,7 @@ void shouldAddRelativePathIfMissing() { - """.stripIndent() + """ )); } @@ -93,7 +93,7 @@ void shouldNoOpIfRelativePathAlreadyPresent() { - """.stripIndent() + """ )); } } diff --git a/src/test/java/org/openrewrite/jenkins/IsJenkinsPluginTest.java b/src/test/java/org/openrewrite/jenkins/IsJenkinsPluginTest.java index 1462344..c681886 100644 --- a/src/test/java/org/openrewrite/jenkins/IsJenkinsPluginTest.java +++ b/src/test/java/org/openrewrite/jenkins/IsJenkinsPluginTest.java @@ -51,7 +51,7 @@ void shouldKnowIfJenkinsPlugin() { - """.stripIndent(), + """, """ @@ -68,6 +68,6 @@ void shouldKnowIfJenkinsPlugin() { - """.stripIndent())); + """)); } } diff --git a/src/test/java/org/openrewrite/jenkins/JavaxAnnotationsToSpotBugsTest.java b/src/test/java/org/openrewrite/jenkins/JavaxAnnotationsToSpotBugsTest.java index 0462153..54a61d6 100644 --- a/src/test/java/org/openrewrite/jenkins/JavaxAnnotationsToSpotBugsTest.java +++ b/src/test/java/org/openrewrite/jenkins/JavaxAnnotationsToSpotBugsTest.java @@ -39,14 +39,14 @@ void shouldChangeClassName() { public class A { static @Nonnull String CONSTANT = "A"; } - """.stripIndent(), + """, """ import edu.umd.cs.findbugs.annotations.NonNull; public class A { static @NonNull String CONSTANT = "A"; } - """.stripIndent() + """ )); } @@ -62,7 +62,7 @@ public String key() { return null; } } - """.stripIndent(), + """, """ import edu.umd.cs.findbugs.annotations.CheckForNull; @@ -72,7 +72,7 @@ public String key() { return null; } } - """.stripIndent() + """ )); } @@ -95,7 +95,7 @@ public String key() { return Objects.equals(in, "a") ? "yes" : "no"; } } - """.stripIndent(), + """, """ import edu.umd.cs.findbugs.annotations.NonNull; @@ -112,7 +112,7 @@ public String key() { return Objects.equals(in, "a") ? "yes" : "no"; } } - """.stripIndent() + """ )); } } diff --git a/src/test/java/org/openrewrite/jenkins/ModernizePluginForJava8Test.java b/src/test/java/org/openrewrite/jenkins/ModernizePluginForJava8Test.java index 8f971c6..6d42f86 100644 --- a/src/test/java/org/openrewrite/jenkins/ModernizePluginForJava8Test.java +++ b/src/test/java/org/openrewrite/jenkins/ModernizePluginForJava8Test.java @@ -49,7 +49,7 @@ void shouldUseHttpsForRepositories() { - """.stripIndent(), + """, """ @@ -68,7 +68,7 @@ void shouldUseHttpsForRepositories() { - """.stripIndent() + """ )); } @@ -93,7 +93,7 @@ void shouldUpgradeParentTo4_51() { - """.stripIndent(), + """, """ @@ -112,7 +112,7 @@ void shouldUpgradeParentTo4_51() { - """.stripIndent() + """ )); } @@ -137,7 +137,7 @@ void shouldNotDowngradeParent() { - """.stripIndent() + """ )); } @@ -162,7 +162,7 @@ void shouldUpgradeJenkinsTo2_346_3() { - """.stripIndent(), + """, """ @@ -181,7 +181,7 @@ void shouldUpgradeJenkinsTo2_346_3() { - """.stripIndent() + """ )); } @@ -206,7 +206,7 @@ void shouldNotDowngradeJenkins() { - """.stripIndent() + """ )); } @@ -232,7 +232,7 @@ void shouldRemoveJavaLevelProperty() { - """.stripIndent(), + """, """ @@ -251,7 +251,7 @@ void shouldRemoveJavaLevelProperty() { - """.stripIndent() + """ )); } @@ -275,7 +275,7 @@ void shouldDisableLocalResolutionForParentPom() { - """.stripIndent(), + """, """ @@ -294,7 +294,7 @@ void shouldDisableLocalResolutionForParentPom() { - """.stripIndent() + """ )); } @@ -336,7 +336,7 @@ void shouldRemoveVersionsOnlyIfPresentInJenkinsBom() { - """.stripIndent(), + """, """ @@ -371,7 +371,7 @@ void shouldRemoveVersionsOnlyIfPresentInJenkinsBom() { - """.stripIndent() + """ )); } @@ -406,7 +406,7 @@ void shouldDoTheWorks() { - """.stripIndent(), + """, """ @@ -444,7 +444,7 @@ void shouldDoTheWorks() { - """.stripIndent() + """ )); } } diff --git a/src/test/java/org/openrewrite/jenkins/ReplaceLibrariesWithApiPluginTest.java b/src/test/java/org/openrewrite/jenkins/ReplaceLibrariesWithApiPluginTest.java index d7e3d2c..600ff04 100644 --- a/src/test/java/org/openrewrite/jenkins/ReplaceLibrariesWithApiPluginTest.java +++ b/src/test/java/org/openrewrite/jenkins/ReplaceLibrariesWithApiPluginTest.java @@ -69,7 +69,7 @@ void shouldWorkFromYamlDefinition() { - """.stripIndent(), + """, """ @@ -98,7 +98,7 @@ void shouldWorkFromYamlDefinition() { - """.stripIndent() + """ )); } @@ -133,7 +133,7 @@ void shouldReplaceDirectDependencyWithApiPlugin() { - """.stripIndent(), + """, """ @@ -162,7 +162,7 @@ void shouldReplaceDirectDependencyWithApiPlugin() { - """.stripIndent() + """ )); } @@ -198,7 +198,7 @@ void shouldExcludeTransitivesFromBundledLibrary() { - """.stripIndent(), + """, """ @@ -239,7 +239,7 @@ void shouldExcludeTransitivesFromBundledLibrary() { - """.stripIndent() + """ )); } } diff --git a/src/test/java/org/openrewrite/jenkins/UpgradeHtmlUnit_3_3_0Test.java b/src/test/java/org/openrewrite/jenkins/UpgradeHtmlUnit_3_3_0Test.java index 0b0d30e..c5c91be 100644 --- a/src/test/java/org/openrewrite/jenkins/UpgradeHtmlUnit_3_3_0Test.java +++ b/src/test/java/org/openrewrite/jenkins/UpgradeHtmlUnit_3_3_0Test.java @@ -23,7 +23,6 @@ import org.openrewrite.test.RewriteTest; import static org.openrewrite.java.Assertions.java; -import static org.openrewrite.java.Assertions.srcMainJava; class UpgradeHtmlUnit_3_3_0Test implements RewriteTest { @Language("java") @@ -33,7 +32,7 @@ class UpgradeHtmlUnit_3_3_0Test implements RewriteTest { public class WebClient { public HtmlPage getPage(String in) { return null; } } - """.stripIndent(); + """; @Language("java") private final String htmlPage2 = """ @@ -41,7 +40,7 @@ public class WebClient { public class HtmlPage { public HtmlForm getFormByName(String in) { return null; } } - """.stripIndent(); + """; @Language("java") private final String htmlForm2 = """ @@ -49,7 +48,7 @@ public class HtmlPage { public class HtmlForm { public HtmlInput getInputByName(String in) { return null; } } - """.stripIndent(); + """; @Language("java") private final String htmlInput2 = """ @@ -61,7 +60,7 @@ public void setAttribute(String attributeName, String attributeValue) {} public void setValueAttribute(String newValue) {} public void setValue(String newValue) {} } - """.stripIndent(); + """; @Language("java") private final String webClient3 = """ @@ -70,7 +69,7 @@ public void setValue(String newValue) {} public class WebClient { public HtmlPage getPage(String in) { return null; } } - """.stripIndent(); + """; @Language("java") private final String htmlPage3 = """ @@ -78,7 +77,7 @@ public class WebClient { public class HtmlPage { public HtmlForm getFormByName(String in) { return null; } } - """.stripIndent(); + """; @Language("java") private final String htmlForm3 = """ @@ -86,7 +85,7 @@ public class HtmlPage { public class HtmlForm { public HtmlInput getInputByName(String in) { return null; } } - """.stripIndent(); + """; @Language("java") private final String htmlInput3 = """ @@ -98,7 +97,7 @@ public void setAttribute(String attributeName, String attributeValue) {} public void setValueAttribute(String newValue) {} public void setValue(String newValue) {} } - """.stripIndent(); + """; @Override public void defaults(RecipeSpec spec) { @@ -110,17 +109,17 @@ public void defaults(RecipeSpec spec) { @DocumentExample void shouldUpdateHtmlUnit() { rewriteRun( - srcMainJava(spec -> spec.path("org/example/HtmlUnitUse.java")), - java(""" + java( + """ package org.example; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; - + import java.io.IOException; - + public class HtmlUnitUse { void run() throws IOException { try (WebClient webClient = new WebClient()) { @@ -135,17 +134,17 @@ void run() throws IOException { } } } - """.stripIndent(), + """, """ package org.example; - + import org.htmlunit.WebClient; import org.htmlunit.html.HtmlForm; import org.htmlunit.html.HtmlInput; import org.htmlunit.html.HtmlPage; - + import java.io.IOException; - + public class HtmlUnitUse { void run() throws IOException { try (WebClient webClient = new WebClient()) { @@ -160,7 +159,8 @@ void run() throws IOException { } } } - """.stripIndent()) + """ + ) ); } } diff --git a/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java b/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java index 319a5d0..6e6f667 100644 --- a/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java +++ b/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java @@ -47,7 +47,7 @@ class AddTeamToCodeownersTest implements RewriteTest { - """.stripIndent(); + """; @Override public void defaults(RecipeSpec spec) { @@ -197,23 +197,23 @@ void shouldNoOpIfTeamAlreadyDefinedForAll(String content) { void shouldNoOpIfInvalidTeamGenerated() { rewriteRun( pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - tool-labels-plugin - 0.1 - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - """), + """ + + + org.jenkins-ci.plugins + plugin + 4.86 + + tool-labels-plugin + 0.1 + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """), text( "* @global-owner1", s -> s.path(".github/CODEOWNERS").noTrim() @@ -225,23 +225,23 @@ void shouldNoOpIfInvalidTeamGenerated() { void shouldNoOpIfInvalidTeamGeneratedAndCodeownersFileAbsent() { rewriteRun( pomXml( - """ - - - org.jenkins-ci.plugins - plugin - 4.86 - - tool-labels-plugin - 0.1 - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - """) + """ + + + org.jenkins-ci.plugins + plugin + 4.86 + + tool-labels-plugin + 0.1 + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """) ); } diff --git a/src/test/java/org/openrewrite/jenkins/migrate/hudson/UtilGetPastTimeStringToTimeSpanStringTest.java b/src/test/java/org/openrewrite/jenkins/migrate/hudson/UtilGetPastTimeStringToTimeSpanStringTest.java index da39165..e165b9b 100644 --- a/src/test/java/org/openrewrite/jenkins/migrate/hudson/UtilGetPastTimeStringToTimeSpanStringTest.java +++ b/src/test/java/org/openrewrite/jenkins/migrate/hudson/UtilGetPastTimeStringToTimeSpanStringTest.java @@ -17,6 +17,7 @@ import org.intellij.lang.annotations.Language; import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; import org.openrewrite.java.JavaParser; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -24,6 +25,7 @@ import static org.openrewrite.java.Assertions.java; class UtilGetPastTimeStringToTimeSpanStringTest implements RewriteTest { + @Language("java") // language=java private final String hudsonUtil = """ @@ -39,7 +41,7 @@ public static String getPastTimeString(long duration) { return getTimeSpanString(duration); } } - """.stripIndent(); + """; @Override public void defaults(RecipeSpec spec) { @@ -47,6 +49,7 @@ public void defaults(RecipeSpec spec) { spec.recipeFromResource("/META-INF/rewrite/hudson-migrations.yml", "org.openrewrite.jenkins.migrate.hudson.UtilGetPastTimeStringToGetTimeSpanString"); } + @DocumentExample @Test void shouldReplaceFullyQualifiedMethodCall() { // language=java @@ -59,7 +62,7 @@ String format(long timestamp) { return hudson.Util.getPastTimeString(timestamp); } } - """.stripIndent(), + """, """ package org.example; @@ -68,7 +71,7 @@ String format(long timestamp) { return hudson.Util.getTimeSpanString(timestamp); } } - """.stripIndent() + """ )); } @@ -86,7 +89,7 @@ String format(long timestamp) { return Util.getPastTimeString(timestamp); } } - """.stripIndent(), + """, """ package org.example; @@ -97,7 +100,7 @@ String format(long timestamp) { return Util.getTimeSpanString(timestamp); } } - """.stripIndent() + """ )); } @@ -115,7 +118,7 @@ String format(long timestamp) { return getPastTimeString(timestamp); } } - """.stripIndent(), + """, """ package org.example; @@ -126,7 +129,7 @@ String format(long timestamp) { return getTimeSpanString(timestamp); } } - """.stripIndent() + """ )); } }