Skip to content

Commit 56b0da9

Browse files
Migrate tests to JUnit5
* Migrate annotations and imports * Migrate assertions * Remove public visibility for test classes and methods * Minor code cleanup
1 parent 95eb0e1 commit 56b0da9

10 files changed

Lines changed: 302 additions & 335 deletions

src/test/java/hudson/plugins/im/IMPublisherTest.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package hudson.plugins.im;
22

3-
import com.google.common.base.Function;
43
import com.google.common.collect.Iterables;
54
import com.google.common.collect.Iterators;
65
import com.google.common.collect.Maps;
@@ -14,29 +13,24 @@
1413
import hudson.model.User;
1514
import hudson.plugins.im.build_notify.DefaultBuildToChatNotifier;
1615
import hudson.scm.ChangeLogSet;
17-
import hudson.scm.NullSCM;
1816
import hudson.tasks.BuildStepDescriptor;
1917
import hudson.tasks.Publisher;
18+
import org.junit.jupiter.api.BeforeEach;
2019

21-
import java.io.IOException;
2220
import java.util.Collection;
2321
import java.util.Collections;
2422
import java.util.Iterator;
2523
import java.util.Map;
2624
import java.util.Set;
2725

28-
import org.junit.Before;
29-
import org.junit.Test;
30-
31-
import static org.junit.Assert.assertEquals;
32-
import static org.junit.Assert.assertFalse;
33-
import static org.junit.Assert.assertTrue;
26+
import org.junit.jupiter.api.Test;
3427

28+
import static org.junit.jupiter.api.Assertions.*;
3529
import static org.mockito.Mockito.mock;
3630
import static org.mockito.Mockito.when;
3731

3832
@SuppressWarnings("rawtypes")
39-
public class IMPublisherTest {
33+
class IMPublisherTest {
4034

4135
private IMPublisher imPublisher;
4236

@@ -53,10 +47,10 @@ public class IMPublisherTest {
5347
private BuildListener listener;
5448
private RangeSet rangeset;
5549

56-
@SuppressWarnings("unchecked")
57-
@Before
5850
// lot of ugly mocking going on here ...
59-
public void before() throws IOException {
51+
@SuppressWarnings("unchecked")
52+
@BeforeEach
53+
void setUp() {
6054

6155
this.imPublisher = new IMTestPublisher();
6256

@@ -140,18 +134,13 @@ private static void createPreviousNextRelationShip(AbstractBuild... builds) {
140134
* list.
141135
*/
142136
@Test
143-
public void testIncludeUpstreamCulprits() throws Exception {
137+
void testIncludeUpstreamCulprits() {
144138
/* Anticipating javax.mail.MessagingException and InterruptedException */
145139
Set<User> recipients = this.imPublisher.getNearestUpstreamCommitters(this.build, listener).keySet();
146140

147-
assertEquals(recipients.toString(), 2, recipients.size());
141+
assertEquals(2, recipients.size(), recipients.toString());
148142

149-
Iterable<String> userNamesIter = Iterables.transform(recipients, new Function<User, String>() {
150-
@Override
151-
public String apply(User from) {
152-
return from.toString();
153-
}
154-
});
143+
Iterable<String> userNamesIter = Iterables.transform(recipients, User::toString);
155144

156145
Set<String> userNames = Sets.newHashSet(userNamesIter);
157146

@@ -162,7 +151,7 @@ public String apply(User from) {
162151

163152
private static class IMTestPublisher extends IMPublisher {
164153
public IMTestPublisher() {
165-
super(Collections.<IMMessageTarget>emptyList(), NotificationStrategy.FAILURE_AND_FIXED.getDisplayName(),
154+
super(Collections.emptyList(), NotificationStrategy.FAILURE_AND_FIXED.getDisplayName(),
166155
true, true, true, true, true, new DefaultBuildToChatNotifier(), MatrixJobMultiplier.ALL);
167156
}
168157

@@ -172,7 +161,7 @@ protected String getPluginName() {
172161
}
173162

174163
@Override
175-
protected IMConnection getIMConnection() throws IMException {
164+
protected IMConnection getIMConnection() {
176165
return null;
177166
}
178167

src/test/java/hudson/plugins/im/MatrixNotificationTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package hudson.plugins.im;
22

3-
import hudson.Launcher;
43
import hudson.matrix.MatrixAggregator;
54
import hudson.matrix.MatrixBuild;
65
import hudson.matrix.MatrixConfiguration;
76
import hudson.model.AbstractBuild;
87
import hudson.model.AbstractProject;
98
import hudson.model.BuildListener;
9+
import org.junit.jupiter.api.BeforeEach;
1010

1111
import java.io.IOException;
1212

13-
import org.junit.Before;
14-
import org.junit.Test;
13+
import org.junit.jupiter.api.Test;
1514
import org.mockito.Mockito;
1615

1716
import static org.mockito.ArgumentMatchers.any;
@@ -26,15 +25,15 @@
2625
* @author kutzi
2726
*/
2827
@SuppressWarnings("rawtypes")
29-
public class MatrixNotificationTest {
28+
class MatrixNotificationTest {
3029

3130
private IMPublisher publisher;
3231
private BuildListener listener;
3332
private AbstractBuild configurationBuild;
3433
private MatrixBuild parentBuild;
3534

36-
@Before
37-
public void before() throws InterruptedException, IOException {
35+
@BeforeEach
36+
void setUp() throws InterruptedException, IOException {
3837
this.publisher = mock(IMPublisher.class);
3938
when(publisher.prebuild(any(AbstractBuild.class), any(BuildListener.class))).thenCallRealMethod();
4039
when(publisher.perform(any(AbstractBuild.class), any(), any(BuildListener.class))).thenCallRealMethod();
@@ -55,7 +54,7 @@ public void before() throws InterruptedException, IOException {
5554
}
5655

5756
@Test
58-
public void testOnlyParent() throws InterruptedException, IOException {
57+
void testOnlyParent() throws InterruptedException, IOException {
5958
when(publisher.getMatrixNotifier()).thenReturn(MatrixJobMultiplier.ONLY_PARENT);
6059

6160
publisher.prebuild(configurationBuild, listener);
@@ -71,7 +70,7 @@ public void testOnlyParent() throws InterruptedException, IOException {
7170
}
7271

7372
@Test
74-
public void testOnlyConfigurations() throws InterruptedException, IOException {
73+
void testOnlyConfigurations() throws InterruptedException, IOException {
7574
when(publisher.getMatrixNotifier()).thenReturn(MatrixJobMultiplier.ONLY_CONFIGURATIONS);
7675

7776
MatrixAggregator aggregator = publisher.createAggregator(parentBuild, null, listener);
@@ -87,7 +86,7 @@ public void testOnlyConfigurations() throws InterruptedException, IOException {
8786
}
8887

8988
@Test
90-
public void testOnlyBoth() throws InterruptedException, IOException {
89+
void testOnlyBoth() throws InterruptedException, IOException {
9190
when(publisher.getMatrixNotifier()).thenReturn(MatrixJobMultiplier.ALL);
9291

9392
MatrixAggregator aggregator = publisher.createAggregator(parentBuild, null, listener);

0 commit comments

Comments
 (0)