Skip to content

Commit

Permalink
ZOOKEEPER-725: Add unit tests for ConfigUtils.getClientConfigStr
Browse files Browse the repository at this point in the history
Reviewers: maoling
Author: Fabrice-TIERCELIN
Closes apache#2056 from Fabrice-TIERCELIN/unit-tests
  • Loading branch information
Fabrice-TIERCELIN authored and AlphaCanisMajoris committed Mar 28, 2024
1 parent 7ccd5d8 commit 8792768
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
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 {

Expand Down Expand Up @@ -112,6 +114,36 @@ public void testGetPropertyBackwardCompatibleWay() throws ConfigException {
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);
Expand Down

0 comments on commit 8792768

Please sign in to comment.