cleanup
This commit is contained in:
@@ -181,11 +181,6 @@
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
|
||||
@@ -199,11 +199,6 @@
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
|
||||
@@ -345,11 +345,6 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
|
||||
+34
-7
@@ -13,15 +13,31 @@ import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* 演示Apache Commons Lang3的StringUtils 和 Guava的Joiner和Spliter。
|
||||
*
|
||||
* Apache的StringUtils已提供绝大多数常用的Null Safe的函数,
|
||||
* Guava提供的是高级版的Joiner和Spliter,Case Format转换等高级函数.
|
||||
*
|
||||
* @author calvin
|
||||
*/
|
||||
public class StringDemo {
|
||||
|
||||
/**
|
||||
* Apache提供的最常用的Null Safe的函数。
|
||||
* 另有一些与String一样,但Null Safe的函数如indexOf(),没有一一演示。
|
||||
*/
|
||||
@Test
|
||||
public void utilsByApache() {
|
||||
//非空,最常用函数
|
||||
//判断非空,最常用函数
|
||||
assertFalse(StringUtils.isNotBlank(null));
|
||||
assertFalse(StringUtils.isNotBlank(""));
|
||||
assertFalse(StringUtils.isNotBlank(" "));
|
||||
|
||||
//default值
|
||||
assertEquals("defaultStr", StringUtils.defaultIfBlank(null, "defaultStr"));
|
||||
assertEquals("defaultStr", StringUtils.defaultIfBlank("", "defaultStr"));
|
||||
|
||||
//截取字符串
|
||||
String input = "hahakaka";
|
||||
String result = StringUtils.substringAfter(input, "ha");
|
||||
@@ -44,23 +60,31 @@ public class StringDemo {
|
||||
result = StringUtils.leftPad("1", 3, '0');
|
||||
assertEquals("001", result);
|
||||
|
||||
//超长部分变省略号
|
||||
assertEquals("abcdefg", StringUtils.abbreviate("abcdefg", 7));
|
||||
assertEquals("abc...", StringUtils.abbreviate("abcdefg", 6));
|
||||
assertEquals("ab...", StringUtils.abbreviate("abcdefg", 5));
|
||||
|
||||
//首字母大写
|
||||
result = StringUtils.capitalize("abc");
|
||||
assertEquals("Abc", result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Guava的高级版Joiner,Splitter的函数与Joiner类似而相反,不再演示。
|
||||
*/
|
||||
@Test
|
||||
public void joinByGuava() {
|
||||
public void joinerByGuava() {
|
||||
|
||||
//忽略Null值。
|
||||
String[] fantasyGenres = { "Space Opera", null, "Horror", "Magic realism", null, "Religion" };
|
||||
String joined = Joiner.on(", ").skipNulls().join(fantasyGenres);
|
||||
System.out.println(joined);
|
||||
assertEquals("Space Opera, Horror, Magic realism, Religion", joined);
|
||||
|
||||
//将Null值转换为特定字符串.
|
||||
String[] fantasyGenres2 = { "Space Opera", null, "Horror", "Magic realism", null, "Religion" };
|
||||
joined = Joiner.on(", ").useForNull("NULL!!!").join(fantasyGenres2);
|
||||
System.out.println(joined);
|
||||
assertEquals("Space Opera, NULL!!!, Horror, Magic realism, NULL!!!, Religion", joined);
|
||||
|
||||
//join Map类型
|
||||
Map<Integer, String> map = Maps.newHashMap();
|
||||
@@ -68,14 +92,17 @@ public class StringDemo {
|
||||
map.put(2, "Horror");
|
||||
map.put(3, "Magic realism");
|
||||
joined = Joiner.on(",").withKeyValueSeparator(":").join(map);
|
||||
System.out.println(joined);
|
||||
assertEquals("1:Space Opera,2:Horror,3:Magic realism", joined);
|
||||
|
||||
//append一个已存在的字符串
|
||||
StringBuilder sb = new StringBuilder("StringBulder Demo: ");
|
||||
StringBuilder sb = new StringBuilder("Append StringBulder demo: ");
|
||||
joined = Joiner.on(", ").skipNulls().appendTo(sb, fantasyGenres).toString();
|
||||
System.out.println(joined);
|
||||
assertEquals("Append StringBulder demo: Space Opera, Horror, Magic realism, Religion", joined);
|
||||
}
|
||||
|
||||
/**
|
||||
* 好玩的CaseFormat转换,在spaceSize->space_size之间转换,比如数据库列名与Java属性。
|
||||
*/
|
||||
@Test
|
||||
public void caseFormatByGuava() {
|
||||
String name = "SPACE_SIZE";
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<h3>日志演示</h3>
|
||||
<ul>
|
||||
<li>Log4JManager: 通过JMX动态查询与改变Logger的日志等级与Appender, 详见JMX页面.</li>
|
||||
<li>MockLog4jAppender: 在测试用例中验证日志的输出, 在Schedule测试用例使用MockAppender校验日志输出.</li>
|
||||
<li>Log4MockjAppender: 在测试用例中验证日志的输出, 在Schedule测试用例使用MockAppender校验日志输出.</li>
|
||||
</ul>
|
||||
<hr/>
|
||||
<h3>其他常用工具</h3>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
演示基于JQuery的JSONP实现,绕过浏览器对Ajax不能访问跨域名网站内容的限制实现Mashup.<br /> 请先将本页另存为本地html文件,打开本地文件访问本地应用服务器中的内容即为跨域访问的场景.
|
||||
</p>
|
||||
<p>
|
||||
<input type="button" value="获取内容" onclick="fetchMashupContent();" />
|
||||
<input type="button" class="btn" value="获取内容" onclick="fetchMashupContent();" />
|
||||
</p>
|
||||
<p>跨域页面内容:</p>
|
||||
<div id="mashupContent" style="display: none" />
|
||||
|
||||
@@ -122,11 +122,7 @@
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
@@ -54,15 +55,11 @@ public class PropertiesLoader {
|
||||
}
|
||||
|
||||
/**
|
||||
* 取出Property,但以System的Property优先.
|
||||
* 取出Property,但以System的Property优先.如果都為Null則返回Default值.
|
||||
*/
|
||||
public String getProperty(String key, String defaultValue) {
|
||||
String result = getProperty(key);
|
||||
if (result != null) {
|
||||
return result;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
return StringUtils.defaultString(result, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +73,12 @@ public class PropertiesLoader {
|
||||
* 取出Property,但以System的Property优先.
|
||||
*/
|
||||
public Integer getInteger(String key, Integer defaultValue) {
|
||||
return Integer.valueOf(getProperty(key, String.valueOf(defaultValue)));
|
||||
String strResult = getProperty(key);
|
||||
if (strResult != null) {
|
||||
return Integer.valueOf(strResult);
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +92,13 @@ public class PropertiesLoader {
|
||||
* 取出Property,但以System的Property优先.
|
||||
*/
|
||||
public Boolean getBoolean(String key, boolean defaultValue) {
|
||||
return Boolean.valueOf(getProperty(key, String.valueOf(defaultValue)));
|
||||
String strResult = getProperty(key);
|
||||
if (strResult != null) {
|
||||
return Boolean.valueOf(strResult);
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,11 +75,6 @@
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
|
||||
+2
-2
@@ -22,12 +22,12 @@ public class SpyMemcachedClientTest extends SpringContextTestCase {
|
||||
String value = "admin";
|
||||
|
||||
spyMemcachedClient.set(key, 60 * 60 * 1, value);
|
||||
Threads.sleep(1000);
|
||||
Threads.sleep(2000);
|
||||
String result = spyMemcachedClient.get(key);
|
||||
assertEquals(value, result);
|
||||
|
||||
spyMemcachedClient.delete(key);
|
||||
Threads.sleep(1000);
|
||||
Threads.sleep(2000);
|
||||
result = spyMemcachedClient.get(key);
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
@echo off
|
||||
echo [INFO] Use maven eclipse plugin download jar and generate eclipse project files.
|
||||
echo [INFO] Please add "-Declipse.workspace=<path-to-eclipse-workspace>" at end of mvn command.
|
||||
|
||||
cd %~dp0
|
||||
cd ..
|
||||
call mvn eclipse:clean eclipse:eclipse
|
||||
cd bin
|
||||
pause
|
||||
@@ -2,7 +2,5 @@
|
||||
echo [INFO] Install jar to local repository.
|
||||
|
||||
cd %~dp0
|
||||
cd ..
|
||||
call mvn clean install -Dmaven.test.skip=true
|
||||
cd bin
|
||||
pause
|
||||
+18
-25
@@ -14,6 +14,7 @@
|
||||
<spring.version>3.1.1.RELEASE</spring.version>
|
||||
<hibernate.version>4.1.2</hibernate.version>
|
||||
<mybatis.version>3.1.1</mybatis.version>
|
||||
<spring-data-jpa.version>1.0.3.RELEASE</spring-data-jpa.version>
|
||||
<cxf.version>2.6.0</cxf.version>
|
||||
<jersey.version>1.12</jersey.version>
|
||||
<shiro.version>1.2.0</shiro.version>
|
||||
@@ -22,9 +23,14 @@
|
||||
<ehcache.version>2.5.2</ehcache.version>
|
||||
<hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
|
||||
<jackson.version>2.0.1</jackson.version>
|
||||
<guava.version>11.0.2</guava.version>
|
||||
<commons-lang3.version>3.1</commons-lang3.version>
|
||||
<slf4j.version>1.6.4</slf4j.version>
|
||||
<jetty.version>7.6.3.v20120416</jetty.version>
|
||||
<h2.version>1.3.166</h2.version>
|
||||
<junit.version>4.10</junit.version>
|
||||
<mockito.version>1.9.0</mockito.version>
|
||||
<powermock.version>1.4.12</powermock.version>
|
||||
<selenium.version>2.21.0</selenium.version>
|
||||
|
||||
<!-- Plugin的属性定义 -->
|
||||
@@ -41,7 +47,7 @@
|
||||
<url>http://localhost:8081/nexus/content/groups/public</url>
|
||||
</repository>
|
||||
-->
|
||||
|
||||
<!--
|
||||
<repository>
|
||||
<id>offical</id>
|
||||
<name>Maven Official Repository</name>
|
||||
@@ -67,7 +73,7 @@
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
|
||||
-->
|
||||
</repositories>
|
||||
|
||||
<!-- 设定插件仓库 如有Nexus私服, 取消注释并指向正确的服务器地址.
|
||||
@@ -195,7 +201,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
<version>1.0.3.RELEASE</version>
|
||||
<version>${spring-data-jpa.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- mybatis -->
|
||||
@@ -575,7 +581,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.1</version>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
@@ -608,7 +614,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>11.0.2</version>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- joda -->
|
||||
@@ -680,39 +686,26 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- hamcrest -->
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<version>1.3.RC2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>1.3.RC2</version>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- mockito -->
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>1.9.0</version>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.4.12</version>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.4.12</version>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
@@ -806,7 +799,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<source>${jdk.version}</source>
|
||||
<target>${jdk.version}</target>
|
||||
@@ -950,9 +943,9 @@
|
||||
|
||||
<!-- sonar插件 -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<groupId>org.codehaus.sonar</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>2.0</version>
|
||||
<version>3.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
@@ -142,11 +142,6 @@
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user