diff --git a/src/test/java/io/jenkins/plugins/forensics/util/ScmResolverTest.java b/src/test/java/io/jenkins/plugins/forensics/util/ScmResolverTest.java index fc7e24a0..fbb25233 100644 --- a/src/test/java/io/jenkins/plugins/forensics/util/ScmResolverTest.java +++ b/src/test/java/io/jenkins/plugins/forensics/util/ScmResolverTest.java @@ -1,13 +1,11 @@ package io.jenkins.plugins.forensics.util; import java.io.IOException; -import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import org.assertj.core.api.ObjectAssert; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition; @@ -16,7 +14,6 @@ import hudson.EnvVars; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; -import hudson.model.ItemGroup; import hudson.model.Job; import hudson.model.Run; import hudson.model.TaskListener; @@ -118,14 +115,18 @@ private SCM createScm(final String key) { return first; } - @Disabled("TODO rewrite to use JenkinsRule, not Mockito") @Test - void shouldResolveScmForPipelineWithFlowNode() throws IOException { - WorkflowJob pipeline = createPipeline(); - pipeline.setDefinition(createCpsFlowDefinition()); + void shouldResolveScmForPipelineWithFlowNode() { + var pipeline = mock(WorkflowJob.class); - Run run = createRunFor(pipeline); - assertThatScmOf(run).isInstanceOf(SCM.class); + var empty = createRunFor(pipeline); + assertThatScmOf(empty).isInstanceOf(NullSCM.class); + + var flowDefinition = createCpsFlowDefinition(); + when(pipeline.getDefinition()).thenReturn(flowDefinition); + + var withScmFromFlowDefinition = createRunFor(pipeline); + assertThatScmOf(withScmFromFlowDefinition).isInstanceOf(SCM.class); } private CpsScmFlowDefinition createCpsFlowDefinition() { @@ -135,14 +136,6 @@ private CpsScmFlowDefinition createCpsFlowDefinition() { return flowDefinition; } - private WorkflowJob createPipeline() throws IOException { - ItemGroup group = mock(ItemGroup.class); - WorkflowJob pipeline = new WorkflowJob(group, "stub"); - when(group.getRootDirFor(any())).thenReturn(Files.createTempFile("", "").toFile()); - when(group.getFullName()).thenReturn("bla"); - return pipeline; - } - @Test void shouldCreateNullBlamerForPipelineWithNoScm() { Job pipeline = mock(Job.class, withSettings().extraInterfaces(SCMTriggerItem.class));