Skip to content

Commit e912698

Browse files
committed
,ore
Signed-off-by: wind57 <[email protected]>
1 parent 7ab4e0a commit e912698

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServiceInstanceMapperTests.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import io.kubernetes.client.openapi.models.V1ServicePort;
2626
import io.kubernetes.client.openapi.models.V1ServicePortBuilder;
2727
import io.kubernetes.client.openapi.models.V1ServiceSpecBuilder;
28-
import org.junit.jupiter.api.Assertions;
28+
import org.assertj.core.api.Assertions;
2929
import org.junit.jupiter.api.Test;
3030
import org.junit.jupiter.api.extension.ExtendWith;
3131

@@ -116,9 +116,9 @@ void testEmptyPorts(CapturedOutput output) {
116116
List<V1ServicePort> servicePorts = List.of();
117117
V1Service service = createService("database", "default", annotations, labels, servicePorts);
118118
KubernetesServiceInstance serviceInstance = mapper.map(service);
119-
Assertions.assertNull(serviceInstance);
120-
Assertions.assertTrue(output.getOut()
121-
.contains("service : database does not have any ServicePort(s), will not consider it for load balancing"));
119+
Assertions.assertThat(serviceInstance).isNull();
120+
Assertions.assertThat(output.getOut()).contains(
121+
"service : database does not have any ServicePort(s), will not consider it for load balancing");
122122
}
123123

124124
@Test
@@ -133,10 +133,10 @@ void singlePortNameMatchesProperty(CapturedOutput output) {
133133
List<V1ServicePort> servicePorts = List.of(new V1ServicePortBuilder().withName("http").withPort(80).build());
134134
V1Service service = createService("database", "default", annotations, labels, servicePorts);
135135
KubernetesServiceInstance serviceInstance = mapper.map(service);
136-
Assertions.assertNotNull(serviceInstance);
137-
Assertions.assertTrue(output.getOut()
136+
Assertions.assertThat(serviceInstance).isNotNull();
137+
Assertions.assertThat(output.getOut())
138138
.contains("single ServicePort found, "
139-
+ "will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')"));
139+
+ "will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')");
140140
}
141141

142142
@Test
@@ -151,10 +151,10 @@ void singlePortNameDoesNotMatchProperty(CapturedOutput output) {
151151
List<V1ServicePort> servicePorts = List.of(new V1ServicePortBuilder().withName("http").withPort(80).build());
152152
V1Service service = createService("database", "default", annotations, labels, servicePorts);
153153
KubernetesServiceInstance serviceInstance = mapper.map(service);
154-
Assertions.assertNotNull(serviceInstance);
155-
Assertions.assertTrue(output.getOut()
154+
Assertions.assertThat(serviceInstance).isNotNull();
155+
Assertions.assertThat(output.getOut())
156156
.contains("single ServicePort found, "
157-
+ "will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')"));
157+
+ "will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')");
158158
}
159159

160160
@Test
@@ -170,9 +170,9 @@ void multiplePortsNameMatchesProperty(CapturedOutput output) {
170170
new V1ServicePortBuilder().withName("https").withPort(443).build());
171171
V1Service service = createService("database", "default", annotations, labels, servicePorts);
172172
KubernetesServiceInstance serviceInstance = mapper.map(service);
173-
Assertions.assertNotNull(serviceInstance);
174-
Assertions.assertTrue(output.getOut().contains("found port name that matches : http"));
175-
Assertions.assertEquals(serviceInstance.getPort(), 80);
173+
Assertions.assertThat(serviceInstance).isNotNull();
174+
Assertions.assertThat(output.getOut()).contains("found port name that matches : http");
175+
Assertions.assertThat(serviceInstance.getPort()).isEqualTo(80);
176176
}
177177

178178
@Test
@@ -188,10 +188,10 @@ void multiplePortsNameDoesNotMatchProperty(CapturedOutput output) {
188188
new V1ServicePortBuilder().withName("https").withPort(443).build());
189189
V1Service service = createService("database", "default", annotations, labels, servicePorts);
190190
KubernetesServiceInstance serviceInstance = mapper.map(service);
191-
Assertions.assertNotNull(serviceInstance);
192-
Assertions.assertTrue(output.getOut().contains("Did not find a port name that is equal to the value http"));
193-
Assertions.assertTrue(output.getOut().contains("Will return 'first' port found, which is non-deterministic"));
194-
Assertions.assertTrue(serviceInstance.getPort() == 80 || serviceInstance.getPort() == 443);
191+
Assertions.assertThat(serviceInstance).isNotNull();
192+
Assertions.assertThat(output.getOut()).contains("Did not find a port name that is equal to the value http");
193+
Assertions.assertThat(output.getOut()).contains("Will return 'first' port found, which is non-deterministic");
194+
Assertions.assertThat(serviceInstance.getPort()).isIn(80, 443);
195195
}
196196

197197
@Test
@@ -207,10 +207,10 @@ void multiPortsEmptyPortNameProperty(CapturedOutput output) {
207207
new V1ServicePortBuilder().withName("https").withPort(443).build());
208208
V1Service service = createService("database", "default", annotations, labels, servicePorts);
209209
KubernetesServiceInstance serviceInstance = mapper.map(service);
210-
Assertions.assertNotNull(serviceInstance);
211-
Assertions.assertTrue(output.getOut().contains("'spring.cloud.kubernetes.loadbalancer.portName' is not set"));
212-
Assertions.assertTrue(output.getOut().contains("Will return 'first' port found, which is non-deterministic"));
213-
Assertions.assertTrue(serviceInstance.getPort() == 80 || serviceInstance.getPort() == 443);
210+
Assertions.assertThat(serviceInstance).isNotNull();
211+
Assertions.assertThat(output.getOut()).contains("'spring.cloud.kubernetes.loadbalancer.portName' is not set");
212+
Assertions.assertThat(output.getOut()).contains("Will return 'first' port found, which is non-deterministic");
213+
Assertions.assertThat(serviceInstance.getPort()).isIn(80, 443);
214214
}
215215

216216
private V1Service createService(String name, String namespace, Map<String, String> annotations,

spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServicesListSupplierTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
import io.kubernetes.client.openapi.models.V1ServicePortBuilder;
3535
import io.kubernetes.client.openapi.models.V1ServiceSpecBuilder;
3636
import io.kubernetes.client.util.ClientBuilder;
37+
import org.assertj.core.api.Assertions;
3738
import org.junit.jupiter.api.AfterAll;
3839
import org.junit.jupiter.api.AfterEach;
39-
import org.junit.jupiter.api.Assertions;
4040
import org.junit.jupiter.api.BeforeAll;
4141
import org.junit.jupiter.api.Test;
4242
import org.junit.jupiter.api.extension.ExtendWith;
@@ -155,8 +155,8 @@ void singleNamespaceTest(CapturedOutput output) {
155155
services.add(serviceA);
156156

157157
StepVerifier.create(instances).expectNext(services).verifyComplete();
158-
Assertions.assertTrue(output.getOut().contains("serviceID : service-a"));
159-
Assertions.assertTrue(output.getOut().contains("discovering services in namespace : default"));
158+
Assertions.assertThat(output.getOut()).contains("serviceID : service-a");
159+
Assertions.assertThat(output.getOut()).contains("discovering services in namespace : default");
160160
}
161161

162162
@Test
@@ -186,9 +186,9 @@ void singleNamespaceNoServicePresentTest(CapturedOutput output) {
186186
List<ServiceInstance> services = List.of();
187187

188188
StepVerifier.create(instances).expectNext(services).verifyComplete();
189-
Assertions.assertTrue(output.getOut().contains("serviceID : service-a"));
190-
Assertions.assertTrue(output.getOut().contains("discovering services in namespace : default"));
191-
Assertions.assertTrue(output.getOut().contains("Error retrieving service with name service-a"));
189+
Assertions.assertThat(output.getOut()).contains("serviceID : service-a");
190+
Assertions.assertThat(output.getOut()).contains("discovering services in namespace : default");
191+
Assertions.assertThat(output.getOut()).contains("Error retrieving service with name service-a");
192192
}
193193

194194
@Test
@@ -226,7 +226,7 @@ void allNamespacesTest(CapturedOutput output) {
226226
services.add(serviceATestNamespace);
227227

228228
StepVerifier.create(instances).expectNext(services).verifyComplete();
229-
Assertions.assertTrue(output.getOut().contains("discovering services in all namespaces"));
229+
Assertions.assertThat(output.getOut()).contains("discovering services in all namespaces");
230230
}
231231

232232
@Test
@@ -271,10 +271,10 @@ void selectiveNamespacesTest(CapturedOutput output) {
271271
services.add(serviceATestNamespace);
272272

273273
StepVerifier.create(instances).expectNext(services).verifyComplete();
274-
Assertions.assertTrue(
275-
output.getOut().contains("Error retrieving service with name service-a in namespace : no-service"));
276-
Assertions.assertTrue(
277-
output.getOut().contains("discovering services in selective namespaces : [default, no-service, test]"));
274+
Assertions.assertThat(
275+
output.getOut()).contains("Error retrieving service with name service-a in namespace : no-service");
276+
Assertions.assertThat(
277+
output.getOut()).contains("discovering services in selective namespaces : [default, no-service, test]");
278278
}
279279

280280
}

0 commit comments

Comments
 (0)