From d000d3ffdc1a18047df64f772391d8829f5b3cda Mon Sep 17 00:00:00 2001 From: Jessica Lane <48732966+jesslane94@users.noreply.github.com> Date: Wed, 24 Jul 2024 03:45:45 -0700 Subject: [PATCH] fix: replaced '.length() > 0' with '!.isEmpty()' in MappingConfig Signed-off-by: Jessica Lane --- .../kit/config/resource/MappingConfig.java | 2 +- .../config/resource/MappingConfigTest.java | 28 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/jkube-kit/config/resource/src/main/java/org/eclipse/jkube/kit/config/resource/MappingConfig.java b/jkube-kit/config/resource/src/main/java/org/eclipse/jkube/kit/config/resource/MappingConfig.java index 26dcac87b4..1198cd1589 100644 --- a/jkube-kit/config/resource/src/main/java/org/eclipse/jkube/kit/config/resource/MappingConfig.java +++ b/jkube-kit/config/resource/src/main/java/org/eclipse/jkube/kit/config/resource/MappingConfig.java @@ -38,6 +38,6 @@ public String[] getFilenamesAsArray() { } public boolean isValid() { - return kind != null && filenameTypes != null && filenameTypes.length() > 0; + return kind != null && filenameTypes != null && !filenameTypes.isEmpty(); } } diff --git a/jkube-kit/config/resource/src/test/java/org/eclipse/jkube/kit/config/resource/MappingConfigTest.java b/jkube-kit/config/resource/src/test/java/org/eclipse/jkube/kit/config/resource/MappingConfigTest.java index 640835e0fb..37d7b1a0d4 100644 --- a/jkube-kit/config/resource/src/test/java/org/eclipse/jkube/kit/config/resource/MappingConfigTest.java +++ b/jkube-kit/config/resource/src/test/java/org/eclipse/jkube/kit/config/resource/MappingConfigTest.java @@ -58,9 +58,9 @@ void getFilenamesAsArray_whenTypesPresent_thenReturnsArray() { void isValid_withMissingKind_shouldReturnFalse() { // Given MappingConfig config = MappingConfig.builder() - .apiVersion("custom-cron-tab.example.com/v1") - .filenameTypes("crontab,cr") - .build(); + .apiVersion("custom-cron-tab.example.com/v1") + .filenameTypes("crontab,cr") + .build(); // When boolean result = config.isValid(); // Then @@ -71,9 +71,23 @@ void isValid_withMissingKind_shouldReturnFalse() { void isValid_withMissingFileNameTypes_shouldReturnFalse() { // Given MappingConfig config = MappingConfig.builder() - .apiVersion("custom-cron-tab.example.com/v1") - .kind("Foo") - .build(); + .apiVersion("custom-cron-tab.example.com/v1") + .kind("Foo") + .build(); + // When + boolean result = config.isValid(); + // Then + assertThat(result).isFalse(); + } + + @Test + void isValid_withEmptyFileNameTypes_shouldReturnFalse() { + // Given + MappingConfig config = MappingConfig.builder() + .apiVersion("custom-cron-tab.example.com/v1") + .kind("Foo") + .filenameTypes("") + .build(); // When boolean result = config.isValid(); // Then @@ -110,7 +124,7 @@ void isValid_withKindAndApiVersionAndFileName_shouldReturnTrue() { @Test void equalsAndHashCodeShouldMatch() { // Given - MappingConfig mc1 = MappingConfig.builder().kind("Foo").filenameTypes("foos").build(); + MappingConfig mc1 = MappingConfig.builder().kind("Foo").filenameTypes("foos").build(); MappingConfig mc2 = MappingConfig.builder().kind("Foo").filenameTypes("foos").build(); // When + Then assertThat(mc1)