11package jenkins .plugins .office365connector ;
22
3- import static org .assertj .core .api .Assertions .assertThat ;
4- import static org .mockito .Mockito .mock ;
5- import static org .mockito .Mockito .mockStatic ;
6- import static org .mockito .Mockito .when ;
7-
8- import java .util .List ;
9-
103import hudson .model .AbstractBuild ;
114import hudson .model .AbstractProject ;
125import hudson .model .TaskListener ;
6+ import jenkins .plugins .office365connector .helpers .ReflectionHelper ;
137import jenkins .plugins .office365connector .helpers .SCMHeadBuilder ;
148import jenkins .plugins .office365connector .model .CardAction ;
159import jenkins .scm .api .SCMHead ;
1610import jenkins .scm .api .metadata .ContributorMetadataAction ;
1711import jenkins .scm .api .metadata .ObjectMetadataAction ;
18- import mockit .internal .reflection .FieldReflection ;
19- import mockit .internal .reflection .MethodReflection ;
2012import org .apache .commons .lang .StringUtils ;
2113import org .jenkinsci .plugins .displayurlapi .DisplayURLProvider ;
22- import org .junit .After ;
23- import org .junit .Before ;
24- import org .junit .Test ;
14+ import org .junit .jupiter . api . AfterEach ;
15+ import org .junit .jupiter . api . BeforeEach ;
16+ import org .junit .jupiter . api . Test ;
2517import org .mockito .MockedStatic ;
2618
27- public class ActionableBuilderTest {
19+ import java .util .List ;
20+
21+ import static org .hamcrest .MatcherAssert .assertThat ;
22+ import static org .hamcrest .Matchers .empty ;
23+ import static org .hamcrest .Matchers .equalTo ;
24+ import static org .hamcrest .Matchers .hasSize ;
25+ import static org .mockito .Mockito .mock ;
26+ import static org .mockito .Mockito .mockStatic ;
27+ import static org .mockito .Mockito .when ;
28+
29+ class ActionableBuilderTest {
2830
2931 private static final String JOB_URL = "http://localhost/job/myFirstJob/167/display/redirect" ;
3032
@@ -37,8 +39,8 @@ public class ActionableBuilderTest {
3739
3840 private MockedStatic <DisplayURLProvider > displayUrlProviderStatic ;
3941
40- @ Before
41- public void setUp () {
42+ @ BeforeEach
43+ void setUp () {
4244 run = mock (AbstractBuild .class );
4345 taskListener = mock (TaskListener .class );
4446
@@ -52,13 +54,13 @@ public void setUp() {
5254 displayUrlProviderStatic .when (DisplayURLProvider ::get ).thenReturn (displayURLProvider );
5355 }
5456
55- @ After
56- public void tearDown () {
57+ @ AfterEach
58+ void tearDown () {
5759 displayUrlProviderStatic .close ();
5860 }
5961
6062 @ Test
61- public void buildActionable_OnEmptyAction_ReturnsEmptyList () {
63+ void buildActionable_OnEmptyAction_ReturnsEmptyList () {
6264
6365 // given
6466 // from @Before
@@ -67,26 +69,26 @@ public void buildActionable_OnEmptyAction_ReturnsEmptyList() {
6769 List <CardAction > potentialActions = actionableBuilder .buildActionable ();
6870
6971 // then
70- assertThat (potentialActions ). hasSize (1 );
72+ assertThat (potentialActions , hasSize (1 ) );
7173 CardAction potentialAction = potentialActions .get (0 );
72- assertThat (potentialAction .getName ()). isEqualTo ("View Build" );
74+ assertThat (potentialAction .getName (), equalTo ("View Build" ) );
7375 }
7476
7577 @ Test
76- public void pullRequestActionable_OnNoSCM_DoesNotAddFact () throws Throwable {
78+ void pullRequestActionable_OnNoSCM_DoesNotAddFact () {
7779
7880 // given
7981 // from @Before
8082
8183 // when
82- MethodReflection . invokeWithCheckedThrows (actionableBuilder . getClass (), actionableBuilder , "pullRequestActionable" , new Class []{} );
84+ ReflectionHelper . invokeMethod (actionableBuilder , "pullRequestActionable" );
8385
8486 // then
85- assertThat (factsBuilder .collect ()). isEmpty ( );
87+ assertThat (factsBuilder .collect (), empty () );
8688 }
8789
8890 @ Test
89- public void pullRequestActionable_OnPureChangeRequestSCMHead_DoesNotAddFact () throws Throwable {
91+ void pullRequestActionable_OnPureChangeRequestSCMHead_DoesNotAddFact () {
9092
9193 // given
9294 // from @Before
@@ -101,15 +103,15 @@ public void pullRequestActionable_OnPureChangeRequestSCMHead_DoesNotAddFact() th
101103 when (job .getAction (ObjectMetadataAction .class )).thenReturn (null );
102104
103105 // when
104- MethodReflection . invokeWithCheckedThrows (actionableBuilder . getClass (), actionableBuilder , "pullRequestActionable" , new Class []{} );
106+ ReflectionHelper . invokeMethod (actionableBuilder , "pullRequestActionable" );
105107 }
106108
107109 // then
108- assertThat (factsBuilder .collect ()). isEmpty ( );
110+ assertThat (factsBuilder .collect (), empty () );
109111 }
110112
111113 @ Test
112- public void pullRequestActionable_OnContributorMetadataAction_AddsFact () throws Throwable {
114+ void pullRequestActionable_OnContributorMetadataAction_AddsFact () {
113115
114116 // given
115117 // from @Before
@@ -127,18 +129,18 @@ public void pullRequestActionable_OnContributorMetadataAction_AddsFact() throws
127129 when (job .getAction (ObjectMetadataAction .class )).thenReturn (objectMetadataAction );
128130
129131 // when
130- MethodReflection . invokeWithCheckedThrows (actionableBuilder . getClass (), actionableBuilder , "pullRequestActionable" , new Class []{} );
132+ ReflectionHelper . invokeMethod (actionableBuilder , "pullRequestActionable" );
131133 }
132134
133135 // then
134- assertThat (factsBuilder .collect ()). hasSize (1 );
136+ assertThat (factsBuilder .collect (), hasSize (1 ) );
135137
136- List <CardAction > potentialActions = FieldReflection . getFieldValue (actionableBuilder . getClass (). getDeclaredField ( "potentialActions" ), actionableBuilder );
137- assertThat (potentialActions ). hasSize (1 );
138+ List <CardAction > potentialActions = ReflectionHelper . getField (actionableBuilder , "potentialActions" );
139+ assertThat (potentialActions , hasSize (1 ) );
138140 }
139141
140142 @ Test
141- public void pullRequestActionable_OnObjectMetadataAction_DoesNotAddFact () throws Throwable {
143+ void pullRequestActionable_OnObjectMetadataAction_DoesNotAddFact () {
142144
143145 // given
144146 // from @Before
@@ -157,19 +159,19 @@ public void pullRequestActionable_OnObjectMetadataAction_DoesNotAddFact() throws
157159 when (job .getAction (ContributorMetadataAction .class )).thenReturn (contributorMetadataAction );
158160
159161 // when
160- MethodReflection . invokeWithCheckedThrows (actionableBuilder . getClass (), actionableBuilder , "pullRequestActionable" , new Class []{} );
162+ ReflectionHelper . invokeMethod (actionableBuilder , "pullRequestActionable" );
161163 }
162164
163165
164166 // then
165- assertThat (factsBuilder .collect ()). hasSize (1 );
167+ assertThat (factsBuilder .collect (), hasSize (1 ) );
166168
167- List <CardAction > potentialActions = FieldReflection . getFieldValue (actionableBuilder . getClass (). getDeclaredField ( "potentialActions" ), actionableBuilder );
168- assertThat (potentialActions ). isEmpty ( );
169+ List <CardAction > potentialActions = ReflectionHelper . getField (actionableBuilder , "potentialActions" );
170+ assertThat (potentialActions , empty () );
169171 }
170172
171173 @ Test
172- public void pullRequestActionable_OnEmptyContributor_AdddFact () throws Throwable {
174+ void pullRequestActionable_OnEmptyContributor_AdddFact () {
173175
174176 // given
175177 // from @Before
@@ -188,7 +190,7 @@ public void pullRequestActionable_OnEmptyContributor_AdddFact() throws Throwable
188190 when (job .getAction (ContributorMetadataAction .class )).thenReturn (contributorMetadataAction );
189191
190192 // when
191- MethodReflection . invokeWithCheckedThrows (actionableBuilder . getClass (), actionableBuilder , "pullRequestActionable" , new Class []{} );
193+ ReflectionHelper . invokeMethod (actionableBuilder , "pullRequestActionable" );
192194 }
193195
194196 // then
@@ -201,7 +203,7 @@ public void pullRequestActionable_OnEmptyContributor_AdddFact() throws Throwable
201203 }
202204
203205 @ Test
204- public void pullRequestActionable_OnEmptyContributorDisplayName_AdddFact () throws Throwable {
206+ void pullRequestActionable_OnEmptyContributorDisplayName_AdddFact () {
205207
206208 // given
207209 // from @Before
@@ -220,7 +222,7 @@ public void pullRequestActionable_OnEmptyContributorDisplayName_AdddFact() throw
220222 when (job .getAction (ContributorMetadataAction .class )).thenReturn (contributorMetadataAction );
221223
222224 // when
223- MethodReflection . invokeWithCheckedThrows (actionableBuilder . getClass (), actionableBuilder , "pullRequestActionable" , new Class []{} );
225+ ReflectionHelper . invokeMethod (actionableBuilder , "pullRequestActionable" );
224226 }
225227
226228 // then
0 commit comments