Skip to content

Commit

Permalink
Add tests for null inputs for Cache.metaNamespaceKeyFunc and ReflectU…
Browse files Browse the repository at this point in the history
…tils.objectMetadata
  • Loading branch information
rohanKanojia authored and manusa committed Apr 27, 2021
1 parent 58bc5df commit bba93b2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

}

0 comments on commit bba93b2

Please sign in to comment.