1
1
package com .cloudbees .jenkins ;
2
2
3
3
import com .github .tomakehurst .wiremock .common .Slf4jNotifier ;
4
- import com .github .tomakehurst .wiremock .junit . WireMockRule ;
4
+ import com .github .tomakehurst .wiremock .junit5 . WireMockExtension ;
5
5
import hudson .Launcher ;
6
6
import hudson .model .AbstractBuild ;
7
7
import hudson .model .Build ;
13
13
import hudson .plugins .git .Revision ;
14
14
import hudson .plugins .git .util .BuildData ;
15
15
import hudson .util .VersionNumber ;
16
+ import jakarta .inject .Inject ;
16
17
import org .eclipse .jgit .lib .ObjectId ;
17
18
import org .jenkinsci .plugins .github .config .GitHubPluginConfig ;
18
- import org .jenkinsci .plugins .github .test .GHMockRule ;
19
- import org .jenkinsci .plugins .github .test .GHMockRule .FixedGHRepoNameTestContributor ;
20
- import org .jenkinsci .plugins .github .test .InjectJenkinsMembersRule ;
21
- import org .junit .Before ;
22
- import org .junit .Rule ;
23
- import org .junit .Test ;
24
- import org .junit .rules .RuleChain ;
25
- import org .junit .runner .RunWith ;
19
+ import org .jenkinsci .plugins .github .test .GitHubMockExtension ;
20
+ import org .jenkinsci .plugins .github .test .GitHubMockExtension .FixedGHRepoNameTestContributor ;
21
+ import org .junit .jupiter .api .BeforeEach ;
22
+ import org .junit .jupiter .api .Test ;
23
+ import org .junit .jupiter .api .extension .ExtendWith ;
24
+ import org .junit .jupiter .api .extension .RegisterExtension ;
26
25
import org .jvnet .hudson .test .Issue ;
27
26
import org .jvnet .hudson .test .JenkinsRule ;
28
27
import org .jvnet .hudson .test .TestBuilder ;
29
28
import org .jvnet .hudson .test .TestExtension ;
29
+ import org .jvnet .hudson .test .junit .jupiter .WithJenkins ;
30
30
import org .mockito .Mock ;
31
- import org .mockito .junit .MockitoJUnitRunner ;
32
-
33
- import jakarta .inject .Inject ;
31
+ import org .mockito .junit .jupiter .MockitoExtension ;
34
32
35
33
import static com .cloudbees .jenkins .GitHubSetCommitStatusBuilderTest .SOME_SHA ;
36
34
import static com .github .tomakehurst .wiremock .client .WireMock .postRequestedFor ;
45
43
*
46
44
* @author <a href="mailto:[email protected] ">Oleg Nenashev</a>
47
45
*/
48
- @ RunWith (MockitoJUnitRunner .class )
46
+ @ WithJenkins
47
+ @ ExtendWith (MockitoExtension .class )
49
48
public class GitHubCommitNotifierTest {
50
49
51
- @ Mock
50
+ @ Mock ( strictness = Mock . Strictness . LENIENT )
52
51
public BuildData data ;
53
52
54
- @ Mock
53
+ @ Mock ( strictness = Mock . Strictness . LENIENT )
55
54
public Revision rev ;
56
55
57
56
@ Inject
58
57
public GitHubPluginConfig config ;
59
58
60
- public JenkinsRule jRule = new JenkinsRule () ;
59
+ private JenkinsRule jRule ;
61
60
62
- @ Rule
63
- public RuleChain chain = RuleChain .outerRule (jRule ).around (new InjectJenkinsMembersRule (jRule , this ));
64
-
65
- @ Rule
66
- public GHMockRule github = new GHMockRule (
67
- new WireMockRule (
68
- wireMockConfig ().dynamicPort ().notifier (new Slf4jNotifier (true ))
69
- ))
61
+ @ RegisterExtension
62
+ static GitHubMockExtension github = new GitHubMockExtension (WireMockExtension .newInstance ()
63
+ .options (wireMockConfig ().dynamicPort ().notifier (new Slf4jNotifier (true ))))
70
64
.stubUser ()
71
65
.stubRepo ()
72
66
.stubStatuses ();
73
67
74
68
75
- @ Before
76
- public void before () throws Throwable {
77
- when (data .getLastBuiltRevision ()).thenReturn (rev );
78
- data .lastBuild = new hudson .plugins .git .util .Build (rev , rev , 0 , Result .SUCCESS );
79
- when (rev .getSha1 ()).thenReturn (ObjectId .fromString (SOME_SHA ));
69
+ @ BeforeEach
70
+ void before (JenkinsRule rule ) throws Throwable {
71
+ jRule = rule ;
72
+ jRule .getInstance ().getInjector ().injectMembers (this );
73
+
74
+ when (data .getLastBuiltRevision ()).thenReturn (rev );
75
+ data .lastBuild = new hudson .plugins .git .util .Build (rev , rev , 0 , Result .SUCCESS );
76
+ when (rev .getSha1 ()).thenReturn (ObjectId .fromString (SOME_SHA ));
80
77
}
81
78
82
79
@ Test
83
80
@ Issue ("JENKINS-23641" )
84
- public void testNoBuildData () throws Exception {
81
+ void testNoBuildData () throws Exception {
85
82
FreeStyleProject prj = jRule .createFreeStyleProject ("23641_noBuildData" );
86
83
prj .getPublishersList ().add (new GitHubCommitNotifier ());
87
84
Build b = prj .scheduleBuild2 (0 ).get ();
@@ -91,7 +88,7 @@ public void testNoBuildData() throws Exception {
91
88
92
89
@ Test
93
90
@ Issue ("JENKINS-23641" )
94
- public void testNoBuildRevision () throws Exception {
91
+ void testNoBuildRevision () throws Exception {
95
92
FreeStyleProject prj = jRule .createFreeStyleProject ();
96
93
prj .setScm (new GitSCM ("http://non.existent.git.repo.nowhere/repo.git" ));
97
94
prj .getPublishersList ().add (new GitHubCommitNotifier ());
@@ -103,7 +100,7 @@ public void testNoBuildRevision() throws Exception {
103
100
104
101
@ Test
105
102
@ Issue ("JENKINS-25312" )
106
- public void testMarkUnstableOnCommitNotifierFailure () throws Exception {
103
+ void testMarkUnstableOnCommitNotifierFailure () throws Exception {
107
104
FreeStyleProject prj = jRule .createFreeStyleProject ();
108
105
prj .getPublishersList ().add (new GitHubCommitNotifier (Result .UNSTABLE .toString ()));
109
106
Build b = prj .scheduleBuild2 (0 ).get ();
@@ -112,15 +109,15 @@ public void testMarkUnstableOnCommitNotifierFailure() throws Exception {
112
109
113
110
@ Test
114
111
@ Issue ("JENKINS-25312" )
115
- public void testMarkSuccessOnCommitNotifierFailure () throws Exception {
112
+ void testMarkSuccessOnCommitNotifierFailure () throws Exception {
116
113
FreeStyleProject prj = jRule .createFreeStyleProject ();
117
114
prj .getPublishersList ().add (new GitHubCommitNotifier (Result .SUCCESS .toString ()));
118
115
Build b = prj .scheduleBuild2 (0 ).get ();
119
116
jRule .assertBuildStatus (Result .SUCCESS , b );
120
117
}
121
118
122
119
@ Test
123
- public void shouldWriteStatusOnGH () throws Exception {
120
+ void shouldWriteStatusOnGH () throws Exception {
124
121
config .getConfigs ().add (github .serverConfig ());
125
122
FreeStyleProject prj = jRule .createFreeStyleProject ();
126
123
@@ -136,7 +133,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
136
133
137
134
prj .scheduleBuild2 (0 ).get ();
138
135
139
- github .service (). verify (1 , postRequestedFor (urlPathMatching (".*/" + SOME_SHA )));
136
+ github .verify (1 , postRequestedFor (urlPathMatching (".*/" + SOME_SHA )));
140
137
}
141
138
142
139
private Build safelyGenerateBuild (FreeStyleProject prj ) throws InterruptedException , java .util .concurrent .ExecutionException {
0 commit comments