Skip to content

Commit

Permalink
Add NPE tests to KubernetesVersionPriorityTest
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo42 committed Mar 10, 2024
1 parent 1d9bea3 commit 914e7ec
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatException;

class KubernetesVersionPriorityTest {

@Test
void should_version_with_highest_priority() {
void highestPriority_should_version_with_highest_priority() {
// given
String highest = "v10";
List<String> versions = Arrays.asList(
Expand All @@ -48,7 +50,13 @@ void should_version_with_highest_priority() {
}

@Test
void should_sort_with_highest_priority() {
void highestPriority_should_null() {
assertThat(KubernetesVersionPriority.highestPriority(null)).isNull();
assertThat(KubernetesVersionPriority.highestPriority(Collections.emptyList())).isNull();
}

@Test
void sortByPriority_should_sort_with_highest_priority() {
// given
CustomResourceDefinitionVersion foo10 = createCustomResourceDefinitionVersion("foo10");
CustomResourceDefinitionVersion v11alpha2 = createCustomResourceDefinitionVersion("v11alpha2");
Expand Down Expand Up @@ -93,6 +101,21 @@ void should_sort_with_highest_priority() {
assertThat(computed.get(0)).isSameAs(v10);
}

@Test
void sortByPriority_should_accept_null_or_empty() {
assertThat(KubernetesVersionPriority.sortByPriority(null, CustomResourceDefinitionVersion::getName)).isEmpty();
assertThat(KubernetesVersionPriority.sortByPriority(Collections.emptyList(), CustomResourceDefinitionVersion::getName))
.isEmpty();
}

@Test
void sortByPriority_no_versionProvider_should_throw_exception() {
final CustomResourceDefinitionVersion v1 = createCustomResourceDefinitionVersion("v1");
assertThatException().isThrownBy(() -> KubernetesVersionPriority.sortByPriority(Collections.singletonList(v1), null));
assertThatException().isThrownBy(() -> KubernetesVersionPriority.sortByPriority(null, null));
assertThatException().isThrownBy(() -> KubernetesVersionPriority.sortByPriority(Collections.emptyList(), null));
}

private static CustomResourceDefinitionVersion createCustomResourceDefinitionVersion(String name) {
return new CustomResourceDefinitionVersionBuilder()
.withName(name)
Expand Down

0 comments on commit 914e7ec

Please sign in to comment.