diff --git a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/informers/cache/CacheTest.java b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/informers/cache/CacheTest.java index 7536901c668..2ab6e8d9f73 100644 --- a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/informers/cache/CacheTest.java +++ b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/informers/cache/CacheTest.java @@ -87,6 +87,7 @@ void testDefaultNamespaceKey() { Pod testPodObj = new PodBuilder().withNewMetadata().withName("test-pod4").withNamespace("default").endMetadata().build(); cache.add(testPodObj); + assertEquals("", Cache.metaNamespaceKeyFunc(null)); assertEquals("default/test-pod4", Cache.metaNamespaceKeyFunc(testPodObj)); assertEquals("default/test-pod4", Cache.namespaceKeyFunc("default", "test-pod4")); } diff --git a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/utils/ReflectUtilsTest.java b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/utils/ReflectUtilsTest.java index e35cffc255b..0640b006517 100644 --- a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/utils/ReflectUtilsTest.java +++ b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/utils/ReflectUtilsTest.java @@ -15,8 +15,10 @@ */ package io.fabric8.kubernetes.client.utils; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertSame; +import io.fabric8.kubernetes.api.model.ConfigMapBuilder; import org.junit.jupiter.api.Test; import io.fabric8.kubernetes.api.model.HasMetadata; @@ -93,4 +95,40 @@ public void testInstanceOf() throws ReflectiveOperationException { assertSame(meta, ReflectUtils.objectMetadata(baz)); } + @Test + void testObjectMetadataReturnsNullOnNull() throws ReflectiveOperationException { + // Given + Object input = null; + + // When + ObjectMeta result = ReflectUtils.objectMetadata(input); + + // Then + assertThat(result).isNull(); + } + + @Test + void testNamespaceReturnsValidNamespace() throws ReflectiveOperationException { + // Given + Object input = new ConfigMapBuilder().withNewMetadata().withNamespace("ns1").endMetadata().build(); + + // When + String result = ReflectUtils.namespace(input); + + // Then + assertThat(result).isNotNull().isEqualTo("ns1"); + } + + @Test + void testNamespaceReturnsBlankNamespace() throws ReflectiveOperationException { + // Given + Object input = null; + + // When + String result = ReflectUtils.namespace(input); + + // Then + assertThat(result).isNotNull().isBlank(); + } + }