From e912698135c237d8aab2eae11f7c2dcd68f67d20 Mon Sep 17 00:00:00 2001 From: wind57 Date: Fri, 28 Mar 2025 18:37:49 +0200 Subject: [PATCH] ,ore Signed-off-by: wind57 --- ...netesClientServiceInstanceMapperTests.java | 42 +++++++++---------- ...rnetesClientServicesListSupplierTests.java | 22 +++++----- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServiceInstanceMapperTests.java b/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServiceInstanceMapperTests.java index bc6e18eb..b92f9a36 100644 --- a/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServiceInstanceMapperTests.java +++ b/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServiceInstanceMapperTests.java @@ -25,7 +25,7 @@ import io.kubernetes.client.openapi.models.V1ServiceBuilder; import io.kubernetes.client.openapi.models.V1ServicePort; import io.kubernetes.client.openapi.models.V1ServicePortBuilder; import io.kubernetes.client.openapi.models.V1ServiceSpecBuilder; -import org.junit.jupiter.api.Assertions; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -116,9 +116,9 @@ class KubernetesClientServiceInstanceMapperTests { List servicePorts = List.of(); V1Service service = createService("database", "default", annotations, labels, servicePorts); KubernetesServiceInstance serviceInstance = mapper.map(service); - Assertions.assertNull(serviceInstance); - Assertions.assertTrue(output.getOut() - .contains("service : database does not have any ServicePort(s), will not consider it for load balancing")); + Assertions.assertThat(serviceInstance).isNull(); + Assertions.assertThat(output.getOut()).contains( + "service : database does not have any ServicePort(s), will not consider it for load balancing"); } @Test @@ -133,10 +133,10 @@ class KubernetesClientServiceInstanceMapperTests { List servicePorts = List.of(new V1ServicePortBuilder().withName("http").withPort(80).build()); V1Service service = createService("database", "default", annotations, labels, servicePorts); KubernetesServiceInstance serviceInstance = mapper.map(service); - Assertions.assertNotNull(serviceInstance); - Assertions.assertTrue(output.getOut() + Assertions.assertThat(serviceInstance).isNotNull(); + Assertions.assertThat(output.getOut()) .contains("single ServicePort found, " - + "will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')")); + + "will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')"); } @Test @@ -151,10 +151,10 @@ class KubernetesClientServiceInstanceMapperTests { List servicePorts = List.of(new V1ServicePortBuilder().withName("http").withPort(80).build()); V1Service service = createService("database", "default", annotations, labels, servicePorts); KubernetesServiceInstance serviceInstance = mapper.map(service); - Assertions.assertNotNull(serviceInstance); - Assertions.assertTrue(output.getOut() + Assertions.assertThat(serviceInstance).isNotNull(); + Assertions.assertThat(output.getOut()) .contains("single ServicePort found, " - + "will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')")); + + "will use it as-is (without checking 'spring.cloud.kubernetes.loadbalancer.portName')"); } @Test @@ -170,9 +170,9 @@ class KubernetesClientServiceInstanceMapperTests { new V1ServicePortBuilder().withName("https").withPort(443).build()); V1Service service = createService("database", "default", annotations, labels, servicePorts); KubernetesServiceInstance serviceInstance = mapper.map(service); - Assertions.assertNotNull(serviceInstance); - Assertions.assertTrue(output.getOut().contains("found port name that matches : http")); - Assertions.assertEquals(serviceInstance.getPort(), 80); + Assertions.assertThat(serviceInstance).isNotNull(); + Assertions.assertThat(output.getOut()).contains("found port name that matches : http"); + Assertions.assertThat(serviceInstance.getPort()).isEqualTo(80); } @Test @@ -188,10 +188,10 @@ class KubernetesClientServiceInstanceMapperTests { new V1ServicePortBuilder().withName("https").withPort(443).build()); V1Service service = createService("database", "default", annotations, labels, servicePorts); KubernetesServiceInstance serviceInstance = mapper.map(service); - Assertions.assertNotNull(serviceInstance); - Assertions.assertTrue(output.getOut().contains("Did not find a port name that is equal to the value http")); - Assertions.assertTrue(output.getOut().contains("Will return 'first' port found, which is non-deterministic")); - Assertions.assertTrue(serviceInstance.getPort() == 80 || serviceInstance.getPort() == 443); + Assertions.assertThat(serviceInstance).isNotNull(); + Assertions.assertThat(output.getOut()).contains("Did not find a port name that is equal to the value http"); + Assertions.assertThat(output.getOut()).contains("Will return 'first' port found, which is non-deterministic"); + Assertions.assertThat(serviceInstance.getPort()).isIn(80, 443); } @Test @@ -207,10 +207,10 @@ class KubernetesClientServiceInstanceMapperTests { new V1ServicePortBuilder().withName("https").withPort(443).build()); V1Service service = createService("database", "default", annotations, labels, servicePorts); KubernetesServiceInstance serviceInstance = mapper.map(service); - Assertions.assertNotNull(serviceInstance); - Assertions.assertTrue(output.getOut().contains("'spring.cloud.kubernetes.loadbalancer.portName' is not set")); - Assertions.assertTrue(output.getOut().contains("Will return 'first' port found, which is non-deterministic")); - Assertions.assertTrue(serviceInstance.getPort() == 80 || serviceInstance.getPort() == 443); + Assertions.assertThat(serviceInstance).isNotNull(); + Assertions.assertThat(output.getOut()).contains("'spring.cloud.kubernetes.loadbalancer.portName' is not set"); + Assertions.assertThat(output.getOut()).contains("Will return 'first' port found, which is non-deterministic"); + Assertions.assertThat(serviceInstance.getPort()).isIn(80, 443); } private V1Service createService(String name, String namespace, Map annotations, diff --git a/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServicesListSupplierTests.java b/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServicesListSupplierTests.java index 423ce00f..d8158463 100644 --- a/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServicesListSupplierTests.java +++ b/spring-cloud-kubernetes-client-loadbalancer/src/test/java/org/springframework/cloud/kubernetes/client/loadbalancer/KubernetesClientServicesListSupplierTests.java @@ -34,9 +34,9 @@ import io.kubernetes.client.openapi.models.V1ServiceList; import io.kubernetes.client.openapi.models.V1ServicePortBuilder; import io.kubernetes.client.openapi.models.V1ServiceSpecBuilder; import io.kubernetes.client.util.ClientBuilder; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -155,8 +155,8 @@ class KubernetesClientServicesListSupplierTests { services.add(serviceA); StepVerifier.create(instances).expectNext(services).verifyComplete(); - Assertions.assertTrue(output.getOut().contains("serviceID : service-a")); - Assertions.assertTrue(output.getOut().contains("discovering services in namespace : default")); + Assertions.assertThat(output.getOut()).contains("serviceID : service-a"); + Assertions.assertThat(output.getOut()).contains("discovering services in namespace : default"); } @Test @@ -186,9 +186,9 @@ class KubernetesClientServicesListSupplierTests { List services = List.of(); StepVerifier.create(instances).expectNext(services).verifyComplete(); - Assertions.assertTrue(output.getOut().contains("serviceID : service-a")); - Assertions.assertTrue(output.getOut().contains("discovering services in namespace : default")); - Assertions.assertTrue(output.getOut().contains("Error retrieving service with name service-a")); + Assertions.assertThat(output.getOut()).contains("serviceID : service-a"); + Assertions.assertThat(output.getOut()).contains("discovering services in namespace : default"); + Assertions.assertThat(output.getOut()).contains("Error retrieving service with name service-a"); } @Test @@ -226,7 +226,7 @@ class KubernetesClientServicesListSupplierTests { services.add(serviceATestNamespace); StepVerifier.create(instances).expectNext(services).verifyComplete(); - Assertions.assertTrue(output.getOut().contains("discovering services in all namespaces")); + Assertions.assertThat(output.getOut()).contains("discovering services in all namespaces"); } @Test @@ -271,10 +271,10 @@ class KubernetesClientServicesListSupplierTests { services.add(serviceATestNamespace); StepVerifier.create(instances).expectNext(services).verifyComplete(); - Assertions.assertTrue( - output.getOut().contains("Error retrieving service with name service-a in namespace : no-service")); - Assertions.assertTrue( - output.getOut().contains("discovering services in selective namespaces : [default, no-service, test]")); + Assertions.assertThat( + output.getOut()).contains("Error retrieving service with name service-a in namespace : no-service"); + Assertions.assertThat( + output.getOut()).contains("discovering services in selective namespaces : [default, no-service, test]"); } }