Skip to content

Commit aa01cb7

Browse files
authored
Merge pull request #3178 from codefromthecrypt/migrate-to-jupiter
Migrate to JUnit Jupiter
2 parents ec220f3 + 24749c7 commit aa01cb7

File tree

131 files changed

+1740
-1731
lines changed

Some content is hidden

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

131 files changed

+1740
-1731
lines changed

e2e/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
</dependency>
2727

2828
<dependency>
29-
<groupId>junit</groupId>
30-
<artifactId>junit</artifactId>
29+
<groupId>org.junit.jupiter</groupId>
30+
<artifactId>junit-jupiter</artifactId>
3131
<scope>test</scope>
3232
</dependency>
3333
<dependency>

e2e/src/test/java/io/kubernetes/client/e2e/basic/CoreV1ApiTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
import io.kubernetes.client.openapi.models.V1ObjectMeta;
2222
import io.kubernetes.client.openapi.models.V1Status;
2323
import io.kubernetes.client.util.ClientBuilder;
24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

26-
public class CoreV1ApiTest {
26+
class CoreV1ApiTest {
2727

2828
@Test
29-
public void testCreateAndDeleteNamespace() throws Exception {
29+
void createAndDeleteNamespace() throws Exception {
3030
ApiClient client = ClientBuilder.defaultClient();
3131
CoreV1Api coreV1Api = new CoreV1Api(client);
3232
V1Namespace namespaceFoo = new V1Namespace()

e2e/src/test/java/io/kubernetes/client/e2e/csr/CSRTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
import java.security.KeyPair;
2626
import java.security.KeyPairGenerator;
2727
import java.security.SecureRandom;
28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2929

30-
public class CSRTest {
30+
class CSRTest {
3131

3232
@Test
33-
public void testBuildClientWithCSR() throws Exception {
33+
void buildClientWithCSR() throws Exception {
3434
// initialize test environment
3535
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
3636
keyGen.initialize(2048, new SecureRandom());

e2e/src/test/java/io/kubernetes/client/e2e/dynamic/DynamicApiTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesApi;
2323
import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject;
2424
import io.kubernetes.client.util.generic.dynamic.Dynamics;
25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

27-
public class DynamicApiTest {
27+
class DynamicApiTest {
2828

2929
@Test
30-
public void testDynamicApiCreateAndDeleteNamespace() throws Exception {
30+
void dynamicApiCreateAndDeleteNamespace() throws Exception {
3131
ApiClient client = ClientBuilder.defaultClient();
3232
DynamicKubernetesApi dynamicApi =
3333
new DynamicKubernetesApi("", "v1", "namespaces", client);

e2e/src/test/java/io/kubernetes/client/e2e/extended/leaderelection/LeaderElectorTest.java

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.kubernetes.client.openapi.apis.CoordinationV1Api;
2626
import io.kubernetes.client.openapi.apis.CoreV1Api;
2727
import io.kubernetes.client.util.ClientBuilder;
28-
import java.io.IOException;
2928
import java.net.HttpURLConnection;
3029
import java.time.Duration;
3130
import java.util.ArrayList;
@@ -34,17 +33,16 @@
3433
import java.util.concurrent.BrokenBarrierException;
3534
import java.util.concurrent.CountDownLatch;
3635
import java.util.concurrent.CyclicBarrier;
36+
import java.util.concurrent.TimeUnit;
3737
import java.util.concurrent.atomic.AtomicInteger;
3838
import java.util.concurrent.atomic.AtomicReference;
39-
import org.junit.Before;
40-
import org.junit.Test;
41-
import org.junit.runner.RunWith;
42-
import org.junit.runners.Parameterized;
39+
import org.junit.jupiter.api.Timeout;
40+
import org.junit.jupiter.params.ParameterizedTest;
41+
import org.junit.jupiter.params.provider.MethodSource;
4342
import org.slf4j.Logger;
4443
import org.slf4j.LoggerFactory;
4544

46-
@RunWith(Parameterized.class)
47-
public class LeaderElectorTest {
45+
class LeaderElectorTest {
4846

4947
private static final Logger LOGGER = LoggerFactory.getLogger(LeaderElectorTest.class);
5048

@@ -57,7 +55,6 @@ private enum LockType {
5755
Lease
5856
}
5957

60-
@Parameterized.Parameters(name = "{0}")
6158
public static Collection<Object[]> constructorFeeder() {
6259
final List<Object[]> args = new ArrayList<>();
6360

@@ -68,20 +65,11 @@ public static Collection<Object[]> constructorFeeder() {
6865
return args;
6966
}
7067

71-
private final ApiClient apiClient;
72-
private final LockType lockType;
68+
private ApiClient apiClient;
69+
private LockType lockType;
7370

74-
public LeaderElectorTest(LockType lockType) {
75-
try {
76-
apiClient = ClientBuilder.defaultClient();
77-
} catch (IOException ex) {
78-
throw new RuntimeException("Couldn't create ApiClient", ex);
79-
}
80-
this.lockType = lockType;
81-
}
82-
83-
@Before
84-
public void setup() throws Exception {
71+
private void initLeaderElectorTest(LockType lockType) throws Exception {
72+
apiClient = ClientBuilder.defaultClient();
8573
// delete the lock resource if it exists, or else first leader candidate might need to wait for
8674
// a whole leaseDuration configured
8775
switch (lockType) {
@@ -97,19 +85,23 @@ public void setup() throws Exception {
9785
default:
9886
throw new RuntimeException("Unknown LockType " + lockType);
9987
}
88+
this.lockType = lockType;
10089
}
10190

102-
@Test(timeout = 30000L)
103-
public void testSingleCandidateLeaderElection() throws Exception {
91+
@MethodSource("constructorFeeder")
92+
@ParameterizedTest(name = "{0}")
93+
@Timeout(value = 30000L, unit = TimeUnit.MILLISECONDS)
94+
void singleCandidateLeaderElection(LockType lockType) throws Exception {
95+
initLeaderElectorTest(lockType);
10496
CountDownLatch startLeadershipLatch = new CountDownLatch(1);
10597
CountDownLatch stopLeadershipLatch = new CountDownLatch(1);
10698

10799
LeaderElector leaderElector =
108100
makeAndRunLeaderElectorAsync(
109101
"candidate",
110102
null,
111-
() -> startLeadershipLatch.countDown(),
112-
() -> stopLeadershipLatch.countDown(),
103+
startLeadershipLatch::countDown,
104+
stopLeadershipLatch::countDown,
113105
apiClient);
114106

115107
startLeadershipLatch.await();
@@ -119,8 +111,11 @@ public void testSingleCandidateLeaderElection() throws Exception {
119111
stopLeadershipLatch.await();
120112
}
121113

122-
@Test(timeout = 30000L)
123-
public void testMultiCandidateLeaderElection() throws Exception {
114+
@MethodSource("constructorFeeder")
115+
@ParameterizedTest(name = "{0}")
116+
@Timeout(value = 30000L, unit = TimeUnit.MILLISECONDS)
117+
void multiCandidateLeaderElection(LockType lockType) throws Exception {
118+
initLeaderElectorTest(lockType);
124119
CyclicBarrier startBarrier = new CyclicBarrier(2);
125120

126121
CountDownLatch startBeingLeader = new CountDownLatch(1);
@@ -186,17 +181,20 @@ public void testMultiCandidateLeaderElection() throws Exception {
186181
assertThat(stopBeingLeaderCount).hasValue(1);
187182
}
188183

189-
@Test(timeout = 45000L)
190-
public void testLeaderGracefulShutdown() throws Exception {
184+
@MethodSource("constructorFeeder")
185+
@ParameterizedTest(name = "{0}")
186+
@Timeout(value = 45000L, unit = TimeUnit.MILLISECONDS)
187+
void leaderGracefulShutdown(LockType lockType) throws Exception {
188+
initLeaderElectorTest(lockType);
191189
CountDownLatch startBeingLeader1 = new CountDownLatch(1);
192190
CountDownLatch stopBeingLeader1 = new CountDownLatch(1);
193191

194192
LeaderElector leaderElector1 =
195193
makeAndRunLeaderElectorAsync(
196194
"candidate1",
197195
null,
198-
() -> startBeingLeader1.countDown(),
199-
() -> stopBeingLeader1.countDown(),
196+
startBeingLeader1::countDown,
197+
stopBeingLeader1::countDown,
200198
apiClient);
201199

202200
// wait for candidate1 to become leader
@@ -209,8 +207,8 @@ public void testLeaderGracefulShutdown() throws Exception {
209207
makeAndRunLeaderElectorAsync(
210208
"candidate2",
211209
null,
212-
() -> startBeingLeader2.countDown(),
213-
() -> stopBeingLeader2.countDown(),
210+
startBeingLeader2::countDown,
211+
stopBeingLeader2::countDown,
214212
apiClient);
215213

216214
leaderElector1.close();

e2e/src/test/java/io/kubernetes/client/e2e/informer/NamespaceInformerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
import io.kubernetes.client.openapi.models.V1NamespaceList;
2424
import io.kubernetes.client.util.ClientBuilder;
2525
import io.kubernetes.client.util.generic.GenericKubernetesApi;
26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

28-
public class NamespaceInformerTest {
28+
class NamespaceInformerTest {
2929
@Test
30-
public void testListWatchingNamespaces() throws Exception {
30+
void listWatchingNamespaces() throws Exception {
3131
ApiClient client = ClientBuilder.defaultClient();
3232
SharedInformerFactory informerFactory = new SharedInformerFactory(client);
3333

e2e/src/test/java/io/kubernetes/client/e2e/kubectl/KubectlDrainTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import io.kubernetes.client.openapi.models.V1PodSpec;
2626
import io.kubernetes.client.util.ClientBuilder;
2727
import java.util.List;
28-
import org.junit.Test;
28+
import org.junit.jupiter.api.Test;
2929

30-
public class KubectlDrainTest {
30+
class KubectlDrainTest {
3131
@Test
32-
public void testPodInvisibleAfterDrain() throws Exception {
32+
void podInvisibleAfterDrain() throws Exception {
3333
Configuration.setDefaultApiClient(ClientBuilder.defaultClient());
3434

3535
V1Node testNode = new V1Node().metadata(new V1ObjectMeta().name("foo"));

e2e/src/test/java/io/kubernetes/client/e2e/kubectl/KubectlNamespaceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
import io.kubernetes.client.openapi.models.V1Namespace;
1818
import io.kubernetes.client.openapi.models.V1ObjectMeta;
1919
import io.kubernetes.client.util.ClientBuilder;
20-
import org.junit.Test;
20+
import org.junit.jupiter.api.Test;
2121

2222
import static org.assertj.core.api.Assertions.assertThat;
2323

24-
public class KubectlNamespaceTest {
24+
class KubectlNamespaceTest {
2525

2626
@Test
27-
public void testCreateApplyDelete() throws Exception {
27+
void createApplyDelete() throws Exception {
2828
ApiClient client = ClientBuilder.standard().build();
2929

3030
// Create a namespace

e2e/src/test/java/io/kubernetes/client/e2e/kubectl/KubectlRolloutTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,27 @@
2828
import java.io.IOException;
2929
import java.io.InputStreamReader;
3030
import java.io.Reader;
31-
import org.junit.Before;
32-
import org.junit.Test;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
3333

34-
public class KubectlRolloutTest {
35-
@Before
36-
public void setup() throws Exception {
34+
class KubectlRolloutTest {
35+
@BeforeEach
36+
void setup() throws Exception {
3737
Configuration.setDefaultApiClient(ClientBuilder.defaultClient());
3838
}
3939

4040
@Test
41-
public void testRolloutDaemonSet() throws Exception {
41+
void rolloutDaemonSet() throws Exception {
4242
testRollout(V1DaemonSet.class, "/test-daemonset.yaml", "/test-daemonset-updated.yaml");
4343
}
4444

4545
@Test
46-
public void testRolloutDeployment() throws Exception {
46+
void rolloutDeployment() throws Exception {
4747
testRollout(V1Deployment.class, "/test-deployment.yaml", "/test-deployment-updated.yaml");
4848
}
4949

5050
@Test
51-
public void testRolloutStatefulSet() throws Exception {
51+
void rolloutStatefulSet() throws Exception {
5252
testRollout(V1StatefulSet.class, "/test-statefulset.yaml", "/test-statefulset-updated.yaml");
5353
}
5454

e2e/src/test/java/io/kubernetes/client/e2e/util/ModelMapperTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import io.kubernetes.client.openapi.models.V1Pod;
2323
import io.kubernetes.client.util.ClientBuilder;
2424
import io.kubernetes.client.util.ModelMapper;
25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

27-
public class ModelMapperTest {
27+
class ModelMapperTest {
2828

2929
@Test
30-
public void apiDiscoveryShouldWork() throws Exception {
30+
void apiDiscoveryShouldWork() throws Exception {
3131
Discovery discovery = new Discovery(ClientBuilder.defaultClient());
3232
ModelMapper.refresh(discovery);
3333

0 commit comments

Comments
 (0)