From e64398f433067b998cde41e9733bb29cf6136dec Mon Sep 17 00:00:00 2001 From: Damian Szczepanik Date: Sat, 6 Apr 2024 23:46:34 +0200 Subject: [PATCH] Removes profile for jdk 17 & 21 (#115) --- .github/workflows/build.yml | 2 +- pom.xml | 46 ++++++++----------- .../model/conditions/TokenMacroCondition.java | 2 +- .../BuildHistoryManagerTest.java | 15 +----- .../buildhistorymanager/model/RuleTest.java | 2 +- .../model/actions/DeleteBuildActionIT.java | 22 ++------- .../conditions/BuildAgeRangeConditionIT.java | 22 ++------- .../BuildNumberRangeConditionIT.java | 24 ++-------- .../BuildNumberRangeConditionTest.java | 4 +- .../conditions/BuildResultConditionIT.java | 24 ++-------- .../conditions/TokenMacroConditionTest.java | 10 ++-- .../utils/DescriptorMocker.java | 23 ---------- .../buildhistorymanager/utils/JobBuilder.java | 4 +- .../buildhistorymanager/utils/RunStub.java | 4 +- 14 files changed, 47 insertions(+), 157 deletions(-) delete mode 100644 src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/DescriptorMocker.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e5348737..c86fc8b2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: build: strategy: matrix: - java: [ '11' ] + java: [ '11', '17', '21' ] os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ] runs-on: ${{ matrix.os }} diff --git a/pom.xml b/pom.xml index 513eb458..709726fd 100644 --- a/pom.xml +++ b/pom.xml @@ -1,11 +1,12 @@ - + 4.0.0 org.jenkins-ci.plugins plugin 4.75 - + pl.damianszczepanik @@ -49,8 +50,6 @@ 2.387.3 9.4 - 2.0.9 - **/*IT.java @@ -165,7 +164,7 @@ maven-hpi-plugin + so it is executed only during integration tests --> InjectionIT @@ -189,45 +188,39 @@ - org.jenkins-ci.plugins - structs - test - - - - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter-engine + ${junit.version} test - org.assertj - assertj-core - 3.25.3 + org.junit.jupiter + junit-jupiter-params + ${junit.version} test org.mockito mockito-core - 3.11.2 + 5.10.0 test org.powermock - powermock-api-mockito2 - ${powermock.version} + powermock-reflect + 2.0.9 test - org.powermock - powermock-module-junit4 - ${powermock.version} + org.assertj + assertj-core + 3.25.3 test + - org.powermock - powermock-reflect - ${powermock.version} + org.jenkins-ci.plugins + structs test @@ -245,7 +238,6 @@ workflow-job test - org.jenkins-ci.plugins.workflow workflow-step-api diff --git a/src/main/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/TokenMacroCondition.java b/src/main/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/TokenMacroCondition.java index 1378a6a9..a98d81a3 100644 --- a/src/main/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/TokenMacroCondition.java +++ b/src/main/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/TokenMacroCondition.java @@ -52,7 +52,7 @@ public boolean matches(Run run, RuleConfiguration configuration) { try { File workspace = run.getRootDir(); String evaluatedMacro = TokenMacro.expandAll(run, new FilePath(workspace), null, template); - LOG.warning(String.format("Evaluated macro '%s' to '%s'", template, evaluatedMacro)); + LOG.info(String.format("Evaluated macro '%s' to '%s'", template, evaluatedMacro)); return StringUtils.defaultString(value).equals(evaluatedMacro); } catch (InterruptedException | IOException | MacroEvaluationException e) { diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/BuildHistoryManagerTest.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/BuildHistoryManagerTest.java index ddc5fd94..9eb656c5 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/BuildHistoryManagerTest.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/BuildHistoryManagerTest.java @@ -1,22 +1,17 @@ package pl.damianszczepanik.jenkins.buildhistorymanager; import static org.assertj.core.api.Assertions.assertThat; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.IOException; import java.util.Arrays; import java.util.List; -import hudson.model.AbstractItem; import hudson.model.Job; import hudson.model.Run; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.reflect.Whitebox; import pl.damianszczepanik.jenkins.buildhistorymanager.model.ConditionBuilder.NegativeCondition; import pl.damianszczepanik.jenkins.buildhistorymanager.model.Rule; @@ -27,12 +22,6 @@ /** * @author Damian Szczepanik (damianszczepanik@github) */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({ - Run.class, // isKeepLog() - AbstractItem.class // getFullName() -}) -@PowerMockIgnore("com.thoughtworks.xstream.converters.extended.DurationConverter") public class BuildHistoryManagerTest { private List sampleRules; diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/RuleTest.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/RuleTest.java index a140831e..f3cc975a 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/RuleTest.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/RuleTest.java @@ -1,7 +1,7 @@ package pl.damianszczepanik.jenkins.buildhistorymanager.model; import static org.assertj.core.api.Assertions.assertThat; -import static org.powermock.api.mockito.PowerMockito.mock; +import static org.mockito.Mockito.mock; import static pl.damianszczepanik.jenkins.buildhistorymanager.model.ConditionBuilder.buildSampleConditions; import static pl.damianszczepanik.jenkins.buildhistorymanager.model.actions.ActionBuilder.buildSampleActions; diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/actions/DeleteBuildActionIT.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/actions/DeleteBuildActionIT.java index 2e0095e1..06745922 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/actions/DeleteBuildActionIT.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/actions/DeleteBuildActionIT.java @@ -5,19 +5,11 @@ import java.util.Collections; import java.util.List; -import hudson.model.AbstractItem; import hudson.model.Job; -import jenkins.model.Jenkins; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.jvnet.hudson.test.JenkinsRule; import pl.damianszczepanik.jenkins.buildhistorymanager.BuildHistoryManager; -import pl.damianszczepanik.jenkins.buildhistorymanager.descriptors.actions.DeleteBuildActionDescriptor; import pl.damianszczepanik.jenkins.buildhistorymanager.model.Rule; -import pl.damianszczepanik.jenkins.buildhistorymanager.utils.DescriptorMocker; import pl.damianszczepanik.jenkins.buildhistorymanager.utils.JobBuilder; import pl.damianszczepanik.jenkins.buildhistorymanager.utils.RunStub; @@ -25,18 +17,10 @@ * @author Damian Szczepanik (damianszczepanik@github) * @see documentation */ -@PrepareForTest({ - Jenkins.class, - AbstractItem.class // getFullName() -}) -@RunWith(PowerMockRunner.class) -@PowerMockIgnore("javax.xml.*") public class DeleteBuildActionIT { - @Before - public void setUp() { - new DescriptorMocker(new DeleteBuildActionDescriptor()); - } + @org.junit.Rule + public JenkinsRule r = new JenkinsRule(); @Test public void testDeletesArtifactsAction() throws IOException, InterruptedException { diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildAgeRangeConditionIT.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildAgeRangeConditionIT.java index 1f97193b..5c269928 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildAgeRangeConditionIT.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildAgeRangeConditionIT.java @@ -5,20 +5,12 @@ import java.util.Calendar; import java.util.List; -import hudson.model.AbstractItem; import hudson.model.Job; -import jenkins.model.Jenkins; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.jvnet.hudson.test.JenkinsRule; import pl.damianszczepanik.jenkins.buildhistorymanager.BuildHistoryManager; -import pl.damianszczepanik.jenkins.buildhistorymanager.descriptors.actions.DeleteBuildActionDescriptor; import pl.damianszczepanik.jenkins.buildhistorymanager.model.Rule; import pl.damianszczepanik.jenkins.buildhistorymanager.model.actions.DeleteArtifactsAction; -import pl.damianszczepanik.jenkins.buildhistorymanager.utils.DescriptorMocker; import pl.damianszczepanik.jenkins.buildhistorymanager.utils.JobBuilder; import pl.damianszczepanik.jenkins.buildhistorymanager.utils.RunStub; @@ -26,18 +18,10 @@ * @author Damian Szczepanik (damianszczepanik@github) * @see documentation */ -@PrepareForTest({ - Jenkins.class, - AbstractItem.class // getFullName() -}) -@RunWith(PowerMockRunner.class) -@PowerMockIgnore("javax.xml.*") public class BuildAgeRangeConditionIT { - @Before - public void setUp() { - new DescriptorMocker(new DeleteBuildActionDescriptor()); - } + @org.junit.Rule + public JenkinsRule r = new JenkinsRule(); @Test public void testBuildNumberRangeCondition() throws IOException, InterruptedException { diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildNumberRangeConditionIT.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildNumberRangeConditionIT.java index e475157c..7728a948 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildNumberRangeConditionIT.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildNumberRangeConditionIT.java @@ -4,20 +4,12 @@ import java.util.Arrays; import java.util.List; -import hudson.model.AbstractItem; import hudson.model.Job; -import jenkins.model.Jenkins; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.jvnet.hudson.test.JenkinsRule; import pl.damianszczepanik.jenkins.buildhistorymanager.BuildHistoryManager; -import pl.damianszczepanik.jenkins.buildhistorymanager.descriptors.actions.DeleteBuildActionDescriptor; import pl.damianszczepanik.jenkins.buildhistorymanager.model.Rule; import pl.damianszczepanik.jenkins.buildhistorymanager.model.actions.DeleteBuildAction; -import pl.damianszczepanik.jenkins.buildhistorymanager.utils.DescriptorMocker; import pl.damianszczepanik.jenkins.buildhistorymanager.utils.JobBuilder; import pl.damianszczepanik.jenkins.buildhistorymanager.utils.RunStub; @@ -25,19 +17,11 @@ * @author Damian Szczepanik (damianszczepanik@github) * @see documentation */ -@PrepareForTest({ - Jenkins.class, - AbstractItem.class // getFullName() -}) -@RunWith(PowerMockRunner.class) -@PowerMockIgnore("javax.xml.*") public class BuildNumberRangeConditionIT { - @Before - public void setUp() { - new DescriptorMocker(new DeleteBuildActionDescriptor()); - } - + @org.junit.Rule + public JenkinsRule r = new JenkinsRule(); + @Test public void testBuildNumberRangeCondition() throws IOException, InterruptedException { diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildNumberRangeConditionTest.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildNumberRangeConditionTest.java index 80589dab..5d1f5752 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildNumberRangeConditionTest.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildNumberRangeConditionTest.java @@ -1,8 +1,8 @@ package pl.damianszczepanik.jenkins.buildhistorymanager.model.conditions; import static org.assertj.core.api.Assertions.assertThat; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import hudson.model.Run; import org.junit.Test; diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildResultConditionIT.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildResultConditionIT.java index e9ccc073..d620b0af 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildResultConditionIT.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/BuildResultConditionIT.java @@ -5,21 +5,13 @@ import java.util.Collections; import java.util.List; -import hudson.model.AbstractItem; import hudson.model.Job; import hudson.model.Result; -import jenkins.model.Jenkins; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import org.jvnet.hudson.test.JenkinsRule; import pl.damianszczepanik.jenkins.buildhistorymanager.BuildHistoryManager; -import pl.damianszczepanik.jenkins.buildhistorymanager.descriptors.actions.DeleteBuildActionDescriptor; import pl.damianszczepanik.jenkins.buildhistorymanager.model.Rule; import pl.damianszczepanik.jenkins.buildhistorymanager.model.actions.DeleteBuildAction; -import pl.damianszczepanik.jenkins.buildhistorymanager.utils.DescriptorMocker; import pl.damianszczepanik.jenkins.buildhistorymanager.utils.JobBuilder; import pl.damianszczepanik.jenkins.buildhistorymanager.utils.RunStub; @@ -27,18 +19,10 @@ * @author Damian Szczepanik (damianszczepanik@github) * @see documentation */ -@PrepareForTest({ - Jenkins.class, - AbstractItem.class // getFullName() -}) -@RunWith(PowerMockRunner.class) -@PowerMockIgnore("javax.xml.*") public class BuildResultConditionIT { - - @Before - public void setUp() { - new DescriptorMocker(new DeleteBuildActionDescriptor()); - } + + @org.junit.Rule + public JenkinsRule r = new JenkinsRule(); @Test public void testBuildResultCondition() throws IOException, InterruptedException { diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/TokenMacroConditionTest.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/TokenMacroConditionTest.java index aae1456b..23c75295 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/TokenMacroConditionTest.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/conditions/TokenMacroConditionTest.java @@ -1,22 +1,17 @@ package pl.damianszczepanik.jenkins.buildhistorymanager.model.conditions; import static org.assertj.core.api.Assertions.assertThat; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.File; import hudson.model.Run; import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.modules.junit4.PowerMockRunner; /** * @author Damian Szczepanik (damianszczepanik@github) */ -@RunWith(PowerMockRunner.class) -@PowerMockIgnore("com.thoughtworks.xstream.converters.extended.DurationConverter") public class TokenMacroConditionTest { @Test @@ -103,6 +98,7 @@ private static Run mockRun() { File workspace = mock(File.class); when(workspace.getPath()).thenReturn("somePath"); when(run.getRootDir()).thenReturn(workspace); + when(run.getNumber()).thenReturn(13); return run; } } diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/DescriptorMocker.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/DescriptorMocker.java deleted file mode 100644 index 3d02ec3d..00000000 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/DescriptorMocker.java +++ /dev/null @@ -1,23 +0,0 @@ -package pl.damianszczepanik.jenkins.buildhistorymanager.utils; - -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.when; - -import hudson.model.Descriptor; -import jenkins.model.Jenkins; -import org.mockito.ArgumentMatchers; - -/** - * @author Damian Szczepanik (damianszczepanik@github) - */ -public class DescriptorMocker { - - public DescriptorMocker(Descriptor descriptor) { - mockStatic(Jenkins.class); - Jenkins jenkins = mock(Jenkins.class); - when(Jenkins.get()).thenReturn(jenkins); // for new Jenkins - when(Jenkins.getInstanceOrNull()).thenReturn(jenkins); // for old Jenkins - when(jenkins.getDescriptorOrDie(ArgumentMatchers.any())).thenReturn(descriptor); - } -} diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/JobBuilder.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/JobBuilder.java index 6b97070f..5d560703 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/JobBuilder.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/JobBuilder.java @@ -1,7 +1,7 @@ package pl.damianszczepanik.jenkins.buildhistorymanager.utils; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import hudson.model.Job; import hudson.model.Run; diff --git a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/RunStub.java b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/RunStub.java index 360add52..7a61f738 100644 --- a/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/RunStub.java +++ b/src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/utils/RunStub.java @@ -1,8 +1,8 @@ package pl.damianszczepanik.jenkins.buildhistorymanager.utils; import static org.assertj.core.api.Assertions.assertThat; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.File; import java.io.IOException;