This is an automated email from the ASF dual-hosted git repository.
zhangyonglun 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 2737b51 Refactor BootstrapArguments (#7287)
2737b51 is described below
commit 2737b51f357068e8ccced30e7228dda9413c00eb
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Sep 7 13:51:38 2020 +0800
Refactor BootstrapArguments (#7287)
* Remove useless fixture
* Refactor BootstrapArguments
* Refactor BootstrapArgumentsTest
---
.../proxy/arg/BootstrapArguments.java | 10 +++-
.../proxy/arg/BootstrapArgumentsTest.java | 56 ++++++++++++++--------
.../shardingsphere/proxy/fixture/FixtureRule.java | 21 --------
3 files changed, 43 insertions(+), 44 deletions(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arg/BootstrapArguments.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arg/BootstrapArguments.java
index 7a97c81..4c704bc 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arg/BootstrapArguments.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/arg/BootstrapArguments.java
@@ -54,7 +54,13 @@ public final class BootstrapArguments {
}
private String paddingWithSlash(final String arg) {
- String path = arg.endsWith("/") ? arg : (arg + "/");
- return path.startsWith("/") ? path : ("/" + path);
+ StringBuilder result = new StringBuilder(arg);
+ if (!arg.startsWith("/")) {
+ result.insert(0, '/');
+ }
+ if (!arg.endsWith("/")) {
+ result.append('/');
+ }
+ return result.toString();
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/arg/BootstrapArgumentsTest.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/arg/BootstrapArgumentsTest.java
index 3fe0799..8c1b138 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/arg/BootstrapArgumentsTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/arg/BootstrapArgumentsTest.java
@@ -25,42 +25,56 @@ import static org.junit.Assert.assertThat;
public final class BootstrapArgumentsTest {
@Test
- public void assertEmptyArgs() {
+ public void assertNewWithEmptyArgument() {
BootstrapArguments actual = new BootstrapArguments(new String[]{});
assertThat(actual.getPort(), is(3307));
assertThat(actual.getConfigurationPath(), is("/conf/"));
}
- @Test
- public void assertWrongParam() {
- String param = "WrongParam";
+ @SuppressWarnings("ResultOfObjectAllocationIgnored")
+ @Test(expected = IllegalArgumentException.class)
+ public void assertNewWithWrongArgument() {
+ String wrongArgument = "WrongArgument";
try {
- new BootstrapArguments(new String[]{param});
- } catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), is(String.format("Invalid port `%s`.",
param)));
+ new BootstrapArguments(new String[]{wrongArgument});
+ } catch (final IllegalArgumentException ex) {
+ assertThat(ex.getMessage(), is(String.format("Invalid port `%s`.",
wrongArgument)));
+ throw ex;
}
}
@Test
- public void assertOneArgs() {
+ public void assertNewWithOneArgumentOnly() {
BootstrapArguments actual = new BootstrapArguments(new
String[]{"3306"});
assertThat(actual.getPort(), is(3306));
assertThat(actual.getConfigurationPath(), is("/conf/"));
}
@Test
- public void assertTwoArgs() {
- BootstrapArguments actual = new BootstrapArguments(new
String[]{"3305", "test"});
- assertThat(actual.getPort(), is(3305));
- assertThat(actual.getConfigurationPath(), is("/test/"));
- actual = new BootstrapArguments(new String[]{"3304", "/test1"});
- assertThat(actual.getPort(), is(3304));
- assertThat(actual.getConfigurationPath(), is("/test1/"));
- actual = new BootstrapArguments(new String[]{"3303", "test2/"});
- assertThat(actual.getPort(), is(3303));
- assertThat(actual.getConfigurationPath(), is("/test2/"));
- actual = new BootstrapArguments(new String[]{"3302", "/test3/"});
- assertThat(actual.getPort(), is(3302));
- assertThat(actual.getConfigurationPath(), is("/test3/"));
+ public void assertNewWithTwoArgumentsAndConfigurationPathWithoutSlash() {
+ BootstrapArguments actual = new BootstrapArguments(new
String[]{"3306", "test_conf"});
+ assertThat(actual.getPort(), is(3306));
+ assertThat(actual.getConfigurationPath(), is("/test_conf/"));
+ }
+
+ @Test
+ public void assertNewWithTwoArgumentsAndConfigurationPathWithLeftSlash() {
+ BootstrapArguments actual = new BootstrapArguments(new
String[]{"3306", "/test_conf"});
+ assertThat(actual.getPort(), is(3306));
+ assertThat(actual.getConfigurationPath(), is("/test_conf/"));
+ }
+
+ @Test
+ public void assertNewWithTwoArgumentsAndConfigurationPathWithRightSlash() {
+ BootstrapArguments actual = new BootstrapArguments(new
String[]{"3306", "test_conf/"});
+ assertThat(actual.getPort(), is(3306));
+ assertThat(actual.getConfigurationPath(), is("/test_conf/"));
+ }
+
+ @Test
+ public void assertNewWithTwoArgumentsAndConfigurationPathWithBothSlash() {
+ BootstrapArguments actual = new BootstrapArguments(new
String[]{"3306", "/test_conf/"});
+ assertThat(actual.getPort(), is(3306));
+ assertThat(actual.getConfigurationPath(), is("/test_conf/"));
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/FixtureRule.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/FixtureRule.java
deleted file mode 100644
index 8c79bb7..0000000
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/FixtureRule.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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
- *
- * http://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.apache.shardingsphere.proxy.fixture;
-
-public final class FixtureRule {
-}