1
1
package io .jenkins .plugins .forensics .util ;
2
2
3
3
import java .io .IOException ;
4
- import java .nio .file .Files ;
5
4
import java .util .ArrayList ;
6
5
import java .util .Arrays ;
7
6
import java .util .Collections ;
8
7
9
8
import org .assertj .core .api .ObjectAssert ;
10
- import org .junit .jupiter .api .Disabled ;
11
9
import org .junit .jupiter .api .Test ;
12
10
13
11
import org .jenkinsci .plugins .workflow .cps .CpsScmFlowDefinition ;
16
14
import hudson .EnvVars ;
17
15
import hudson .model .AbstractBuild ;
18
16
import hudson .model .AbstractProject ;
19
- import hudson .model .ItemGroup ;
20
17
import hudson .model .Job ;
21
18
import hudson .model .Run ;
22
19
import hudson .model .TaskListener ;
@@ -118,14 +115,18 @@ private SCM createScm(final String key) {
118
115
return first ;
119
116
}
120
117
121
- @ Disabled ("TODO rewrite to use JenkinsRule, not Mockito" )
122
118
@ Test
123
- void shouldResolveScmForPipelineWithFlowNode () throws IOException {
124
- WorkflowJob pipeline = createPipeline ();
125
- pipeline .setDefinition (createCpsFlowDefinition ());
119
+ void shouldResolveScmForPipelineWithFlowNode () {
120
+ var pipeline = mock (WorkflowJob .class );
126
121
127
- Run <?, ?> run = createRunFor (pipeline );
128
- assertThatScmOf (run ).isInstanceOf (SCM .class );
122
+ var empty = createRunFor (pipeline );
123
+ assertThatScmOf (empty ).isInstanceOf (NullSCM .class );
124
+
125
+ var flowDefinition = createCpsFlowDefinition ();
126
+ when (pipeline .getDefinition ()).thenReturn (flowDefinition );
127
+
128
+ var withScmFromFlowDefinition = createRunFor (pipeline );
129
+ assertThatScmOf (withScmFromFlowDefinition ).isInstanceOf (SCM .class );
129
130
}
130
131
131
132
private CpsScmFlowDefinition createCpsFlowDefinition () {
@@ -135,14 +136,6 @@ private CpsScmFlowDefinition createCpsFlowDefinition() {
135
136
return flowDefinition ;
136
137
}
137
138
138
- private WorkflowJob createPipeline () throws IOException {
139
- ItemGroup <?> group = mock (ItemGroup .class );
140
- WorkflowJob pipeline = new WorkflowJob (group , "stub" );
141
- when (group .getRootDirFor (any ())).thenReturn (Files .createTempFile ("" , "" ).toFile ());
142
- when (group .getFullName ()).thenReturn ("bla" );
143
- return pipeline ;
144
- }
145
-
146
139
@ Test
147
140
void shouldCreateNullBlamerForPipelineWithNoScm () {
148
141
Job <?, ?> pipeline = mock (Job .class , withSettings ().extraInterfaces (SCMTriggerItem .class ));
0 commit comments