This is an automated email from the ASF dual-hosted git repository.
zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 3c3a55fc389 Revise URLArgumentLineTest (#30286)
3c3a55fc389 is described below
commit 3c3a55fc389985d372f35a53540892b6f631363b
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Feb 25 23:29:50 2024 +0800
Revise URLArgumentLineTest (#30286)
---
.../infra/url/core/arg/URLArgumentLine.java | 10 ----
.../infra/url/core/arg/URLArgumentLineTest.java | 67 ++++++----------------
2 files changed, 19 insertions(+), 58 deletions(-)
diff --git
a/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/core/arg/URLArgumentLine.java
b/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/core/arg/URLArgumentLine.java
index 7ec5fa53cdd..c884d4bccf7 100644
---
a/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/core/arg/URLArgumentLine.java
+++
b/infra/url/core/src/main/java/org/apache/shardingsphere/infra/url/core/arg/URLArgumentLine.java
@@ -56,16 +56,6 @@ public final class URLArgumentLine {
return Optional.of(new URLArgumentLine(parsedArg[0], parsedArg[1],
matcher));
}
- /**
- * Set system property.
- *
- * @param key property key
- * @param value property value
- */
- public static void setSystemProperty(final String key, final String value)
{
- System.setProperty(key, value);
- }
-
/**
* Replace argument.
*
diff --git
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/arg/URLArgumentLineTest.java
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/arg/URLArgumentLineTest.java
index f2202cfa7cf..acd0505683c 100644
---
a/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/arg/URLArgumentLineTest.java
+++
b/infra/url/core/src/test/java/org/apache/shardingsphere/infra/url/core/arg/URLArgumentLineTest.java
@@ -18,71 +18,42 @@
package org.apache.shardingsphere.infra.url.core.arg;
import org.junit.jupiter.api.Test;
-import java.lang.reflect.Field;
+
import java.util.Optional;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-public class URLArgumentLineTest {
-
- private static final Pattern PLACEHOLDER_PATTERN =
Pattern.compile("\\$\\$\\{(.+::.*)}$");
-
- private static final String NAME = "fixture.config.driver.jdbc-url";
+class URLArgumentLineTest {
- private static final String DEFAULT_VALUE = "jdbc-url";
+ private final String line = "key=$${value::default_value}";
@Test
- void assertParse() throws NoSuchFieldException, IllegalAccessException {
- String line = String.format("%s=$${%s::%s}", NAME, NAME,
DEFAULT_VALUE);
- Matcher matcher = PLACEHOLDER_PATTERN.matcher(line);
- matcher.find();
-
- URLArgumentLine actual = URLArgumentLine.parse(line).get();
-
- assertThat(getURLArgumentLineField("argName").get(actual), is(NAME));
- assertThat(getURLArgumentLineField("argDefaultValue").get(actual),
is(DEFAULT_VALUE));
-
assertThat(getURLArgumentLineField("placehodlerMatcher").get(actual).toString(),
is(matcher.toString()));
+ void assertParseWithInvalidPattern() {
+ assertFalse(URLArgumentLine.parse("invalid").isPresent());
}
@Test
- void assertParseInvalidPattern() {
- final String line = "invalid-value";
- Optional<URLArgumentLine> actual = URLArgumentLine.parse(line);
-
- assertThat(actual, is(Optional.empty()));
+ void assertReplaceArgumentWithNone() {
+ Optional<URLArgumentLine> argLine = URLArgumentLine.parse(line);
+ assertTrue(argLine.isPresent());
+
assertThat(argLine.get().replaceArgument(URLArgumentPlaceholderType.NONE),
is("key=default_value"));
}
@Test
void assertReplaceArgumentWithEnvironment() {
- String line = String.format("%s=$${%s::%s}", NAME, NAME,
DEFAULT_VALUE);
- String actual =
URLArgumentLine.parse(line).get().replaceArgument(URLArgumentPlaceholderType.ENVIRONMENT);
-
- assertThat(actual, is(String.format("%s=%s", NAME, DEFAULT_VALUE)));
- }
-
- @Test
- void assertReplaceArgumentWithProperty() {
- String line = String.format("%s=$${%s::%s}", NAME, NAME,
DEFAULT_VALUE);
- URLArgumentLine.setSystemProperty(NAME, DEFAULT_VALUE);
- String actual =
URLArgumentLine.parse(line).get().replaceArgument(URLArgumentPlaceholderType.SYSTEM_PROPS);
-
- assertThat(actual, is(String.format("%s=%s", NAME, DEFAULT_VALUE)));
+ Optional<URLArgumentLine> argLine = URLArgumentLine.parse(line);
+ assertTrue(argLine.isPresent());
+
assertThat(argLine.get().replaceArgument(URLArgumentPlaceholderType.ENVIRONMENT),
is("key=default_value"));
}
@Test
- void assertReplaceArgumentWithNone() {
- String line = String.format("%s=$${%s::}", NAME, NAME);
- String actual =
URLArgumentLine.parse(line).get().replaceArgument(URLArgumentPlaceholderType.NONE);
-
- assertThat(actual, is(NAME));
- }
-
- private Field getURLArgumentLineField(final String name) throws
NoSuchFieldException {
- Field field = URLArgumentLine.class.getDeclaredField(name);
- field.setAccessible(true);
- return field;
+ void assertReplaceArgumentWithSystemProperty() {
+ System.setProperty("value", "props_value");
+ Optional<URLArgumentLine> argLine = URLArgumentLine.parse(line);
+ assertTrue(argLine.isPresent());
+
assertThat(argLine.get().replaceArgument(URLArgumentPlaceholderType.SYSTEM_PROPS),
is("key=props_value"));
}
}