diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigDataLocationResolverTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigDataLocationResolverTests.java index 178ecda3..75e78a9f 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigDataLocationResolverTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigDataLocationResolverTests.java @@ -20,7 +20,7 @@ import java.util.function.Supplier; import io.kubernetes.client.openapi.ApiClient; import io.kubernetes.client.openapi.apis.CoreV1Api; -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; import org.mockito.Mockito; @@ -78,15 +78,15 @@ class KubernetesClientConfigDataLocationResolverTests { ConfigDataLocation configDataLocation = ConfigDataLocation.of("kubernetes:abc"); RESOLVER.resolveProfileSpecific(RESOLVER_CONTEXT, configDataLocation, profiles); - Assertions.assertTrue(context.isRegistered(KubernetesClientProperties.class)); - Assertions.assertTrue(context.isRegistered(CoreV1Api.class)); - Assertions.assertTrue(context.isRegistered(ApiClient.class)); + Assertions.assertThat(context.isRegistered(KubernetesClientProperties.class)).isTrue(); + Assertions.assertThat(context.isRegistered(CoreV1Api.class)).isTrue(); + Assertions.assertThat(context.isRegistered(ApiClient.class)).isTrue(); - Assertions.assertFalse(context.isRegistered(ConfigMapConfigProperties.class)); - Assertions.assertFalse(context.isRegistered(SecretsConfigProperties.class)); + Assertions.assertThat(context.isRegistered(ConfigMapConfigProperties.class)).isFalse(); + Assertions.assertThat(context.isRegistered(SecretsConfigProperties.class)).isFalse(); - Assertions.assertFalse(context.isRegistered(ConfigMapPropertySourceLocator.class)); - Assertions.assertFalse(context.isRegistered(SecretsPropertySourceLocator.class)); + Assertions.assertThat(context.isRegistered(ConfigMapPropertySourceLocator.class)).isFalse(); + Assertions.assertThat(context.isRegistered(SecretsPropertySourceLocator.class)).isFalse(); } /* @@ -114,24 +114,24 @@ class KubernetesClientConfigDataLocationResolverTests { ConfigDataLocation configDataLocation = ConfigDataLocation.of("kubernetes:abc"); RESOLVER.resolveProfileSpecific(RESOLVER_CONTEXT, configDataLocation, profiles); - Assertions.assertTrue(context.isRegistered(KubernetesClientProperties.class)); - Assertions.assertTrue(context.isRegistered(CoreV1Api.class)); - Assertions.assertTrue(context.isRegistered(ApiClient.class)); + Assertions.assertThat(context.isRegistered(KubernetesClientProperties.class)).isTrue(); + Assertions.assertThat(context.isRegistered(CoreV1Api.class)).isTrue(); + Assertions.assertThat(context.isRegistered(ApiClient.class)).isTrue(); - Assertions.assertTrue(context.isRegistered(ConfigMapConfigProperties.class)); - Assertions.assertTrue(context.isRegistered(SecretsConfigProperties.class)); + Assertions.assertThat(context.isRegistered(ConfigMapConfigProperties.class)).isTrue(); + Assertions.assertThat(context.isRegistered(SecretsConfigProperties.class)).isTrue(); - Assertions.assertTrue(context.isRegistered(ConfigMapPropertySourceLocator.class)); - Assertions.assertTrue(context.isRegistered(SecretsPropertySourceLocator.class)); + Assertions.assertThat(context.isRegistered(ConfigMapPropertySourceLocator.class)).isTrue(); + Assertions.assertThat(context.isRegistered(SecretsPropertySourceLocator.class)).isTrue(); ConfigMapPropertySourceLocator configMapPropertySourceLocator = context .get(ConfigMapPropertySourceLocator.class); - Assertions.assertSame(KubernetesClientConfigMapPropertySourceLocator.class, - configMapPropertySourceLocator.getClass()); + Assertions.assertThat(configMapPropertySourceLocator.getClass()).isEqualTo( + KubernetesClientConfigMapPropertySourceLocator.class); SecretsPropertySourceLocator secretsPropertySourceLocator = context.get(SecretsPropertySourceLocator.class); - Assertions.assertSame(KubernetesClientSecretsPropertySourceLocator.class, - secretsPropertySourceLocator.getClass()); + Assertions.assertThat(secretsPropertySourceLocator.getClass()).isEqualTo( + KubernetesClientSecretsPropertySourceLocator.class); } @@ -161,25 +161,25 @@ class KubernetesClientConfigDataLocationResolverTests { ConfigDataLocation configDataLocation = ConfigDataLocation.of("kubernetes:abc"); RESOLVER.resolveProfileSpecific(RESOLVER_CONTEXT, configDataLocation, profiles); - Assertions.assertTrue(context.isRegistered(KubernetesClientProperties.class)); - Assertions.assertTrue(context.isRegistered(CoreV1Api.class)); - Assertions.assertTrue(context.isRegistered(ApiClient.class)); + Assertions.assertThat(context.isRegistered(KubernetesClientProperties.class)).isTrue(); + Assertions.assertThat(context.isRegistered(CoreV1Api.class)).isTrue(); + Assertions.assertThat(context.isRegistered(ApiClient.class)).isTrue(); - Assertions.assertTrue(context.isRegistered(ConfigMapConfigProperties.class)); - Assertions.assertTrue(context.isRegistered(SecretsConfigProperties.class)); + Assertions.assertThat(context.isRegistered(ConfigMapConfigProperties.class)).isTrue(); + Assertions.assertThat(context.isRegistered(SecretsConfigProperties.class)).isTrue(); ConfigMapPropertySourceLocator configMapPropertySourceLocator = context .get(ConfigMapPropertySourceLocator.class); - Assertions.assertSame(KubernetesClientConfigMapPropertySourceLocator.class, - configMapPropertySourceLocator.getClass()); + Assertions.assertThat(configMapPropertySourceLocator.getClass()).isEqualTo( + KubernetesClientConfigMapPropertySourceLocator.class); SecretsPropertySourceLocator secretsPropertySourceLocator = context.get(SecretsPropertySourceLocator.class); - Assertions.assertSame(KubernetesClientSecretsPropertySourceLocator.class, - secretsPropertySourceLocator.getClass()); + Assertions.assertThat(secretsPropertySourceLocator.getClass()).isEqualTo( + KubernetesClientSecretsPropertySourceLocator.class); - Assertions.assertTrue(capturedOutput.getOut() + Assertions.assertThat(capturedOutput.getOut()) .contains("Could not create the Kubernetes ApiClient in a cluster environment, because connection port " - + "was not provided.")); + + "was not provided."); } /* @@ -211,24 +211,24 @@ class KubernetesClientConfigDataLocationResolverTests { ConfigDataLocation configDataLocation = ConfigDataLocation.of("kubernetes:abc"); RESOLVER.resolveProfileSpecific(RESOLVER_CONTEXT, configDataLocation, profiles); - Assertions.assertTrue(context.isRegistered(KubernetesClientProperties.class)); - Assertions.assertTrue(context.isRegistered(CoreV1Api.class)); - Assertions.assertTrue(context.isRegistered(ApiClient.class)); + Assertions.assertThat(context.isRegistered(KubernetesClientProperties.class)).isTrue(); + Assertions.assertThat(context.isRegistered(CoreV1Api.class)).isTrue(); + Assertions.assertThat(context.isRegistered(ApiClient.class)).isTrue(); - Assertions.assertTrue(context.isRegistered(ConfigMapConfigProperties.class)); - Assertions.assertTrue(context.isRegistered(SecretsConfigProperties.class)); + Assertions.assertThat(context.isRegistered(ConfigMapConfigProperties.class)).isTrue(); + Assertions.assertThat(context.isRegistered(SecretsConfigProperties.class)).isTrue(); - Assertions.assertTrue(context.isRegistered(ConfigMapPropertySourceLocator.class)); - Assertions.assertTrue(context.isRegistered(SecretsPropertySourceLocator.class)); + Assertions.assertThat(context.isRegistered(ConfigMapPropertySourceLocator.class)).isTrue(); + Assertions.assertThat(context.isRegistered(SecretsPropertySourceLocator.class)).isTrue(); ConfigMapPropertySourceLocator configMapPropertySourceLocator = context .get(ConfigMapPropertySourceLocator.class); - Assertions.assertSame(ConfigDataRetryableConfigMapPropertySourceLocator.class, - configMapPropertySourceLocator.getClass()); + Assertions.assertThat(configMapPropertySourceLocator.getClass()).isEqualTo( + ConfigDataRetryableConfigMapPropertySourceLocator.class); SecretsPropertySourceLocator secretsPropertySourceLocator = context.get(SecretsPropertySourceLocator.class); - Assertions.assertSame(ConfigDataRetryableSecretsPropertySourceLocator.class, - secretsPropertySourceLocator.getClass()); + Assertions.assertThat(secretsPropertySourceLocator.getClass()).isEqualTo( + ConfigDataRetryableSecretsPropertySourceLocator.class); } diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigReloadAutoConfigurationTest.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigReloadAutoConfigurationTest.java index a78b344d..f7e8b879 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigReloadAutoConfigurationTest.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigReloadAutoConfigurationTest.java @@ -31,8 +31,8 @@ import io.kubernetes.client.openapi.models.V1ConfigMapBuilder; import io.kubernetes.client.openapi.models.V1ConfigMapList; import io.kubernetes.client.openapi.models.V1ObjectMetaBuilder; import io.kubernetes.client.util.ClientBuilder; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -177,12 +177,9 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { setup("spring.cloud.bootstrap.enabled=true", "spring.cloud.kubernetes.reload.enabled=true", "spring.main.cloud-platform=KUBERNETES"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 1); - Assertions.assertTrue(map.values() - .iterator() - .next() - .getClass() - .isAssignableFrom(KubernetesClientEventBasedConfigMapChangeDetector.class)); + Assertions.assertThat(1).isEqualTo(map.size()); + Assertions.assertThat(map.values().iterator().next().getClass()) + .isAssignableFrom(KubernetesClientEventBasedConfigMapChangeDetector.class); } /** @@ -201,12 +198,9 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { setup("spring.cloud.bootstrap.enabled=true", "spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=event", "spring.main.cloud-platform=KUBERNETES"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 1); - Assertions.assertTrue(map.values() - .iterator() - .next() - .getClass() - .isAssignableFrom(KubernetesClientEventBasedConfigMapChangeDetector.class)); + Assertions.assertThat(1).isEqualTo(map.size()); + Assertions.assertThat(map.values().iterator().next().getClass()) + .isAssignableFrom(KubernetesClientEventBasedConfigMapChangeDetector.class); } /** @@ -225,7 +219,7 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { setup("spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=event", "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.reload.monitoring-configMaps=false"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 0); + Assertions.assertThat(map).isEmpty(); } /** @@ -244,7 +238,7 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { setup("spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=polling", "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.reload.monitoring-configMaps=false"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 0); + Assertions.assertThat(map).isEmpty(); } /** @@ -263,9 +257,9 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { setup("spring.cloud.bootstrap.enabled=true", "spring.cloud.kubernetes.reload.enabled=true", "spring.cloud.kubernetes.reload.mode=polling", "spring.main.cloud-platform=KUBERNETES"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 1); - Assertions.assertTrue( - map.values().iterator().next().getClass().isAssignableFrom(PollingConfigMapChangeDetector.class)); + Assertions.assertThat(1).isEqualTo(map.size()); + Assertions.assertThat(map.values().iterator().next().getClass()) + .isAssignableFrom(PollingConfigMapChangeDetector.class); } /** @@ -287,12 +281,10 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { "spring.cloud.kubernetes.reload.monitoring-configMaps=false", "spring.cloud.kubernetes.reload.mode=event"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 1); - Assertions.assertTrue(map.values() - .iterator() - .next() - .getClass() - .isAssignableFrom(KubernetesClientEventBasedSecretsChangeDetector.class)); + Assertions.assertThat(1).isEqualTo(map.size()); + Assertions.assertThat(map.values().iterator().next().getClass()) + .isAssignableFrom(KubernetesClientEventBasedSecretsChangeDetector.class); + } /** @@ -314,9 +306,9 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { "spring.cloud.kubernetes.reload.monitoring-configMaps=false", "spring.cloud.kubernetes.reload.mode=polling"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 1); - Assertions - .assertTrue(map.values().iterator().next().getClass().isAssignableFrom(PollingSecretsChangeDetector.class)); + Assertions.assertThat(1).isEqualTo(map.size()); + Assertions.assertThat(map.values().iterator().next().getClass()) + .isAssignableFrom(PollingSecretsChangeDetector.class); } /** @@ -338,13 +330,13 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { "spring.cloud.kubernetes.reload.monitoring-configMaps=true", "spring.cloud.kubernetes.reload.mode=event"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 2); + Assertions.assertThat(map.size()).isEqualTo(2); List result = map.values() .stream() .sorted(Comparator.comparing(x -> x.getClass().getName())) .toList(); - Assertions.assertEquals(result.get(0).getClass(), KubernetesClientEventBasedConfigMapChangeDetector.class); - Assertions.assertEquals(result.get(1).getClass(), KubernetesClientEventBasedSecretsChangeDetector.class); + Assertions.assertThat(result.get(0).getClass()).isEqualTo(KubernetesClientEventBasedConfigMapChangeDetector.class); + Assertions.assertThat(result.get(1).getClass()).isEqualTo(KubernetesClientEventBasedSecretsChangeDetector.class); } /** @@ -366,13 +358,13 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { "spring.cloud.kubernetes.reload.monitoring-configMaps=true", "spring.cloud.kubernetes.reload.mode=polling"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 2); + Assertions.assertThat(map.size()).isEqualTo(2); List result = map.values() .stream() .sorted(Comparator.comparing(x -> x.getClass().getName())) .toList(); - Assertions.assertEquals(result.get(0).getClass(), PollingConfigMapChangeDetector.class); - Assertions.assertEquals(result.get(1).getClass(), PollingSecretsChangeDetector.class); + Assertions.assertThat(result.get(0).getClass()).isEqualTo(PollingConfigMapChangeDetector.class); + Assertions.assertThat(result.get(1).getClass()).isEqualTo(PollingSecretsChangeDetector.class); } /** @@ -393,7 +385,7 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.reload.monitoring-configMaps=false", "spring.cloud.kubernetes.reload.monitoring-secrets=false"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 0); + Assertions.assertThat(map).isEmpty(); } /** @@ -414,7 +406,7 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { "spring.main.cloud-platform=KUBERNETES", "spring.cloud.kubernetes.reload.monitoring-configMaps=false", "spring.cloud.kubernetes.reload.monitoring-secrets=false"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 0); + Assertions.assertThat(map).isEmpty(); } /** @@ -436,12 +428,12 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { "spring.cloud.kubernetes.reload.monitoring-configMaps=true", "spring.cloud.kubernetes.reload.monitoring-secrets=false"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 1); + Assertions.assertThat(map.size()).isEqualTo(1); List result = map.values() .stream() .sorted(Comparator.comparing(x -> x.getClass().getName())) .toList(); - Assertions.assertEquals(result.get(0).getClass(), KubernetesClientEventBasedConfigMapChangeDetector.class); + Assertions.assertThat(result.get(0).getClass()).isEqualTo(KubernetesClientEventBasedConfigMapChangeDetector.class); } /** @@ -463,12 +455,12 @@ public class KubernetesClientConfigReloadAutoConfigurationTest { "spring.cloud.kubernetes.reload.monitoring-configMaps=true", "spring.cloud.kubernetes.reload.monitoring-secrets=false"); Map map = context.getBeansOfType(ConfigurationChangeDetector.class); - Assertions.assertEquals(map.size(), 1); + Assertions.assertThat(map.size()).isEqualTo(1); List result = map.values() .stream() .sorted(Comparator.comparing(x -> x.getClass().getName())) .toList(); - Assertions.assertEquals(result.get(0).getClass(), PollingConfigMapChangeDetector.class); + Assertions.assertThat(result.get(0).getClass()).isEqualTo(PollingConfigMapChangeDetector.class); } // 2. config and secrets property source locators diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigUtilsTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigUtilsTests.java index b2cdfee6..eae1ff69 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigUtilsTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/KubernetesClientConfigUtilsTests.java @@ -19,7 +19,7 @@ package org.springframework.cloud.kubernetes.client.config; import java.time.Duration; import java.util.Set; -import org.junit.jupiter.api.Assertions; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; @@ -38,8 +38,8 @@ class KubernetesClientConfigUtilsTests { Duration.ofMillis(15000), Set.of("non-default"), false, Duration.ofSeconds(2)); Set namespaces = KubernetesClientConfigUtils .namespaces(new KubernetesNamespaceProvider(new MockEnvironment()), properties, "configmap"); - Assertions.assertEquals(1, namespaces.size()); - Assertions.assertEquals(namespaces.iterator().next(), "non-default"); + Assertions.assertThat(1).isEqualTo(namespaces.size()); + Assertions.assertThat("non-default").isEqualTo(namespaces.iterator().next()); } @Test @@ -49,8 +49,8 @@ class KubernetesClientConfigUtilsTests { environment.setProperty("spring.cloud.kubernetes.client.namespace", "some"); KubernetesNamespaceProvider provider = new KubernetesNamespaceProvider(environment); Set namespaces = KubernetesClientConfigUtils.namespaces(provider, properties, "configmap"); - Assertions.assertEquals(1, namespaces.size()); - Assertions.assertEquals(namespaces.iterator().next(), "some"); + Assertions.assertThat(1).isEqualTo(namespaces.size()); + Assertions.assertThat("some").isEqualTo(namespaces.iterator().next()); } } diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProviderTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProviderTests.java index 44840858..378ba2e7 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProviderTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledConfigMapContextToSourceDataProviderTests.java @@ -32,8 +32,8 @@ import io.kubernetes.client.openapi.models.V1ConfigMapBuilder; import io.kubernetes.client.openapi.models.V1ConfigMapList; import io.kubernetes.client.openapi.models.V1ObjectMetaBuilder; import io.kubernetes.client.util.ClientBuilder; +import org.assertj.core.api.Assertions; 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; @@ -116,8 +116,8 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals("configmap.test-configmap.default", sourceData.sourceName()); - Assertions.assertEquals(Map.of("name", "value"), sourceData.sourceData()); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.test-configmap.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Map.of("name", "value")); } @@ -166,10 +166,10 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.red-configmap.red-configmap-again.default"); - Assertions.assertEquals(sourceData.sourceData().size(), 2); - Assertions.assertEquals(sourceData.sourceData().get("colorOne"), "really-red"); - Assertions.assertEquals(sourceData.sourceData().get("colorTwo"), "really-red-again"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.red-configmap.red-configmap-again.default"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2); + Assertions.assertThat(sourceData.sourceData().get("colorOne")).isEqualTo("really-red"); + Assertions.assertThat(sourceData.sourceData().get("colorTwo")).isEqualTo("really-red-again"); } @@ -198,8 +198,8 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.color.default"); - Assertions.assertEquals(sourceData.sourceData(), Collections.emptyMap()); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.color.default"); + Assertions.assertThat(sourceData.sourceData()).isEmpty(); } @@ -231,8 +231,8 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals("configmap.test-configmap.default", sourceData.sourceName()); - Assertions.assertEquals(Map.of("name", "value"), sourceData.sourceData()); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.test-configmap.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Map.of("name", "value")); } /** @@ -263,8 +263,8 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals("configmap.blue-configmap.default", sourceData.sourceName()); - Assertions.assertEquals(Map.of("me.what-color", "blue-color"), sourceData.sourceData()); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.blue-configmap.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Map.of("me.what-color", "blue-color")); } /** @@ -309,21 +309,21 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.another-blue-configmap.blue-configmap.default"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.another-blue-configmap.blue-configmap.default"); Map properties = sourceData.sourceData(); - Assertions.assertEquals(2, properties.size()); + Assertions.assertThat(properties.size()).isEqualTo(2); Iterator keys = properties.keySet().iterator(); String firstKey = keys.next(); String secondKey = keys.next(); if (firstKey.contains("first")) { - Assertions.assertEquals(firstKey, "another-blue-configmap.blue-configmap.first"); + Assertions.assertThat(firstKey).isEqualTo("another-blue-configmap.blue-configmap.first"); } - Assertions.assertEquals(secondKey, "another-blue-configmap.blue-configmap.second"); - Assertions.assertEquals(properties.get(firstKey), "blue"); - Assertions.assertEquals(properties.get(secondKey), "blue"); + Assertions.assertThat(secondKey).isEqualTo("another-blue-configmap.blue-configmap.second"); + Assertions.assertThat(properties.get(firstKey)).isEqualTo("blue"); + Assertions.assertThat(properties.get(secondKey)).isEqualTo("blue"); } /** @@ -361,8 +361,8 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertTrue(sourceData.sourceData().isEmpty()); - Assertions.assertEquals(sourceData.sourceName(), "configmap.color.default"); + Assertions.assertThat(sourceData.sourceData()).isEmpty(); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.color.default"); } @@ -400,9 +400,9 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceData().size(), 1); - Assertions.assertEquals(sourceData.sourceData().get("one"), "1"); - Assertions.assertEquals(sourceData.sourceName(), "configmap.color-configmap.default"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(1); + Assertions.assertThat(sourceData.sourceData().get("one")).isEqualTo("1"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.color-configmap.default"); } @@ -445,10 +445,10 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceData().size(), 2); - Assertions.assertEquals(sourceData.sourceData().get("color-configmap.color-configmap-k8s.one"), "1"); - Assertions.assertEquals(sourceData.sourceData().get("color-configmap.color-configmap-k8s.two"), "2"); - Assertions.assertEquals(sourceData.sourceName(), "configmap.color-configmap.color-configmap-k8s.default"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2); + Assertions.assertThat(sourceData.sourceData().get("color-configmap.color-configmap-k8s.one")).isEqualTo("1"); + Assertions.assertThat(sourceData.sourceData().get("color-configmap.color-configmap-k8s.two")).isEqualTo("2"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.color-configmap.color-configmap-k8s.default"); } @@ -522,17 +522,17 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceData().size(), 4); - Assertions.assertEquals(sourceData.sourceData() - .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.one"), "1"); - Assertions.assertEquals(sourceData.sourceData() - .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.two"), "2"); - Assertions.assertEquals(sourceData.sourceData() - .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.four"), "4"); - Assertions.assertEquals(sourceData.sourceData() - .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.five"), "5"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(4); + Assertions.assertThat(sourceData.sourceData() + .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.one")).isEqualTo("1"); + Assertions.assertThat(sourceData.sourceData() + .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.two")).isEqualTo("2"); + Assertions.assertThat(sourceData.sourceData() + .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.four")).isEqualTo("4"); + Assertions.assertThat(sourceData.sourceData() + .get("color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.five")).isEqualTo("5"); - Assertions.assertEquals(sourceData.sourceName(), + Assertions.assertThat(sourceData.sourceName()).isEqualTo( "configmap.color-configmap.color-configmap-k8s.shape-configmap.shape-configmap-k8s.default"); } @@ -576,10 +576,10 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData redData = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData redSourceData = redData.apply(redContext); - Assertions.assertEquals(redSourceData.sourceData().size(), 1); - Assertions.assertEquals(redSourceData.sourceData().get("color"), "red"); - Assertions.assertEquals(redSourceData.sourceName(), "configmap.red-configmap.default"); - Assertions.assertTrue(output.getAll().contains("Loaded all config maps in namespace '" + NAMESPACE + "'")); + Assertions.assertThat(redSourceData.sourceData().size()).isEqualTo(1); + Assertions.assertThat(redSourceData.sourceData().get("color")).isEqualTo("red"); + Assertions.assertThat(redSourceData.sourceName()).isEqualTo("configmap.red-configmap.default"); + Assertions.assertThat(output.getAll()).contains("Loaded all config maps in namespace '" + NAMESPACE + "'"); NormalizedSource greenSource = new LabeledConfigMapNormalizedSource(NAMESPACE, Map.of("color", "green"), false, ConfigUtils.Prefix.DEFAULT, false); @@ -588,17 +588,17 @@ class LabeledConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData greenData = new LabeledConfigMapContextToSourceDataProvider().get(); SourceData greenSourceData = greenData.apply(greenContext); - Assertions.assertEquals(greenSourceData.sourceData().size(), 1); - Assertions.assertEquals(greenSourceData.sourceData().get("color"), "green"); - Assertions.assertEquals(greenSourceData.sourceName(), "configmap.green-configmap.default"); + Assertions.assertThat(greenSourceData.sourceData().size()).isEqualTo(1); + Assertions.assertThat(greenSourceData.sourceData().get("color")).isEqualTo("green"); + Assertions.assertThat(greenSourceData.sourceName()).isEqualTo("configmap.green-configmap.default"); // meaning there is a single entry with such a log statement String[] out = output.getAll().split("Loaded all config maps in namespace"); - Assertions.assertEquals(out.length, 2); + Assertions.assertThat(out.length).isEqualTo(2); // meaning that the second read was done from the cache out = output.getAll().split("Loaded \\(from cache\\) all config maps in namespace"); - Assertions.assertEquals(out.length, 2); + Assertions.assertThat(out.length).isEqualTo(2); } private void stubCall(V1ConfigMapList list) { diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProviderTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProviderTests.java index 9a666509..2f96f9ed 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProviderTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/LabeledSecretContextToSourceDataProviderTests.java @@ -33,8 +33,8 @@ import io.kubernetes.client.openapi.models.V1Secret; import io.kubernetes.client.openapi.models.V1SecretBuilder; import io.kubernetes.client.openapi.models.V1SecretList; import io.kubernetes.client.util.ClientBuilder; +import org.assertj.core.api.Assertions; 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; @@ -114,8 +114,8 @@ class LabeledSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.color.default"); - Assertions.assertEquals(sourceData.sourceData(), Collections.emptyMap()); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.color.default"); + Assertions.assertThat(sourceData.sourceData()).isEmpty(); } @@ -142,8 +142,8 @@ class LabeledSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.test-secret.default"); - Assertions.assertEquals(sourceData.sourceData(), Map.of("color", "really-red")); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.test-secret.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Map.of("color", "really-red")); } @@ -174,10 +174,10 @@ class LabeledSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.color-one.color-two.default"); - Assertions.assertEquals(sourceData.sourceData().size(), 2); - Assertions.assertEquals(sourceData.sourceData().get("colorOne"), "really-red-one"); - Assertions.assertEquals(sourceData.sourceData().get("colorTwo"), "really-red-two"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.color-one.color-two.default"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2); + Assertions.assertThat(sourceData.sourceData().get("colorOne")).isEqualTo("really-red-one"); + Assertions.assertThat(sourceData.sourceData().get("colorTwo")).isEqualTo("really-red-two"); } @@ -199,8 +199,8 @@ class LabeledSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.test-secret.default"); - Assertions.assertEquals(sourceData.sourceData(), Map.of("color", "really-red")); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.test-secret.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Map.of("color", "really-red")); } /** @@ -233,8 +233,8 @@ class LabeledSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals("secret.blue-secret.default", sourceData.sourceName()); - Assertions.assertEquals(Map.of("me.what-color", "blue-color"), sourceData.sourceData()); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.blue-secret.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Map.of("me.what-color", "blue-color")); } /** @@ -279,25 +279,25 @@ class LabeledSecretContextToSourceDataProviderTests { SourceData sourceData = data.apply(context); // maps don't have a defined order, so assert components separately - Assertions.assertEquals(46, sourceData.sourceName().length()); - Assertions.assertTrue(sourceData.sourceName().contains("secret")); - Assertions.assertTrue(sourceData.sourceName().contains("blue-secret")); - Assertions.assertTrue(sourceData.sourceName().contains("another-blue-secret")); - Assertions.assertTrue(sourceData.sourceName().contains("default")); + Assertions.assertThat(sourceData.sourceName().length()).isEqualTo(46); + Assertions.assertThat(sourceData.sourceName()).contains("secret"); + Assertions.assertThat(sourceData.sourceName()).contains("blue-secret"); + Assertions.assertThat(sourceData.sourceName()).contains("another-blue-secret"); + Assertions.assertThat(sourceData.sourceName()).contains("default"); Map properties = sourceData.sourceData(); - Assertions.assertEquals(2, properties.size()); + Assertions.assertThat(properties.size()).isEqualTo(2); Iterator keys = properties.keySet().iterator(); String firstKey = keys.next(); String secondKey = keys.next(); if (firstKey.contains("first")) { - Assertions.assertEquals(firstKey, "another-blue-secret.blue-secret.first"); + Assertions.assertThat(firstKey).isEqualTo("another-blue-secret.blue-secret.first"); } - Assertions.assertEquals(secondKey, "another-blue-secret.blue-secret.second"); - Assertions.assertEquals(properties.get(firstKey), "blue"); - Assertions.assertEquals(properties.get(secondKey), "blue"); + Assertions.assertThat(secondKey).isEqualTo("another-blue-secret.blue-secret.second"); + Assertions.assertThat(properties.get(firstKey)).isEqualTo("blue"); + Assertions.assertThat(properties.get(secondKey)).isEqualTo("blue"); } /** @@ -337,9 +337,9 @@ class LabeledSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceData().size(), 1); - Assertions.assertEquals(sourceData.sourceData().get("one"), "1"); - Assertions.assertEquals(sourceData.sourceName(), "secret.color-secret.default"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(1); + Assertions.assertThat(sourceData.sourceData().get("one")).isEqualTo("1"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.color-secret.default"); } @@ -382,10 +382,10 @@ class LabeledSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceData().size(), 2); - Assertions.assertEquals(sourceData.sourceData().get("color-secret.color-secret-k8s.one"), "1"); - Assertions.assertEquals(sourceData.sourceData().get("color-secret.color-secret-k8s.two"), "2"); - Assertions.assertEquals(sourceData.sourceName(), "secret.color-secret.color-secret-k8s.default"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2); + Assertions.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.one")).isEqualTo("1"); + Assertions.assertThat(sourceData.sourceData().get("color-secret.color-secret-k8s.two")).isEqualTo("2"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.color-secret.color-secret-k8s.default"); } @@ -459,17 +459,17 @@ class LabeledSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceData().size(), 4); - Assertions.assertEquals( - sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.one"), "1"); - Assertions.assertEquals( - sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.two"), "2"); - Assertions.assertEquals( - sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.four"), "4"); - Assertions.assertEquals( - sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.five"), "5"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(4); + Assertions.assertThat( + sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.one")).isEqualTo("1"); + Assertions.assertThat( + sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.two")).isEqualTo("2"); + Assertions.assertThat( + sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.four")).isEqualTo("4"); + Assertions.assertThat( + sourceData.sourceData().get("color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.five")).isEqualTo("5"); - Assertions.assertEquals(sourceData.sourceName(), + Assertions.assertThat(sourceData.sourceName()).isEqualTo( "secret.color-secret.color-secret-k8s.shape-secret.shape-secret-k8s.default"); } @@ -500,9 +500,9 @@ class LabeledSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new LabeledSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceData().size(), 1); - Assertions.assertEquals(sourceData.sourceData().get("color"), "blue"); - Assertions.assertEquals(sourceData.sourceName(), "secret.color-secret.default"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(1); + Assertions.assertThat(sourceData.sourceData().get("color")).isEqualTo("blue"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.color-secret.default"); } /** @@ -544,10 +544,10 @@ class LabeledSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData redData = new LabeledSecretContextToSourceDataProvider().get(); SourceData redSourceData = redData.apply(redContext); - Assertions.assertEquals(redSourceData.sourceData().size(), 1); - Assertions.assertEquals(redSourceData.sourceData().get("color"), "red"); - Assertions.assertEquals(redSourceData.sourceName(), "secret.red.default"); - Assertions.assertTrue(output.getAll().contains("Loaded all secrets in namespace '" + NAMESPACE + "'")); + Assertions.assertThat(redSourceData.sourceData().size()).isEqualTo(1); + Assertions.assertThat(redSourceData.sourceData().get("color")).isEqualTo("red"); + Assertions.assertThat(redSourceData.sourceName()).isEqualTo("secret.red.default"); + Assertions.assertThat(output.getOut()).contains("Loaded all secrets in namespace '" + NAMESPACE + "'"); NormalizedSource greenSource = new LabeledSecretNormalizedSource(NAMESPACE, Map.of("color", "green"), false, ConfigUtils.Prefix.DEFAULT, false); @@ -556,17 +556,17 @@ class LabeledSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData greenData = new LabeledSecretContextToSourceDataProvider().get(); SourceData greenSourceData = greenData.apply(greenContext); - Assertions.assertEquals(greenSourceData.sourceData().size(), 1); - Assertions.assertEquals(greenSourceData.sourceData().get("color"), "green"); - Assertions.assertEquals(greenSourceData.sourceName(), "secret.green.default"); + Assertions.assertThat(greenSourceData.sourceData().size()).isEqualTo(1); + Assertions.assertThat(greenSourceData.sourceData().get("color")).isEqualTo("green"); + Assertions.assertThat(greenSourceData.sourceName()).isEqualTo("secret.green.default"); // meaning there is a single entry with such a log statement String[] out = output.getAll().split("Loaded all secrets in namespace"); - Assertions.assertEquals(out.length, 2); + Assertions.assertThat(out.length).isEqualTo(2); // meaning that the second read was done from the cache out = output.getAll().split("Loaded \\(from cache\\) all secrets in namespace"); - Assertions.assertEquals(out.length, 2); + Assertions.assertThat(out.length).isEqualTo(2); } private void stubCall(V1SecretList list) { diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/NamedConfigMapContextToSourceDataProviderTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/NamedConfigMapContextToSourceDataProviderTests.java index dcdbda38..e32e01ab 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/NamedConfigMapContextToSourceDataProviderTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/NamedConfigMapContextToSourceDataProviderTests.java @@ -30,8 +30,8 @@ import io.kubernetes.client.openapi.models.V1ConfigMapBuilder; import io.kubernetes.client.openapi.models.V1ConfigMapList; import io.kubernetes.client.openapi.models.V1ObjectMetaBuilder; import io.kubernetes.client.util.ClientBuilder; +import org.assertj.core.api.Assertions; 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; @@ -109,8 +109,8 @@ class NamedConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.blue.default"); - Assertions.assertEquals(sourceData.sourceData(), Map.of()); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.blue.default"); + Assertions.assertThat(sourceData.sourceData()).isEmpty(); } @@ -139,8 +139,8 @@ class NamedConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.red.default"); - Assertions.assertEquals(sourceData.sourceData(), COLOR_REALLY_RED); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.red.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(COLOR_REALLY_RED); } @@ -178,9 +178,9 @@ class NamedConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.red.red-with-profile.default.with-profile"); - Assertions.assertEquals(sourceData.sourceData().size(), 1); - Assertions.assertEquals(sourceData.sourceData().get("taste"), "mango"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.red.red-with-profile.default.with-profile"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(1); + Assertions.assertThat(sourceData.sourceData().get("taste")).isEqualTo("mango"); } @@ -220,10 +220,10 @@ class NamedConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.red.red-with-profile.default"); - Assertions.assertEquals(sourceData.sourceData().size(), 2); - Assertions.assertEquals(sourceData.sourceData().get("some.color"), "really-red"); - Assertions.assertEquals(sourceData.sourceData().get("some.taste"), "mango"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.red.red-with-profile.default"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2); + Assertions.assertThat(sourceData.sourceData().get("some.color")).isEqualTo("really-red"); + Assertions.assertThat(sourceData.sourceData().get("some.taste")).isEqualTo("mango"); } @@ -275,11 +275,11 @@ class NamedConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.red.red-with-shape.red-with-taste.default"); - Assertions.assertEquals(sourceData.sourceData().size(), 3); - Assertions.assertEquals(sourceData.sourceData().get("some.color"), "really-red"); - Assertions.assertEquals(sourceData.sourceData().get("some.taste"), "mango"); - Assertions.assertEquals(sourceData.sourceData().get("some.shape"), "round"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.red.red-with-shape.red-with-taste.default"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(3); + Assertions.assertThat(sourceData.sourceData().get("some.color")).isEqualTo("really-red"); + Assertions.assertThat(sourceData.sourceData().get("some.taste")).isEqualTo("mango"); + Assertions.assertThat(sourceData.sourceData().get("some.shape")).isEqualTo("round"); } @@ -309,8 +309,8 @@ class NamedConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.application.default"); - Assertions.assertEquals(sourceData.sourceData(), Collections.singletonMap("some.color", "red")); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.application.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Collections.singletonMap("some.color", "red")); } /** @@ -340,8 +340,8 @@ class NamedConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.red.default"); - Assertions.assertEquals(sourceData.sourceData(), COLOR_REALLY_RED); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.red.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(COLOR_REALLY_RED); } /** @@ -367,8 +367,8 @@ class NamedConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.red.default"); - Assertions.assertEquals(sourceData.sourceData(), Map.of("key", "value")); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.red.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Map.of("key", "value")); } /** @@ -399,8 +399,8 @@ class NamedConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedConfigMapContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "configmap.one.default"); - Assertions.assertEquals(sourceData.sourceData(), Map.of("key", "value")); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("configmap.one.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Map.of("key", "value")); } /** @@ -437,9 +437,9 @@ class NamedConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData redData = new NamedConfigMapContextToSourceDataProvider().get(); SourceData redSourceData = redData.apply(redContext); - Assertions.assertEquals(redSourceData.sourceName(), "configmap.red.default"); - Assertions.assertEquals(redSourceData.sourceData(), Map.of("color", "red")); - Assertions.assertTrue(output.getAll().contains("Loaded all config maps in namespace '" + NAMESPACE + "'")); + Assertions.assertThat(redSourceData.sourceName()).isEqualTo("configmap.red.default"); + Assertions.assertThat(redSourceData.sourceData()).isEqualTo(Map.of("color", "red")); + Assertions.assertThat(output.getOut()).contains("Loaded all config maps in namespace '" + NAMESPACE + "'"); NormalizedSource greenSource = new NamedConfigMapNormalizedSource("green", NAMESPACE, true, true); KubernetesClientConfigContext greenContext = new KubernetesClientConfigContext(api, greenSource, NAMESPACE, @@ -447,16 +447,16 @@ class NamedConfigMapContextToSourceDataProviderTests { KubernetesClientContextToSourceData greenData = new NamedConfigMapContextToSourceDataProvider().get(); SourceData greenSourceData = greenData.apply(greenContext); - Assertions.assertEquals(greenSourceData.sourceName(), "configmap.green.default"); - Assertions.assertEquals(greenSourceData.sourceData(), Map.of("color", "green")); + Assertions.assertThat(greenSourceData.sourceName()).isEqualTo("configmap.green.default"); + Assertions.assertThat(greenSourceData.sourceData()).isEqualTo(Map.of("color", "green")); // meaning there is a single entry with such a log statement String[] out = output.getAll().split("Loaded all config maps in namespace"); - Assertions.assertEquals(out.length, 2); + Assertions.assertThat(out.length).isEqualTo(2); // meaning that the second read was done from the cache out = output.getAll().split("Loaded \\(from cache\\) all config maps in namespace"); - Assertions.assertEquals(out.length, 2); + Assertions.assertThat(out.length).isEqualTo(2); } diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/NamedSecretContextToSourceDataProviderTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/NamedSecretContextToSourceDataProviderTests.java index e78b2426..3564729e 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/NamedSecretContextToSourceDataProviderTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/NamedSecretContextToSourceDataProviderTests.java @@ -31,8 +31,8 @@ import io.kubernetes.client.openapi.models.V1SecretBuilder; import io.kubernetes.client.openapi.models.V1SecretList; import io.kubernetes.client.openapi.models.V1SecretListBuilder; import io.kubernetes.client.util.ClientBuilder; +import org.assertj.core.api.Assertions; 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; @@ -99,8 +99,8 @@ class NamedSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.red.default"); - Assertions.assertEquals(sourceData.sourceData(), Map.of("color", "really-red")); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.red.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Map.of("color", "really-red")); } @@ -139,9 +139,9 @@ class NamedSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.red.default"); - Assertions.assertEquals(sourceData.sourceData().size(), 1); - Assertions.assertEquals(sourceData.sourceData().get("color"), "really-red"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.red.default"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(1); + Assertions.assertThat(sourceData.sourceData().get("color")).isEqualTo("really-red"); } @@ -168,8 +168,8 @@ class NamedSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.blue.default"); - Assertions.assertEquals(sourceData.sourceData(), Collections.emptyMap()); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.blue.default"); + Assertions.assertThat(sourceData.sourceData()).isEmpty(); } /** @@ -199,8 +199,8 @@ class NamedSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.red.default"); - Assertions.assertEquals(sourceData.sourceData(), Map.of("color", "really-red")); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.red.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Map.of("color", "really-red")); } /** @@ -235,9 +235,9 @@ class NamedSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.red.red-with-profile.default.with-profile"); - Assertions.assertEquals(sourceData.sourceData().size(), 1); - Assertions.assertEquals(sourceData.sourceData().get("taste"), "mango"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.red.red-with-profile.default.with-profile"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(1); + Assertions.assertThat(sourceData.sourceData().get("taste")).isEqualTo("mango"); } @@ -273,10 +273,10 @@ class NamedSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.red.red-with-taste.default"); - Assertions.assertEquals(sourceData.sourceData().size(), 2); - Assertions.assertEquals(sourceData.sourceData().get("some.color"), "really-red"); - Assertions.assertEquals(sourceData.sourceData().get("some.taste"), "mango"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.red.red-with-taste.default"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(2); + Assertions.assertThat(sourceData.sourceData().get("some.color")).isEqualTo("really-red"); + Assertions.assertThat(sourceData.sourceData().get("some.taste")).isEqualTo("mango"); } @@ -317,12 +317,12 @@ class NamedSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.red.red-with-shape.red-with-taste.default"); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.red.red-with-shape.red-with-taste.default"); - Assertions.assertEquals(sourceData.sourceData().size(), 3); - Assertions.assertEquals(sourceData.sourceData().get("some.color"), "really-red"); - Assertions.assertEquals(sourceData.sourceData().get("some.taste"), "mango"); - Assertions.assertEquals(sourceData.sourceData().get("some.shape"), "round"); + Assertions.assertThat(sourceData.sourceData().size()).isEqualTo(3); + Assertions.assertThat(sourceData.sourceData().get("some.color")).isEqualTo("really-red"); + Assertions.assertThat(sourceData.sourceData().get("some.taste")).isEqualTo("mango"); + Assertions.assertThat(sourceData.sourceData().get("some.shape")).isEqualTo("round"); } @@ -349,8 +349,8 @@ class NamedSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData data = new NamedSecretContextToSourceDataProvider().get(); SourceData sourceData = data.apply(context); - Assertions.assertEquals(sourceData.sourceName(), "secret.single-yaml.default"); - Assertions.assertEquals(sourceData.sourceData(), Map.of("key", "value")); + Assertions.assertThat(sourceData.sourceName()).isEqualTo("secret.single-yaml.default"); + Assertions.assertThat(sourceData.sourceData()).isEqualTo(Map.of("key", "value")); } /** @@ -387,9 +387,9 @@ class NamedSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData redData = new NamedSecretContextToSourceDataProvider().get(); SourceData redSourceData = redData.apply(redContext); - Assertions.assertEquals(redSourceData.sourceName(), "secret.red.default"); - Assertions.assertEquals(redSourceData.sourceData(), Map.of("color", "red")); - Assertions.assertTrue(output.getAll().contains("Loaded all secrets in namespace '" + NAMESPACE + "'")); + Assertions.assertThat(redSourceData.sourceName()).isEqualTo("secret.red.default"); + Assertions.assertThat(redSourceData.sourceData()).isEqualTo(Map.of("color", "red")); + Assertions.assertThat(output.getAll()).contains("Loaded all secrets in namespace '" + NAMESPACE + "'"); NormalizedSource greenSource = new NamedSecretNormalizedSource("green", NAMESPACE, true, true); KubernetesClientConfigContext greenContext = new KubernetesClientConfigContext(api, greenSource, NAMESPACE, @@ -397,16 +397,16 @@ class NamedSecretContextToSourceDataProviderTests { KubernetesClientContextToSourceData greenData = new NamedSecretContextToSourceDataProvider().get(); SourceData greenSourceData = greenData.apply(greenContext); - Assertions.assertEquals(greenSourceData.sourceName(), "secret.green.default"); - Assertions.assertEquals(greenSourceData.sourceData(), Map.of("color", "green")); + Assertions.assertThat(greenSourceData.sourceName()).isEqualTo("secret.green.default"); + Assertions.assertThat(greenSourceData.sourceData()).isEqualTo(Map.of("color", "green")); // meaning there is a single entry with such a log statement String[] out = output.getAll().split("Loaded all secrets in namespace"); - Assertions.assertEquals(out.length, 2); + Assertions.assertThat(out.length).isEqualTo(2); // meaning that the second read was done from the cache out = output.getAll().split("Loaded \\(from cache\\) all secrets in namespace"); - Assertions.assertEquals(out.length, 2); + Assertions.assertThat(out.length).isEqualTo(2); } diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/configmap_retry/ConfigFailFastDisabled.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/configmap_retry/ConfigFailFastDisabled.java index d47e9cae..0f41f18a 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/configmap_retry/ConfigFailFastDisabled.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/configmap_retry/ConfigFailFastDisabled.java @@ -21,9 +21,9 @@ import com.github.tomakehurst.wiremock.client.WireMock; import io.kubernetes.client.openapi.JSON; import io.kubernetes.client.openapi.models.V1ConfigMapList; 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.mockito.MockedStatic; @@ -91,7 +91,8 @@ abstract class ConfigFailFastDisabled { propertySourceLocator = spy(propertySourceLocator); stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error"))); - Assertions.assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment())); + Assertions.assertThatCode(() -> propertySourceLocator.locate(new MockEnvironment())) + .doesNotThrowAnyException(); // verify locate is called only once verify(propertySourceLocator, times(1)).locate(any()); diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/configmap_retry/ConfigRetryEnabled.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/configmap_retry/ConfigRetryEnabled.java index 0fb14bd0..87ee6bbf 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/configmap_retry/ConfigRetryEnabled.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/configmap_retry/ConfigRetryEnabled.java @@ -26,9 +26,9 @@ import io.kubernetes.client.openapi.models.V1ConfigMap; import io.kubernetes.client.openapi.models.V1ConfigMapList; import io.kubernetes.client.openapi.models.V1ObjectMeta; 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.mockito.MockedStatic; @@ -110,15 +110,16 @@ abstract class ConfigRetryEnabled { stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(configMapList)))); - PropertySource propertySource = Assertions - .assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment())); + PropertySource[] propertySource = new PropertySource[1]; + Assertions.assertThatCode(() -> propertySource[0] = propertySourceLocator.locate(new MockEnvironment())) + .doesNotThrowAnyException(); // verify locate is called only once WireMock.verify(1, getRequestedFor(urlEqualTo(API))); // validate the contents of the property source - assertThat(propertySource.getProperty("some.prop")).isEqualTo("theValue"); - assertThat(propertySource.getProperty("some.number")).isEqualTo("0"); + assertThat(propertySource[0].getProperty("some.prop")).isEqualTo("theValue"); + assertThat(propertySource[0].getProperty("some.number")).isEqualTo("0"); } @Test @@ -152,15 +153,17 @@ abstract class ConfigRetryEnabled { .whenScenarioStateIs("Failed thrice") .willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(configMapList)))); - PropertySource propertySource = Assertions - .assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment())); + PropertySource[] propertySource = new PropertySource[1]; + Assertions.assertThatCode(() -> propertySource[0] = propertySourceLocator.locate(new MockEnvironment())) + .doesNotThrowAnyException(); // verify the request was retried 4 times, 5 total request WireMock.verify(5, getRequestedFor(urlEqualTo(API))); // validate the contents of the property source - assertThat(propertySource.getProperty("some.prop")).isEqualTo("theValue"); - assertThat(propertySource.getProperty("some.number")).isEqualTo("0"); + assertThat(propertySource[0].getProperty("some.prop")).isEqualTo("theValue"); + assertThat(propertySource[0 + ].getProperty("some.number")).isEqualTo("0"); } @Test diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedSecretsChangeDetectorTests.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedSecretsChangeDetectorTests.java index b38e49f9..8244fb49 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedSecretsChangeDetectorTests.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedSecretsChangeDetectorTests.java @@ -37,9 +37,9 @@ import io.kubernetes.client.openapi.models.V1SecretList; import io.kubernetes.client.util.ClientBuilder; import io.kubernetes.client.util.Watch; import okhttp3.OkHttpClient; +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; @@ -186,7 +186,7 @@ class KubernetesClientEventBasedSecretsChangeDetectorTests { Map right = null; boolean result = KubernetesClientEventBasedSecretsChangeDetector.equals(left, right); - Assertions.assertTrue(result); + Assertions.assertThat(result).isTrue(); } /** @@ -200,7 +200,7 @@ class KubernetesClientEventBasedSecretsChangeDetectorTests { Map right = null; boolean result = KubernetesClientEventBasedSecretsChangeDetector.equals(left, right); - Assertions.assertTrue(result); + Assertions.assertThat(result).isTrue(); } /** @@ -214,7 +214,7 @@ class KubernetesClientEventBasedSecretsChangeDetectorTests { Map right = null; boolean result = KubernetesClientEventBasedSecretsChangeDetector.equals(left, right); - Assertions.assertTrue(result); + Assertions.assertThat(result).isTrue(); } /** @@ -228,7 +228,7 @@ class KubernetesClientEventBasedSecretsChangeDetectorTests { Map right = Map.of(); boolean result = KubernetesClientEventBasedSecretsChangeDetector.equals(left, right); - Assertions.assertTrue(result); + Assertions.assertThat(result).isTrue(); } /** @@ -242,7 +242,7 @@ class KubernetesClientEventBasedSecretsChangeDetectorTests { Map right = Map.of(); boolean result = KubernetesClientEventBasedSecretsChangeDetector.equals(left, right); - Assertions.assertTrue(result); + Assertions.assertThat(result).isTrue(); } /** @@ -256,7 +256,7 @@ class KubernetesClientEventBasedSecretsChangeDetectorTests { Map right = Map.of("1", "b".getBytes()); boolean result = KubernetesClientEventBasedSecretsChangeDetector.equals(left, right); - Assertions.assertFalse(result); + Assertions.assertThat(result).isFalse(); } /** @@ -270,7 +270,7 @@ class KubernetesClientEventBasedSecretsChangeDetectorTests { Map right = Map.of("1", "b".getBytes()); boolean result = KubernetesClientEventBasedSecretsChangeDetector.equals(left, right); - Assertions.assertFalse(result); + Assertions.assertThat(result).isFalse(); } /** @@ -284,7 +284,7 @@ class KubernetesClientEventBasedSecretsChangeDetectorTests { Map right = Map.of("1", "b".getBytes(), "2", "aa".getBytes()); boolean result = KubernetesClientEventBasedSecretsChangeDetector.equals(left, right); - Assertions.assertFalse(result); + Assertions.assertThat(result).isFalse(); } } diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsFailFastDisabled.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsFailFastDisabledTests.java similarity index 95% rename from spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsFailFastDisabled.java rename to spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsFailFastDisabledTests.java index 39327360..b0d91ff1 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsFailFastDisabled.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsFailFastDisabledTests.java @@ -21,9 +21,9 @@ import com.github.tomakehurst.wiremock.client.WireMock; import io.kubernetes.client.openapi.JSON; import io.kubernetes.client.openapi.models.V1SecretList; 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.mockito.MockedStatic; @@ -52,7 +52,7 @@ import static org.mockito.Mockito.verify; "spring.cloud.kubernetes.secrets.name=my-secret", "spring.cloud.kubernetes.secrets.enable-api=true", "spring.main.cloud-platform=KUBERNETES", "spring.config.import=kubernetes:" }, classes = SecretsRetryApplication.class) -class SecretsFailFastDisabled { +class SecretsFailFastDisabledTests { private static final String API = "/api/v1/namespaces/default/secrets"; @@ -97,7 +97,8 @@ class SecretsFailFastDisabled { KubernetesClientSecretsPropertySourceLocator propertySourceLocator = spy(psl); stubFor(get(API).willReturn(aResponse().withStatus(500).withBody("Internal Server Error"))); - Assertions.assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment())); + Assertions.assertThatCode(() -> propertySourceLocator.locate(new MockEnvironment())) + .doesNotThrowAnyException(); // verify locate is called only once verify(propertySourceLocator, times(1)).locate(any()); diff --git a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsRetryEnabled.java b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsRetryEnabledTests.java similarity index 88% rename from spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsRetryEnabled.java rename to spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsRetryEnabledTests.java index 160741c5..4edae0b4 100644 --- a/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsRetryEnabled.java +++ b/spring-cloud-kubernetes-client-config/src/test/java/org/springframework/cloud/kubernetes/client/config/secrets_retry/SecretsRetryEnabledTests.java @@ -26,8 +26,9 @@ import io.kubernetes.client.openapi.models.V1ObjectMeta; import io.kubernetes.client.openapi.models.V1Secret; import io.kubernetes.client.openapi.models.V1SecretList; import io.kubernetes.client.util.ClientBuilder; +import org.assertj.core.api.Assertions; +import org.assertj.core.api.Assumptions; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -62,7 +63,7 @@ import static org.mockito.Mockito.spy; "spring.cloud.kubernetes.secrets.name=my-secret", "spring.cloud.kubernetes.secrets.enable-api=true", "spring.main.cloud-platform=KUBERNETES", "spring.config.import=kubernetes:" }, classes = SecretsRetryApplication.class) -class SecretsRetryEnabled { +class SecretsRetryEnabledTests { private static final String API = "/api/v1/namespaces/default/secrets"; @@ -117,15 +118,16 @@ class SecretsRetryEnabled { stubFor(get(API).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(secretList)))); - PropertySource propertySource = Assertions - .assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment())); + final PropertySource[] propertySource = new PropertySource[1]; + Assertions.assertThatCode(() -> propertySource[0] = propertySourceLocator.locate(new MockEnvironment())) + .doesNotThrowAnyException(); // verify locate is called only once WireMock.verify(1, getRequestedFor(urlEqualTo(API))); // validate the contents of the property source - assertThat(propertySource.getProperty("some.sensitive.prop")).isEqualTo("theSensitiveValue"); - assertThat(propertySource.getProperty("some.sensitive.number")).isEqualTo("1"); + assertThat(propertySource[0].getProperty("some.sensitive.prop")).isEqualTo("theSensitiveValue"); + assertThat(propertySource[0].getProperty("some.sensitive.number")).isEqualTo("1"); } @Test @@ -159,15 +161,16 @@ class SecretsRetryEnabled { .whenScenarioStateIs("Failed thrice") .willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(secretList)))); - PropertySource propertySource = Assertions - .assertDoesNotThrow(() -> propertySourceLocator.locate(new MockEnvironment())); + final PropertySource[] propertySource = new PropertySource[1]; + Assertions.assertThatNoException() + .isThrownBy(() -> propertySource[0] = propertySourceLocator.locate(new MockEnvironment())); // verify retried 4 times WireMock.verify(4, getRequestedFor(urlEqualTo(API))); // validate the contents of the property source - assertThat(propertySource.getProperty("some.sensitive.prop")).isEqualTo("theSensitiveValue"); - assertThat(propertySource.getProperty("some.sensitive.number")).isEqualTo("1"); + assertThat(propertySource[0].getProperty("some.sensitive.prop")).isEqualTo("theSensitiveValue"); + assertThat(propertySource[0].getProperty("some.sensitive.number")).isEqualTo("1"); } @Test