diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java index 9f7cc346ff8..98d8710b0fd 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/ConfigTest.java @@ -1238,7 +1238,7 @@ void refresh_whenOAuthTokenSourceSetToUser_thenConfigUnchanged() { } @Test - void build_given_emptyKubeConfig_then_shouldNotProduceNPE() throws URISyntaxException { + void builder_given_emptyKubeConfig_then_shouldNotProduceNPE() throws URISyntaxException { try { // Given System.setProperty("kubeconfig", diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/KubeConfigUtilsTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/KubeConfigUtilsTest.java index ba70b544479..2748e63fc02 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/KubeConfigUtilsTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/internal/KubeConfigUtilsTest.java @@ -23,15 +23,21 @@ import io.fabric8.kubernetes.api.model.NamedAuthInfo; import io.fabric8.kubernetes.api.model.NamedContext; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.Objects; +import java.util.function.Consumer; +import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Named.named; class KubeConfigUtilsTest { @Test @@ -137,37 +143,36 @@ void getAuthInfo_when_authInfoDoesntExist_returnsNull() { assertThat(found).isNull(); } - @Test - void hasAuthInfoNamed_when_authInfoExists_returnsTrue() { + @ParameterizedTest + @MethodSource("hasAuthInfoNamed_arguments") + void hasAuthInfoNamed(Config config, String authInfoName, Consumer consumer) { // given - Config config = getTestKubeConfig(); // when - boolean hasIt = KubeConfigUtils.hasAuthInfoNamed(config, "test/api-test-com:443"); + boolean hasIt = KubeConfigUtils.hasAuthInfoNamed(config, authInfoName); // then - assertThat(hasIt).isTrue(); + consumer.accept(hasIt); } - @Test - void hasAuthInfoNamed_when_authInfoDoesntExist_returnsFalse() { - // given - Config config = getTestKubeConfig(); - // when - boolean hasIt = KubeConfigUtils.hasAuthInfoNamed(config, "bogus"); - // then - assertThat(hasIt).isFalse(); - } - - @Test - void hasAuthInfoNamed_when_hasNoAuthInfo_returnsFalse() { - // given - Config config = new ConfigBuilder().build(); - // when - boolean hasIt = KubeConfigUtils.hasAuthInfoNamed(config, "test/api-test-com:443"); - // then - assertThat(hasIt).isFalse(); + static Stream hasAuthInfoNamed_arguments() { + return Stream.of( + // given config with authInfo, when getAuthInfoName with existing name, then should return true + Arguments.of( + named("config with authInfo", getTestKubeConfig()), + named("existing name", "test/api-test-com:443"), + named("should return true", (Consumer) (hasIt -> assertThat(hasIt).isTrue()))), + // given config with authInfo, when getAuthInfoName with missing name, then should return false + Arguments.of( + named("config with authInfo", getTestKubeConfig()), + named("missing authInfo name", "bogus"), + named("should return false", (Consumer) (hasIt -> assertThat(hasIt).isFalse()))), + // given config without authInfo, when getAuthInfoName with missing name, then should return false + Arguments.of( + named("config without authInfo", new ConfigBuilder().build()), + named("missing authInfo name", "test/api-test-com:443"), + named("should return false", (Consumer) (hasIt -> assertThat(hasIt).isFalse())))); } - private Config getTestKubeConfig() { + private static Config getTestKubeConfig() { return new ConfigBuilder() .withCurrentContext("test-context") .addNewCluster()