This is an automated email from the ASF dual-hosted git repository.

maoling pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 89a26b0a6 ZOOKEEPER-725: Add unit tests for 
ConfigUtils.getClientConfigStr
89a26b0a6 is described below

commit 89a26b0a6b8852b1e6e968e98ca18eb4b1f11560
Author: Fabrice TIERCELIN <[email protected]>
AuthorDate: Mon Feb 5 09:38:10 2024 +0100

    ZOOKEEPER-725: Add unit tests for ConfigUtils.getClientConfigStr
    
    Reviewers: maoling
    Author: Fabrice-TIERCELIN
    Closes #2056 from Fabrice-TIERCELIN/unit-tests
---
 .../zookeeper/server/util/ConfigUtilsTest.java     | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git 
a/zookeeper-server/src/test/java/org/apache/zookeeper/server/util/ConfigUtilsTest.java
 
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/util/ConfigUtilsTest.java
index e70c45ce4..937d812fe 100644
--- 
a/zookeeper-server/src/test/java/org/apache/zookeeper/server/util/ConfigUtilsTest.java
+++ 
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/util/ConfigUtilsTest.java
@@ -23,6 +23,8 @@ import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 public class ConfigUtilsTest {
 
@@ -112,6 +114,36 @@ public class ConfigUtilsTest {
         clearProp(newProp, oldProp);
     }
 
+    /**
+     * Tests the ConfigUtils.getClientConfigStr(String) method with version.
+     */
+    @ParameterizedTest
+    @ValueSource(strings = {
+            "version=1.2.3\n",
+            "version = 1.2.3\n",
+            "version=1.2.3\nfoo=bar\n",
+            "foo=bar\nversion=1.2.3\n"
+    })
+    public void testGetClientConfigStrWithVersion(String configData) {
+        String result = ConfigUtils.getClientConfigStr(configData);
+        assertEquals("1.2.3 ", result);
+    }
+
+    /**
+     * Tests the ConfigUtils.getClientConfigStr(String) method without version.
+     */
+    @ParameterizedTest
+    @ValueSource(strings = {
+            "versions=1.2.3\n",
+            "versions = 1.2.3\n",
+            "foo=bar\n",
+            "version=\n"
+    })
+    public void testGetClientConfigStrWithoutVersion(String configData) {
+        String result = ConfigUtils.getClientConfigStr(configData);
+        assertEquals(" ", result);
+    }
+
     private void clearProp(String newProp, String oldProp) {
         System.clearProperty(newProp);
         System.clearProperty(oldProp);

Reply via email to