Skip to content

Commit 17afb4b

Browse files
Migrate tests to JUnit Jupiter (#834)
1 parent 0b967cd commit 17afb4b

File tree

85 files changed

+3164
-3176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3164
-3176
lines changed

pom.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ THE SOFTWARE.
6565
<spotbugs.effort>Max</spotbugs.effort>
6666
<spotbugs.threshold>Low</spotbugs.threshold>
6767
<spotless.check.skip>false</spotless.check.skip>
68+
<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
6869
<bc-version>1.82</bc-version>
6970
<argLine>-Xms256M -Xmx256M -XX:+TieredCompilation -XX:TieredStopAtLevel=1</argLine>
7071
</properties>
@@ -164,11 +165,6 @@ THE SOFTWARE.
164165
<artifactId>junit-jupiter-params</artifactId>
165166
<scope>test</scope>
166167
</dependency>
167-
<dependency>
168-
<groupId>org.junit.vintage</groupId>
169-
<artifactId>junit-vintage-engine</artifactId>
170-
<scope>test</scope>
171-
</dependency>
172168
<dependency>
173169
<groupId>org.mockito</groupId>
174170
<artifactId>mockito-core</artifactId>
@@ -308,14 +304,14 @@ THE SOFTWARE.
308304
<artifactItem>
309305
<groupId>org.jenkins-ci</groupId>
310306
<artifactId>remoting-test-client</artifactId>
311-
<version>1.3</version>
307+
<version>68.vc9a_c9f451b_7b_</version>
312308
<outputDirectory>target/test-classes</outputDirectory>
313309
<destFileName>remoting-test-client.jar</destFileName>
314310
</artifactItem>
315311
<artifactItem>
316312
<groupId>org.jenkins-ci</groupId>
317313
<artifactId>remoting-test-client</artifactId>
318-
<version>1.3</version>
314+
<version>68.vc9a_c9f451b_7b_</version>
319315
<classifier>tests</classifier>
320316
<outputDirectory>target/test-classes</outputDirectory>
321317
<destFileName>remoting-test-client-tests.jar</destFileName>

src/test/java/JarCertDump.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @author Kohsuke Kawaguchi
1313
*/
1414
public class JarCertDump {
15+
1516
public static void main(String[] args) throws IOException {
1617
try (JarFile j = new JarFile(new File(args[0]))) {
1718
JarEntry je = j.getJarEntry("hudson/remoting/Channel.class");

src/test/java/OISInterception.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @author Kohsuke Kawaguchi
1313
*/
1414
public class OISInterception {
15+
1516
public static void main(String[] args) throws Exception {
1617
ByteArrayOutputStream baos = new ByteArrayOutputStream();
1718
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {

src/test/java/TrafficAnalyzer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @author Kohsuke Kawaguchi
66
*/
77
public class TrafficAnalyzer {
8+
89
public static void main(String[] args) throws Exception {
910
hudson.remoting.TrafficAnalyzer.main(args);
1011
}

src/test/java/hudson/remoting/BinarySafeStreamTest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141
/**
4242
* @author Kohsuke Kawaguchi
4343
*/
44-
public class BinarySafeStreamTest {
44+
class BinarySafeStreamTest {
45+
4546
@Test
46-
public void test1() throws IOException {
47+
void test1() throws IOException {
4748
ByteArrayOutputStream buf = new ByteArrayOutputStream();
4849
byte[] data = "Sending some data to make sure it's encoded".getBytes(StandardCharsets.UTF_8);
4950
try (OutputStream o = BinarySafeStream.wrap(buf)) {
@@ -59,7 +60,7 @@ public void test1() throws IOException {
5960
}
6061

6162
@Test
62-
public void testSingleWrite() throws IOException {
63+
void testSingleWrite() throws IOException {
6364
byte[] ds = getDataSet(65536);
6465
String master = Base64.getEncoder().encodeToString(ds);
6566

@@ -71,7 +72,7 @@ public void testSingleWrite() throws IOException {
7172
}
7273

7374
@Test
74-
public void testChunkedWrites() throws IOException {
75+
void testChunkedWrites() throws IOException {
7576
byte[] ds = getDataSet(65536);
7677
String master = Base64.getEncoder().encodeToString(ds);
7778

@@ -85,12 +86,12 @@ public void testChunkedWrites() throws IOException {
8586
}
8687

8788
@Test
88-
public void testRoundtripNoFlush() throws IOException {
89+
void testRoundtripNoFlush() throws IOException {
8990
_testRoundtrip(false);
9091
}
9192

9293
@Test
93-
public void testRoundtripFlush() throws IOException {
94+
void testRoundtripFlush() throws IOException {
9495
_testRoundtrip(true);
9596
}
9697

@@ -99,15 +100,15 @@ private void _testRoundtrip(boolean flush) throws IOException {
99100
Random r = new Random(0);
100101

101102
for (int i = 0; i < 16; i++) {
102-
if (dump) {
103+
if (DUMP) {
103104
System.out.println("test started");
104105
}
105106
ByteArrayOutputStream buf = new ByteArrayOutputStream();
106107
randomCopy(r, new ByteArrayInputStream(dataSet), BinarySafeStream.wrap(buf), flush);
107108

108109
decodeByMaster(buf.toString(), dataSet);
109110

110-
if (dump) {
111+
if (DUMP) {
111112
System.out.println("------");
112113
}
113114

@@ -123,7 +124,7 @@ private void _testRoundtrip(boolean flush) throws IOException {
123124
fail(msg);
124125
}
125126

126-
if (dump) {
127+
if (DUMP) {
127128
System.out.println("------");
128129
}
129130
}
@@ -163,7 +164,7 @@ private void randomCopy(Random r, InputStream in, OutputStream out, boolean rand
163164
switch (r.nextInt(3)) {
164165
case 0:
165166
int ch = in.read();
166-
if (dump) {
167+
if (DUMP) {
167168
System.out.println("read1(" + ch + ')');
168169
}
169170
assertTrue(255 >= ch && ch >= -1); // make sure the range is [-1,255]
@@ -180,7 +181,7 @@ private void randomCopy(Random r, InputStream in, OutputStream out, boolean rand
180181

181182
byte[] tmp = new byte[start + chunk + trail];
182183
int len = in.read(tmp, start, chunk);
183-
if (dump) {
184+
if (DUMP) {
184185
System.out.println(
185186
"read2(" + print(tmp, start, len) + ",len=" + len + ",chunk=" + chunk + ")");
186187
}
@@ -190,10 +191,10 @@ private void randomCopy(Random r, InputStream in, OutputStream out, boolean rand
190191

191192
// check extra data corruption
192193
for (int i = 0; i < start; i++) {
193-
assertEquals(tmp[i], 0);
194+
assertEquals(0, tmp[i]);
194195
}
195196
for (int i = 0; i < trail; i++) {
196-
assertEquals(tmp[start + chunk + i], 0);
197+
assertEquals(0, tmp[start + chunk + i]);
197198
}
198199

199200
out.write(tmp, start, len);
@@ -203,7 +204,7 @@ private void randomCopy(Random r, InputStream in, OutputStream out, boolean rand
203204
len = r.nextInt(16);
204205
tmp = new byte[len];
205206
len = in.read(tmp);
206-
if (dump) {
207+
if (DUMP) {
207208
System.out.println("read3(" + print(tmp, 0, len) + ",len=" + len + ')');
208209
}
209210
if (len == -1) {
@@ -235,5 +236,5 @@ private static String print(byte[] buf, int start, int len) {
235236
return out.append('}').toString();
236237
}
237238

238-
private static final boolean dump = false;
239+
private static final boolean DUMP = false;
239240
}

src/test/java/hudson/remoting/ChannelFilterTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package hudson.remoting;
22

3-
import static org.junit.Assert.assertThrows;
43
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
55

66
import java.io.IOException;
77
import java.util.concurrent.Callable;
@@ -12,10 +12,11 @@
1212
/**
1313
* @author Kohsuke Kawaguchi
1414
*/
15-
public class ChannelFilterTest {
15+
class ChannelFilterTest {
16+
1617
@ParameterizedTest
1718
@MethodSource(ChannelRunners.PROVIDER_METHOD)
18-
public void testFilter(ChannelRunner channelRunner) throws Exception {
19+
void testFilter(ChannelRunner channelRunner) throws Exception {
1920
channelRunner.withChannel(channel -> {
2021
channel.addLocalExecutionInterceptor(new CallableDecorator() {
2122
@Override
@@ -56,7 +57,7 @@ public Object call() throws Exception {
5657

5758
@ParameterizedTest
5859
@MethodSource(ChannelRunners.PROVIDER_METHOD)
59-
public void testBlacklisting(ChannelRunner channelRunner) throws Exception {
60+
void testBlacklisting(ChannelRunner channelRunner) throws Exception {
6061
channelRunner.withChannel(channel -> {
6162
channel.addLocalExecutionInterceptor(new CallableDecorator() {
6263
@Override

src/test/java/hudson/remoting/ChannelTest.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@
4040
/**
4141
* @author Kohsuke Kawaguchi
4242
*/
43-
public class ChannelTest {
43+
class ChannelTest {
44+
4445
private static final Logger LOGGER = Logger.getLogger(ChannelTest.class.getName());
4546

4647
@ParameterizedTest
4748
@MethodSource(ChannelRunners.PROVIDER_METHOD)
48-
public void testCapability(ChannelRunner channelRunner) throws Exception {
49+
void testCapability(ChannelRunner channelRunner) throws Exception {
4950
assumeFalse(
5051
channelRunner instanceof InProcessCompatibilityRunner,
5152
"In-process runner does not support multi-classloader RPC");
@@ -55,7 +56,7 @@ public void testCapability(ChannelRunner channelRunner) throws Exception {
5556
@Issue("JENKINS-9050")
5657
@ParameterizedTest
5758
@MethodSource(ChannelRunners.PROVIDER_METHOD)
58-
public void testFailureInDeserialization(ChannelRunner channelRunner) throws Exception {
59+
void testFailureInDeserialization(ChannelRunner channelRunner) throws Exception {
5960
channelRunner.withChannel(channel -> {
6061
final IOException e = assertThrows(IOException.class, () -> channel.call(new CallableImpl()));
6162
assertEquals("foobar", e.getCause().getCause().getMessage());
@@ -82,12 +83,12 @@ private void readObject(ObjectInputStream ois) {
8283
@Issue("JENKINS-10424")
8384
@ParameterizedTest
8485
@MethodSource(ChannelRunners.PROVIDER_METHOD)
85-
public void testExportCallerDeallocation(ChannelRunner channelRunner) throws Exception {
86+
void testExportCallerDeallocation(ChannelRunner channelRunner) throws Exception {
8687
channelRunner.withChannel(channel -> {
8788
for (int i = 0; i < 100; i++) {
8889
final GreeterImpl g = new GreeterImpl();
8990
channel.call(new GreetingTask(g));
90-
assertEquals(g.name, "Kohsuke");
91+
assertEquals("Kohsuke", g.name);
9192
assertFalse(
9293
channel.exportedObjects.isExported(g),
9394
"in this scenario, auto-unexport by the caller should kick in.");
@@ -101,12 +102,12 @@ public void testExportCallerDeallocation(ChannelRunner channelRunner) throws Exc
101102
@Issue("JENKINS-10424")
102103
@ParameterizedTest
103104
@MethodSource(ChannelRunners.PROVIDER_METHOD)
104-
public void testExportCalleeDeallocation(ChannelRunner channelRunner) throws Exception {
105+
void testExportCalleeDeallocation(ChannelRunner channelRunner) throws Exception {
105106
channelRunner.withChannel(channel -> {
106107
for (int j = 0; j < 10; j++) {
107108
final GreeterImpl g = new GreeterImpl();
108109
channel.call(new GreetingTask(channel.export(Greeter.class, g)));
109-
assertEquals(g.name, "Kohsuke");
110+
assertEquals("Kohsuke", g.name);
110111
boolean isExported = channel.exportedObjects.isExported(g);
111112
if (!isExported) {
112113
// it is unlikely but possible that GC happens on remote node
@@ -137,7 +138,7 @@ public void testExportCalleeDeallocation(ChannelRunner channelRunner) throws Exc
137138

138139
@ParameterizedTest
139140
@MethodSource(ChannelRunners.PROVIDER_METHOD)
140-
public void testGetSetProperty(ChannelRunner channelRunner) throws Exception {
141+
void testGetSetProperty(ChannelRunner channelRunner) throws Exception {
141142
channelRunner.withChannel(channel -> {
142143
channel.setProperty("foo", "bar");
143144
assertEquals("bar", channel.getProperty("foo"));
@@ -152,7 +153,7 @@ public void testGetSetProperty(ChannelRunner channelRunner) throws Exception {
152153

153154
@ParameterizedTest
154155
@MethodSource(ChannelRunners.PROVIDER_METHOD)
155-
public void testWaitForRemoteProperty(ChannelRunner channelRunner) throws Exception {
156+
void testWaitForRemoteProperty(ChannelRunner channelRunner) throws Exception {
156157
channelRunner.withChannel(channel -> {
157158
Future<Void> f = channel.callAsync(new WaitForRemotePropertyCallable());
158159
assertEquals("bar", channel.waitForRemoteProperty("foo"));
@@ -206,7 +207,7 @@ public Object call() {
206207

207208
@ParameterizedTest
208209
@MethodSource(ChannelRunners.PROVIDER_METHOD)
209-
public void testClassLoaderHolder(ChannelRunner channelRunner) throws Exception {
210+
void testClassLoaderHolder(ChannelRunner channelRunner) throws Exception {
210211
channelRunner.withChannel(channel -> {
211212
URLClassLoader ucl = new URLClassLoader(new URL[0]);
212213
ClassLoaderHolder h = channel.call(new Echo<>(new ClassLoaderHolder(ucl)));
@@ -232,7 +233,7 @@ public T call() throws RuntimeException {
232233
@Issue("JENKINS-39150")
233234
@ParameterizedTest
234235
@MethodSource(ChannelRunners.PROVIDER_METHOD)
235-
public void testDiagnostics(ChannelRunner channelRunner) throws Exception {
236+
void testDiagnostics(ChannelRunner channelRunner) throws Exception {
236237
assumeFalse(channelRunner instanceof ForkRunner, "Can't call diagnostics on forked runners");
237238
channelRunner.withChannel(channel -> {
238239
StringWriter sw = new StringWriter();
@@ -247,7 +248,7 @@ public void testDiagnostics(ChannelRunner channelRunner) throws Exception {
247248

248249
@ParameterizedTest
249250
@MethodSource(ChannelRunners.PROVIDER_METHOD)
250-
public void testCallSiteStacktrace(ChannelRunner channelRunner) throws Exception {
251+
void testCallSiteStacktrace(ChannelRunner channelRunner) throws Exception {
251252
channelRunner.withChannel(channel -> {
252253
final Exception e = assertThrows(Exception.class, () -> this.failRemotelyToBeWrappedLocally(channel));
253254
assertEquals("Local Nested", e.getMessage());
@@ -291,7 +292,7 @@ public Void call() throws IOException {
291292
@Issue("JENKINS-45023")
292293
@ParameterizedTest
293294
@MethodSource(ChannelRunners.PROVIDER_METHOD)
294-
public void testShouldNotAcceptUserRequestsWhenIsBeingClosed(ChannelRunner channelRunner) throws Exception {
295+
void testShouldNotAcceptUserRequestsWhenIsBeingClosed(ChannelRunner channelRunner) throws Exception {
295296
channelRunner.withChannel(channel -> {
296297
// Create a sample request to the channel
297298
final Callable<Void, Exception> testPayload = new NeverEverCallable();
@@ -318,7 +319,7 @@ public void testShouldNotAcceptUserRequestsWhenIsBeingClosed(ChannelRunner chann
318319
@Issue("JENKINS-45294")
319320
@ParameterizedTest
320321
@MethodSource(ChannelRunners.PROVIDER_METHOD)
321-
public void testShouldNotAcceptUserRPCRequestsWhenIsBeingClosed(ChannelRunner channelRunner) throws Exception {
322+
void testShouldNotAcceptUserRPCRequestsWhenIsBeingClosed(ChannelRunner channelRunner) throws Exception {
322323
channelRunner.withChannel(channel -> {
323324
Collection<String> src = new ArrayList<>();
324325
src.add("Hello");
@@ -490,7 +491,7 @@ private void assertFailsWithChannelClosedException(Channel channel, TestRunnable
490491
}
491492

492493
@Test
493-
public void isClosedChannelException() {
494+
void isClosedChannelException() {
494495
assertThat(Channel.isClosedChannelException(null), is(false));
495496
assertThat(Channel.isClosedChannelException(new IOException()), is(false));
496497
assertThat(Channel.isClosedChannelException(new ClosedChannelException()), is(true));

0 commit comments

Comments
 (0)