Skip to content

Commit 0ba2194

Browse files
Migrate all test assertions to AssertJ
Signed-off-by: Adrian Cole <[email protected]>
1 parent 59889c2 commit 0ba2194

File tree

104 files changed

+1253
-1451
lines changed

Some content is hidden

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

104 files changed

+1253
-1451
lines changed

e2e/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
<artifactId>junit</artifactId>
4040
<scope>test</scope>
4141
</dependency>
42+
<dependency>
43+
<groupId>org.assertj</groupId>
44+
<artifactId>assertj-core</artifactId>
45+
<scope>test</scope>
46+
</dependency>
4247

4348
<dependency>
4449
<groupId>org.slf4j</groupId>

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
package io.kubernetes.client.e2e.extended.leaderelection;
1414

15+
import static org.assertj.core.api.Assertions.assertThat;
16+
1517
import io.kubernetes.client.extended.leaderelection.LeaderElectionConfig;
1618
import io.kubernetes.client.extended.leaderelection.LeaderElector;
1719
import io.kubernetes.client.extended.leaderelection.Lock;
@@ -34,7 +36,6 @@
3436
import java.util.concurrent.CyclicBarrier;
3537
import java.util.concurrent.atomic.AtomicInteger;
3638
import java.util.concurrent.atomic.AtomicReference;
37-
import org.junit.Assert;
3839
import org.junit.Before;
3940
import org.junit.Test;
4041
import org.junit.runner.RunWith;
@@ -165,8 +166,8 @@ public void testMultiCandidateLeaderElection() throws Exception {
165166

166167
// wait till someone becomes leader
167168
startBeingLeader.await();
168-
Assert.assertNotNull(leaderRef.get());
169-
Assert.assertTrue(candidate1.equals(leaderRef.get()) || candidate2.equals(leaderRef.get()));
169+
assertThat(leaderRef).doesNotHaveNullValue();
170+
assertThat(candidate1.equals(leaderRef.get()) || candidate2.equals(leaderRef.get())).isTrue();
170171

171172
// stop both LeaderElectors, in order .. non-leader, then leader so that
172173
// non-leader doesn't get to become leader
@@ -181,8 +182,8 @@ public void testMultiCandidateLeaderElection() throws Exception {
181182
stopBeingLeader.await();
182183

183184
// make sure that only one candidate became leader
184-
Assert.assertEquals(1, startBeingLeaderCount.get());
185-
Assert.assertEquals(1, stopBeingLeaderCount.get());
185+
assertThat(startBeingLeaderCount).hasValue(1);
186+
assertThat(stopBeingLeaderCount).hasValue(1);
186187
}
187188

188189
@Test(timeout = 45000L)

examples/examples-release-17/src/test/java/io/kubernetes/client/examples/ExampleTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.kubernetes.client.openapi.apis.CoreV1Api;
2626
import io.kubernetes.client.openapi.models.V1Namespace;
2727
import io.kubernetes.client.openapi.models.V1ObjectMeta;
28-
import java.io.IOException;
2928
import org.junit.Rule;
3029
import org.junit.Test;
3130

@@ -34,7 +33,7 @@ public class ExampleTest {
3433
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
3534

3635
@Test
37-
public void exactUrlOnly() throws IOException, ApiException {
36+
public void exactUrlOnly() throws ApiException {
3837
ApiClient client = new ApiClient();
3938
client.setBasePath("http://localhost:" + PORT);
4039
Configuration.setDefaultApiClient(client);

examples/examples-release-18/src/test/java/io/kubernetes/client/examples/ExampleTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.kubernetes.client.openapi.apis.CoreV1Api;
2626
import io.kubernetes.client.openapi.models.V1Namespace;
2727
import io.kubernetes.client.openapi.models.V1ObjectMeta;
28-
import java.io.IOException;
2928
import org.junit.Rule;
3029
import org.junit.Test;
3130

@@ -34,7 +33,7 @@ public class ExampleTest {
3433
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
3534

3635
@Test
37-
public void exactUrlOnly() throws IOException, ApiException {
36+
public void exactUrlOnly() throws ApiException {
3837
ApiClient client = new ApiClient();
3938
client.setBasePath("http://localhost:" + PORT);
4039
Configuration.setDefaultApiClient(client);

examples/examples-release-19/src/test/java/io/kubernetes/client/examples/ExampleTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.kubernetes.client.openapi.apis.CoreV1Api;
2626
import io.kubernetes.client.openapi.models.V1Namespace;
2727
import io.kubernetes.client.openapi.models.V1ObjectMeta;
28-
import java.io.IOException;
2928
import org.junit.Rule;
3029
import org.junit.Test;
3130

@@ -34,7 +33,7 @@ public class ExampleTest {
3433
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
3534

3635
@Test
37-
public void exactUrlOnly() throws IOException, ApiException {
36+
public void exactUrlOnly() throws ApiException {
3837
ApiClient client = new ApiClient();
3938
client.setBasePath("http://localhost:" + PORT);
4039
Configuration.setDefaultApiClient(client);

examples/examples-release-20/src/test/java/io/kubernetes/client/examples/ExampleTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.kubernetes.client.openapi.apis.CoreV1Api;
2626
import io.kubernetes.client.openapi.models.V1Namespace;
2727
import io.kubernetes.client.openapi.models.V1ObjectMeta;
28-
import java.io.IOException;
2928
import org.junit.Rule;
3029
import org.junit.Test;
3130

@@ -34,7 +33,7 @@ public class ExampleTest {
3433
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
3534

3635
@Test
37-
public void exactUrlOnly() throws IOException, ApiException {
36+
public void exactUrlOnly() throws ApiException {
3837
ApiClient client = new ApiClient();
3938
client.setBasePath("http://localhost:" + PORT);
4039
Configuration.setDefaultApiClient(client);

examples/examples-release-latest/src/test/java/io/kubernetes/client/examples/ExampleTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import io.kubernetes.client.openapi.apis.CoreV1Api;
2626
import io.kubernetes.client.openapi.models.V1Namespace;
2727
import io.kubernetes.client.openapi.models.V1ObjectMeta;
28-
import java.io.IOException;
2928
import org.junit.Rule;
3029
import org.junit.Test;
3130

@@ -34,7 +33,7 @@ public class ExampleTest {
3433
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
3534

3635
@Test
37-
public void exactUrlOnly() throws IOException, ApiException {
36+
public void exactUrlOnly() throws ApiException {
3837
ApiClient client = new ApiClient();
3938
client.setBasePath("http://localhost:" + PORT);
4039
Configuration.setDefaultApiClient(client);

extended/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
<artifactId>commons-collections4</artifactId>
7777
<scope>test</scope>
7878
</dependency>
79+
<dependency>
80+
<groupId>org.assertj</groupId>
81+
<artifactId>assertj-core</artifactId>
82+
<scope>test</scope>
83+
</dependency>
7984
</dependencies>
8085

8186
<build>

extended/src/test/java/io/kubernetes/client/extended/controller/ControllerManagerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
package io.kubernetes.client.extended.controller;
1414

15-
import static org.junit.Assert.*;
15+
import static org.assertj.core.api.Assertions.assertThat;
1616

1717
import io.kubernetes.client.informer.SharedInformerFactory;
1818
import org.junit.Test;
@@ -27,12 +27,12 @@ public void testControllerStartShutdown() {
2727
ControllerManager cm = new ControllerManager(new SharedInformerFactory(), dummy1, dummy2);
2828

2929
cm.run();
30-
assertTrue(dummy1.started);
31-
assertTrue(dummy2.started);
30+
assertThat(dummy1.started).isTrue();
31+
assertThat(dummy2.started).isTrue();
3232

3333
cm.shutdown();
34-
assertTrue(dummy1.stopped);
35-
assertTrue(dummy2.stopped);
34+
assertThat(dummy1.stopped).isTrue();
35+
assertThat(dummy2.stopped).isTrue();
3636
}
3737

3838
static class DummyController implements Controller {

extended/src/test/java/io/kubernetes/client/extended/controller/ControllerWatchTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
package io.kubernetes.client.extended.controller;
1414

15-
import static org.junit.Assert.*;
15+
import static org.assertj.core.api.Assertions.assertThat;
1616

1717
import io.kubernetes.client.extended.controller.reconciler.Request;
1818
import io.kubernetes.client.extended.workqueue.DefaultWorkQueue;
@@ -34,11 +34,11 @@ public void testOnAdd() {
3434
new DefaultControllerWatch(
3535
V1Pod.class, workQueue, Controllers.defaultReflectiveKeyFunc(), Duration.ZERO);
3636
controllerWatch.getResourceEventHandler().onAdd(testPod);
37-
assertEquals(1, workQueue.length());
37+
assertThat(workQueue.length()).isEqualTo(1);
3838

3939
controllerWatch.setOnAddFilterPredicate((V1Pod addedPod) -> false);
4040
controllerWatch.getResourceEventHandler().onAdd(testPod);
41-
assertEquals(1, workQueue.length());
41+
assertThat(workQueue.length()).isEqualTo(1);
4242
}
4343

4444
@Test
@@ -48,11 +48,11 @@ public void testOnUpdate() {
4848
new DefaultControllerWatch(
4949
V1Pod.class, workQueue, Controllers.defaultReflectiveKeyFunc(), Duration.ZERO);
5050
controllerWatch.getResourceEventHandler().onUpdate(null, testPod);
51-
assertEquals(1, workQueue.length());
51+
assertThat(workQueue.length()).isEqualTo(1);
5252

5353
controllerWatch.setOnUpdateFilterPredicate((V1Pod oldPod, V1Pod newPod) -> false);
5454
controllerWatch.getResourceEventHandler().onUpdate(null, testPod);
55-
assertEquals(1, workQueue.length());
55+
assertThat(workQueue.length()).isEqualTo(1);
5656
}
5757

5858
@Test
@@ -62,10 +62,10 @@ public void testOnDelete() {
6262
new DefaultControllerWatch(
6363
V1Pod.class, workQueue, Controllers.defaultReflectiveKeyFunc(), Duration.ZERO);
6464
controllerWatch.getResourceEventHandler().onDelete(testPod, false);
65-
assertEquals(1, workQueue.length());
65+
assertThat(workQueue.length()).isEqualTo(1);
6666

6767
controllerWatch.setOnDeleteFilterPredicate((V1Pod newPod, Boolean stateUnknown) -> false);
6868
controllerWatch.getResourceEventHandler().onDelete(testPod, false);
69-
assertEquals(1, workQueue.length());
69+
assertThat(workQueue.length()).isEqualTo(1);
7070
}
7171
}

0 commit comments

Comments
 (0)