From be3ed0878d8df2760cd007a67b1edea678d0bcc5 Mon Sep 17 00:00:00 2001 From: erabii Date: Mon, 10 Jun 2024 15:30:17 +0300 Subject: [PATCH] Fix 1661 (#1662) --- .../commons/leader/LeaderProperties.java | 2 +- .../commons/leader/LeaderPropertiesTests.java | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/leader/LeaderPropertiesTests.java diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeaderProperties.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeaderProperties.java index fe54bc108..7f1957f13 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeaderProperties.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeaderProperties.java @@ -106,7 +106,7 @@ public void setNamespace(String namespace) { } public String getNamespace(String defaultValue) { - if (!StringUtils.hasText(defaultValue)) { + if (!StringUtils.hasText(namespace)) { return defaultValue; } diff --git a/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/leader/LeaderPropertiesTests.java b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/leader/LeaderPropertiesTests.java new file mode 100644 index 000000000..087c00996 --- /dev/null +++ b/spring-cloud-kubernetes-commons/src/test/java/org/springframework/cloud/kubernetes/commons/leader/LeaderPropertiesTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.kubernetes.commons.leader; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * @author wind57 + */ +class LeaderPropertiesTests { + + @Test + void getNamespaceNull() { + LeaderProperties leaderProperties = new LeaderProperties(); + String namespace = leaderProperties.getNamespace("a"); + Assertions.assertEquals("a", namespace); + } + + @Test + void getNamespaceEmpty() { + LeaderProperties leaderProperties = new LeaderProperties(); + leaderProperties.setNamespace(""); + String namespace = leaderProperties.getNamespace("a"); + Assertions.assertEquals("a", namespace); + } + + @Test + void getNamespacePresent() { + LeaderProperties leaderProperties = new LeaderProperties(); + leaderProperties.setNamespace("c"); + String namespace = leaderProperties.getNamespace("a"); + Assertions.assertEquals("c", namespace); + } + +}