From 7b652fcd6e2586985d594d2521461d572de76f9c Mon Sep 17 00:00:00 2001 From: Steve Hill Date: Fri, 18 Aug 2023 12:53:43 -0700 Subject: [PATCH] AddTeamToCodeowners DocumentExample --- .../github/AddTeamToCodeownersTest.java | 204 +++++++++--------- .../ArtifactIdTeamNameGeneratorTest.java | 8 +- 2 files changed, 107 insertions(+), 105 deletions(-) diff --git a/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java b/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java index 8da13db..1240bda 100644 --- a/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java +++ b/src/test/java/org/openrewrite/jenkins/github/AddTeamToCodeownersTest.java @@ -17,6 +17,7 @@ import org.intellij.lang.annotations.Language; import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; @@ -29,22 +30,22 @@ class AddTeamToCodeownersTest implements RewriteTest { @Language("xml") // language=xml private static final String POM = """ - - - org.jenkins-ci.plugins - plugin - 4.72 - - sample - 0.1 - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - """.stripIndent(); + + + org.jenkins-ci.plugins + plugin + 4.72 + + sample + 0.1 + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """.stripIndent(); @Override public void defaults(RecipeSpec spec) { @@ -52,110 +53,111 @@ public void defaults(RecipeSpec spec) { } @Test + @DocumentExample void shouldAddFileIfMissing() { rewriteRun( - pomXml(POM), - text(null, - """ - * @jenkinsci/sample-plugin-developers - """.stripIndent(), - s -> s.path(".github/CODEOWNERS") - ) + pomXml(POM), + text(null, + """ + * @jenkinsci/sample-plugin-developers + """.stripIndent(), + s -> s.path(".github/CODEOWNERS") + ) ); } @Test void shouldAddLineIfTeamNotDefinedForAll() { rewriteRun( - pomXml(POM), - text( - """ - # This is a comment. - * @global-owner1 @global-owner2 - *.js @js-owner #This is an inline comment. - /build/logs/ @doctocat - """.stripIndent(), - """ - # This is a comment. - * @jenkinsci/sample-plugin-developers - * @global-owner1 @global-owner2 - *.js @js-owner #This is an inline comment. - /build/logs/ @doctocat - """.stripIndent(), - s -> s.path(".github/CODEOWNERS") - ) + pomXml(POM), + text( + """ + # This is a comment. + * @global-owner1 @global-owner2 + *.js @js-owner #This is an inline comment. + /build/logs/ @doctocat + """.stripIndent(), + """ + # This is a comment. + * @jenkinsci/sample-plugin-developers + * @global-owner1 @global-owner2 + *.js @js-owner #This is an inline comment. + /build/logs/ @doctocat + """.stripIndent(), + s -> s.path(".github/CODEOWNERS") + ) ); } @Test void shouldHandleMultiModule() { rewriteRun( - mavenProject("sample-parent", - pomXml(""" - - org.example - sample-parent - 0.1 - pom - - plugin - different-plugin - - - """.stripIndent()), - mavenProject("plugin", - pomXml(""" - - - org.jenkins-ci.plugins - plugin - 4.72 - - my-plugin - 0.1 - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - """.stripIndent())), - mavenProject("different-plugin", - pomXml(""" - - - org.jenkins-ci.plugins - plugin - 4.72 - - different-plugin - 0.1 - - - repo.jenkins-ci.org - https://repo.jenkins-ci.org/public/ - - - - """.stripIndent()))), - text( - null, - """ - * @jenkinsci/sample-plugin-developers - """.stripIndent(), - s -> s.path(".github/CODEOWNERS") - )); + mavenProject("sample-parent", + pomXml(""" + + org.example + sample-parent + 0.1 + pom + + plugin + different-plugin + + + """.stripIndent()), + mavenProject("plugin", + pomXml(""" + + + org.jenkins-ci.plugins + plugin + 4.72 + + my-plugin + 0.1 + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """.stripIndent())), + mavenProject("different-plugin", + pomXml(""" + + + org.jenkins-ci.plugins + plugin + 4.72 + + different-plugin + 0.1 + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + """.stripIndent()))), + text( + null, + """ + * @jenkinsci/sample-plugin-developers + """.stripIndent(), + s -> s.path(".github/CODEOWNERS") + )); } @Test void shouldNoOpIfTeamAlreadyDefinedForAll() { rewriteRun( - pomXml(POM), - text( - "* @jenkinsci/sample-plugin-developers", - s -> s.path(".github/CODEOWNERS") - ) + pomXml(POM), + text( + "* @jenkinsci/sample-plugin-developers", + s -> s.path(".github/CODEOWNERS") + ) ); } } diff --git a/src/test/java/org/openrewrite/jenkins/github/ArtifactIdTeamNameGeneratorTest.java b/src/test/java/org/openrewrite/jenkins/github/ArtifactIdTeamNameGeneratorTest.java index 7559027..de3815d 100644 --- a/src/test/java/org/openrewrite/jenkins/github/ArtifactIdTeamNameGeneratorTest.java +++ b/src/test/java/org/openrewrite/jenkins/github/ArtifactIdTeamNameGeneratorTest.java @@ -25,10 +25,10 @@ class ArtifactIdTeamNameGeneratorTest { @ParameterizedTest @CsvSource({ - "commons-text-api,@jenkinsci/commons-text-api-plugin-developers", - "stashNotifier,@jenkinsci/stashnotifier-plugin-developers", - "aws-java-sdk-parent,@jenkinsci/aws-java-sdk-plugin-developers", - "warnings-ng-parent,@jenkinsci/warnings-ng-plugin-developers", + "commons-text-api,@jenkinsci/commons-text-api-plugin-developers", + "stashNotifier,@jenkinsci/stashnotifier-plugin-developers", + "aws-java-sdk-parent,@jenkinsci/aws-java-sdk-plugin-developers", + "warnings-ng-parent,@jenkinsci/warnings-ng-plugin-developers", }) void shouldGenerateExpectedTeamName(String artifactId, String expected) { String actual = generator.generate(new TeamNameInput(artifactId));