Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test2 #14

Merged
merged 56 commits into from
Dec 6, 2018
Merged
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
8cafcab
combine test coverage report (#2643)
htynkn Oct 15, 2018
1ef1220
Optimize ut for serialization model. (#2632)
carryxyh Oct 15, 2018
393ffce
prototype for issue2570 (#2640)
beiwei30 Oct 16, 2018
d8282fe
[Dubbo -fix annotation bug] Fix @Reference bug (#2649)
zonghaishang Oct 17, 2018
b723837
Merge pull request #2656, make sure serialization exception sends bac…
beiwei30 Oct 19, 2018
c805c1d
#1903: supplemental change (#2666)
beiwei30 Oct 21, 2018
5e60bef
Optimize the doSelect method of RandomLoadBalance to reduce the times…
tswstarplanet Oct 21, 2018
dd950ac
解决与quartz集成报错问题 (#2677)
liunancun Oct 23, 2018
6938d48
Code format (#2662)
x-ultimate Oct 23, 2018
f2b6f07
Merge pull request#2679, consumer throws RpcException when RegistryDi…
beiwei30 Oct 24, 2018
7286e23
remove ServiceClassHolder and use the ApplicationModel replacedly (#2…
Jeff-Lv Oct 24, 2018
ac013b1
[Dubbo-1983] Support Protobuf Serialization (#2618)
kun-song Oct 26, 2018
910b261
Smooth Round Robin selection (#2650)
jasonjoo2010 Oct 26, 2018
b8bc80b
enhance pull request 2618 (#2691)
beiwei30 Oct 26, 2018
46f95bf
fix typo error in FAQ (#2684)
xuchuanyin Oct 26, 2018
a777aec
remove author info for RoundRobinLoadBalance (#2697)
jasonjoo2010 Oct 29, 2018
dba175a
fix pom for protostuff serialization (#2700)
beiwei30 Oct 29, 2018
99a00ba
Optimize REGISTRIES field in AbstractRegistryFactory. (#2703)
jingui123 Oct 30, 2018
36a1155
[version 2.7.0]remove the StaticContext class and refactor the code r…
Jeff-Lv Oct 30, 2018
e94d74b
Optimize heartbeat and reconnect task. (#2658)
carryxyh Oct 30, 2018
195c82d
polish the code for pull request 2658: Optimize heartbeat and reconne…
beiwei30 Oct 30, 2018
4d0a36c
重构 ServiceBean 的 isDelay 方法,使其更符合语义 (#2686)
code4wt Oct 30, 2018
0a116aa
【Unit Test】FailbackRegistry Test: recover method (#2591)
tswstarplanet Oct 30, 2018
c21cc05
replace ServiceAnnotationBeanPostProcessor log.isInfoEnabled->log.isW…
Oct 31, 2018
3cf801b
[Dubbo-2678][For Master] Add ability to turn off SPI auto injection, …
chickenlj Nov 1, 2018
0d51bc4
Merge pull request #2725, problems of graceful shutdown in 2.6.3 and …
beiwei30 Nov 5, 2018
505d155
enhance comments (#2735)
beiwei30 Nov 5, 2018
2284ede
code format (#2730)
x-ultimate Nov 5, 2018
16f7a1e
Close all servers/ports after tests finish (#2741)
OrDTesters Nov 6, 2018
aed0102
Simplify the code of StringUtils to make it more graceful. (#2740)
code4wt Nov 6, 2018
56b2193
Add 'forks' config into xml config (#2568)
carryxyh Nov 6, 2018
1a88c22
fix typo (#2747)
zonghaishang Nov 7, 2018
e3bd693
[DUBBO-2489] MockClusterInvoker provides local forced mock,I tested i…
beiwei30 Nov 7, 2018
b0107e7
#2748: Provider should disable mock configuration (#2749)
beiwei30 Nov 7, 2018
aa9f16e
Fix the bug that ReferenceBean refers service more than once when deb…
code4wt Nov 8, 2018
20a5efb
Close all servers/ports after tests finish (#2755)
OrDTesters Nov 8, 2018
a7cf737
add checkstyle rule to check import order (#2745)
htynkn Nov 8, 2018
dcbd326
Changing URL so tests can run in any order (#2760)
OrDTesters Nov 8, 2018
117d485
[Dubbo-2353]fix Invalid property 'interfaceName' of bean class [org.a…
kexianjun Nov 8, 2018
7f5fd46
#2762: [Dubbo - qos-http] stopServer should be invoked ? (#2767)
beiwei30 Nov 9, 2018
bff16eb
#2777: heartbeat threads blocks process shutdown (#2778)
beiwei30 Nov 13, 2018
38a6511
oschina vote (#2786)
beiwei30 Nov 14, 2018
b1a7622
fix typo (#2791)
kun-song Nov 16, 2018
9466425
improvement on Parameters and CollectionUtils (#2790)
kun-song Nov 16, 2018
026fa0b
[REFACTOR]:[fix typo] (#2804)
Ivan97 Nov 19, 2018
5ea6b33
[Dubbo-2798]fix apporiate NotWritablePropertyException (#2800)
kexianjun Nov 20, 2018
28b3736
[Dubbo-2758] Adding dependency on dubbo-remoting-mina for tests in du…
OrDTesters Nov 22, 2018
a24289f
modify dubbo version to 2.6.5
cvictory Nov 23, 2018
46b3458
fix typo of field (#2825)
likemoongg Nov 24, 2018
5aeb049
[Dubbo-2845] Fix OOM in UT testSelectByWeight (#2845) (#2846)
biyuhao Nov 29, 2018
bc6a06c
Fix UT failed on windows with FileNetworkerTest (#2848)
water-coder Nov 29, 2018
133d570
Update README.md
beiwei30 Dec 3, 2018
32140d4
fixed typo of variable (#2875)
zzkyeee Dec 4, 2018
d0f7c05
Remove unnessesary code in RegistryDirectory#doList (#2861)
LiZhenNet Dec 4, 2018
1f751a6
add some ScriptRoute test case (#2879)
lixiaojiee Dec 4, 2018
e8af04d
remove the duplicate superclass of TagRouter and ConditionRouter (#2885)
lixiaojiee Dec 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify the code of StringUtils to make it more graceful. (apache#2740
)

* Simplify the code of StringUtils to make it more graceful.

* Add Apache license
code4wt authored and beiwei30 committed Nov 6, 2018
commit aed0102f0a5a1d5d795bbe4589562d4346f41e70
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.dubbo.common.utils;

/**
* Contains some methods to check array.
*/
public final class ArrayUtils {

private ArrayUtils() {
}

/**
* <p>Checks if the array is null or empty. <p/>
*
* @param array th array to check
* @return {@code true} if the array is null or empty.
*/
public static boolean isEmpty(final Object[] array) {
return array == null || array.length == 0;
}

/**
* <p>Checks if the array is not null or empty. <p/>
*
* @param array th array to check
* @return {@code true} if the array is not null or empty.
*/
public static boolean isNotEmpty(final Object[] array) {
return !isEmpty(array);
}
}
Original file line number Diff line number Diff line change
@@ -174,7 +174,7 @@ public static String repeat(final String str, final String separator, final int
* {@code null} if null String input
*/
public static String removeEnd(final String str, final String remove) {
if (isEmpty(str) || isEmpty(remove)) {
if (isAnyEmpty(str, remove)) {
return str;
}
if (str.endsWith(remove)) {
@@ -314,7 +314,7 @@ public static String replace(final String text, final String searchString, final
* {@code null} if null String input
*/
public static String replace(final String text, final String searchString, final String replacement, int max) {
if (isEmpty(text) || isEmpty(searchString) || replacement == null || max == 0) {
if (isAnyEmpty(text, searchString) || replacement == null || max == 0) {
return text;
}
int start = 0;
@@ -340,10 +340,7 @@ public static String replace(final String text, final String searchString, final
}

public static boolean isBlank(String str) {
if (str == null || str.length() == 0) {
return true;
}
return false;
return isEmpty(str);
}

/**
@@ -353,10 +350,57 @@ public static boolean isBlank(String str) {
* @return is empty.
*/
public static boolean isEmpty(String str) {
if (str == null || str.length() == 0) {
return true;
return str == null || str.isEmpty();
}

/**
* <p>Checks if the strings contain empty or null elements. <p/>
*
* <pre>
* StringUtils.isNoneEmpty(null) = false
* StringUtils.isNoneEmpty("") = false
* StringUtils.isNoneEmpty(" ") = true
* StringUtils.isNoneEmpty("abc") = true
* StringUtils.isNoneEmpty("abc", "def") = true
* StringUtils.isNoneEmpty("abc", null) = false
* StringUtils.isNoneEmpty("abc", "") = false
* StringUtils.isNoneEmpty("abc", " ") = true
* </pre>
*
* @param ss the strings to check
* @return {@code true} if all strings are not empty or null
*/
public static boolean isNoneEmpty(final String... ss) {
if (ArrayUtils.isEmpty(ss)) {
return false;
}
return false;
for (final String s : ss){
if (isEmpty(s)) {
return false;
}
}
return true;
}

/**
* <p>Checks if the strings contain at least on empty or null element. <p/>
*
* <pre>
* StringUtils.isAnyEmpty(null) = true
* StringUtils.isAnyEmpty("") = true
* StringUtils.isAnyEmpty(" ") = false
* StringUtils.isAnyEmpty("abc") = false
* StringUtils.isAnyEmpty("abc", "def") = false
* StringUtils.isAnyEmpty("abc", null) = true
* StringUtils.isAnyEmpty("abc", "") = true
* StringUtils.isAnyEmpty("abc", " ") = false
* </pre>
*
* @param ss the strings to check
* @return {@code true} if at least one in the strings is empty or null
*/
public static boolean isAnyEmpty(final String... ss) {
return !isNoneEmpty(ss);
}

/**
@@ -366,7 +410,7 @@ public static boolean isEmpty(String str) {
* @return is not empty.
*/
public static boolean isNotEmpty(String str) {
return str != null && str.length() > 0;
return !isEmpty(str);
}

/**
@@ -391,25 +435,19 @@ public static boolean isEquals(String s1, String s2) {
* @return is integer
*/
public static boolean isInteger(String str) {
if (str == null || str.length() == 0) {
return false;
}
return INT_PATTERN.matcher(str).matches();
return isNotEmpty(str) && INT_PATTERN.matcher(str).matches();
}

public static int parseInteger(String str) {
if (!isInteger(str)) {
return 0;
}
return Integer.parseInt(str);
return isInteger(str) ? Integer.parseInt(str) : 0;
}

/**
* Returns true if s is a legal Java identifier.<p>
* <a href="http://www.exampledepot.com/egs/java.lang/IsJavaId.html">more info.</a>
*/
public static boolean isJavaIdentifier(String s) {
if (s.length() == 0 || !Character.isJavaIdentifierStart(s.charAt(0))) {
if (isEmpty(s) || !Character.isJavaIdentifierStart(s.charAt(0))) {
return false;
}
for (int i = 1; i < s.length(); i++) {
@@ -421,10 +459,7 @@ public static boolean isJavaIdentifier(String s) {
}

public static boolean isContains(String values, String value) {
if (values == null || values.length() == 0) {
return false;
}
return isContains(Constants.COMMA_SPLIT_PATTERN.split(values), value);
return isNotEmpty(values) && isContains(Constants.COMMA_SPLIT_PATTERN.split(values), value);
}

/**
@@ -433,7 +468,7 @@ public static boolean isContains(String values, String value) {
* @return contains
*/
public static boolean isContains(String[] values, String value) {
if (value != null && value.length() > 0 && values != null && values.length > 0) {
if (isNotEmpty(value) && ArrayUtils.isNotEmpty(values)) {
for (String v : values) {
if (value.equals(v)) {
return true;
@@ -449,7 +484,7 @@ public static boolean isNumeric(String str) {
}
int sz = str.length();
for (int i = 0; i < sz; i++) {
if (Character.isDigit(str.charAt(i)) == false) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
@@ -494,14 +529,14 @@ public static String toString(String msg, Throwable e) {
}

/**
* translat.
* translate.
*
* @param src source string.
* @param from src char table.
* @param to target char table.
* @return String.
*/
public static String translat(String src, String from, String to) {
public static String translate(String src, String from, String to) {
if (isEmpty(src)) {
return src;
}
@@ -561,8 +596,8 @@ public static String[] split(String str, char ch) {
* @return String.
*/
public static String join(String[] array) {
if (array.length == 0) {
return "";
if (ArrayUtils.isEmpty(array)) {
return EMPTY;
}
StringBuilder sb = new StringBuilder();
for (String s : array) {
@@ -579,8 +614,8 @@ public static String join(String[] array) {
* @return String.
*/
public static String join(String[] array, char split) {
if (array.length == 0) {
return "";
if (ArrayUtils.isEmpty(array)) {
return EMPTY;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < array.length; i++) {
@@ -600,8 +635,8 @@ public static String join(String[] array, char split) {
* @return String.
*/
public static String join(String[] array, String split) {
if (array.length == 0) {
return "";
if (ArrayUtils.isEmpty(array)) {
return EMPTY;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < array.length; i++) {
@@ -614,8 +649,8 @@ public static String join(String[] array, String split) {
}

public static String join(Collection<String> coll, String split) {
if (coll.isEmpty()) {
return "";
if (CollectionUtils.isEmpty(coll)) {
return EMPTY;
}

StringBuilder sb = new StringBuilder();
@@ -643,7 +678,7 @@ private static Map<String, String> parseKeyValuePair(String str, String itemSepa
Map<String, String> map = new HashMap<String, String>(tmp.length);
for (int i = 0; i < tmp.length; i++) {
Matcher matcher = KVP_PATTERN.matcher(tmp[i]);
if (matcher.matches() == false) {
if (!matcher.matches()) {
continue;
}
map.put(matcher.group(1), matcher.group(2));
@@ -663,7 +698,7 @@ public static String getQueryStringValue(String qs, String key) {
* @return Parameters instance.
*/
public static Map<String, String> parseQueryString(String qs) {
if (qs == null || qs.length() == 0) {
if (isEmpty(qs)) {
return new HashMap<String, String>();
}
return parseKeyValuePair(qs, "\\&");
@@ -672,12 +707,12 @@ public static Map<String, String> parseQueryString(String qs) {
public static String getServiceKey(Map<String, String> ps) {
StringBuilder buf = new StringBuilder();
String group = ps.get(Constants.GROUP_KEY);
if (group != null && group.length() > 0) {
if (isNotEmpty(group)) {
buf.append(group).append("/");
}
buf.append(ps.get(Constants.INTERFACE_KEY));
String version = ps.get(Constants.VERSION_KEY);
if (version != null && version.length() > 0) {
if (isNotEmpty(group)) {
buf.append(":").append(version);
}
return buf.toString();
@@ -689,8 +724,7 @@ public static String toQueryString(Map<String, String> ps) {
for (Map.Entry<String, String> entry : new TreeMap<String, String>(ps).entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key != null && key.length() > 0
&& value != null && value.length() > 0) {
if (isNoneEmpty(key, value)) {
if (buf.length() > 0) {
buf.append("&");
}
@@ -704,7 +738,7 @@ public static String toQueryString(Map<String, String> ps) {
}

public static String camelToSplitName(String camelName, String split) {
if (camelName == null || camelName.length() == 0) {
if (isEmpty(camelName)) {
return camelName;
}
StringBuilder buf = null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.dubbo.common.utils;

import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;

import org.junit.Test;

public class ArrayUtilsTest {

@Test
public void isEmpty() throws Exception {
assertTrue(ArrayUtils.isEmpty(null));
assertTrue(ArrayUtils.isEmpty(new Object[0]));
assertFalse(ArrayUtils.isEmpty(new Object[]{"abc"}));
}

@Test
public void isNotEmpty() throws Exception {
assertFalse(ArrayUtils.isNotEmpty(null));
assertFalse(ArrayUtils.isNotEmpty(new Object[0]));
assertTrue(ArrayUtils.isNotEmpty(new Object[]{"abc"}));
}

}
Original file line number Diff line number Diff line change
@@ -111,6 +111,30 @@ public void testIsEmpty() throws Exception {
assertFalse(StringUtils.isEmpty("abc"));
}

@Test
public void testIsNoneEmpty() throws Exception {
assertFalse(StringUtils.isNoneEmpty(null));
assertFalse(StringUtils.isNoneEmpty(""));
assertTrue(StringUtils.isNoneEmpty(" "));
assertTrue(StringUtils.isNoneEmpty("abc"));
assertTrue(StringUtils.isNoneEmpty("abc", "def"));
assertFalse(StringUtils.isNoneEmpty("abc", null));
assertFalse(StringUtils.isNoneEmpty("abc", ""));
assertTrue(StringUtils.isNoneEmpty("abc", " "));
}

@Test
public void testIsAnyEmpty() throws Exception {
assertTrue(StringUtils.isAnyEmpty(null));
assertTrue(StringUtils.isAnyEmpty(""));
assertFalse(StringUtils.isAnyEmpty(" "));
assertFalse(StringUtils.isAnyEmpty("abc"));
assertFalse(StringUtils.isAnyEmpty("abc", "def"));
assertTrue(StringUtils.isAnyEmpty("abc", null));
assertTrue(StringUtils.isAnyEmpty("abc", ""));
assertFalse(StringUtils.isAnyEmpty("abc", " "));
}

@Test
public void testIsNotEmpty() throws Exception {
assertFalse(StringUtils.isNotEmpty(null));
@@ -200,10 +224,10 @@ public void testSplit() throws Exception {
}

@Test
public void testTranslat() throws Exception {
public void testTranslate() throws Exception {
String s = "16314";
assertEquals(StringUtils.translat(s, "123456", "abcdef"), "afcad");
assertEquals(StringUtils.translat(s, "123456", "abcd"), "acad");
assertEquals(StringUtils.translate(s, "123456", "abcdef"), "afcad");
assertEquals(StringUtils.translate(s, "123456", "abcd"), "acad");
}

@Test