mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code to replace join
This commit is contained in:
@@ -32,6 +32,7 @@ public class IterUtilTest {
|
||||
String join1 = IterUtil.join(list1.iterator(), ":");
|
||||
Assert.assertEquals("1:2:3:4", join1);
|
||||
|
||||
// 包装每个节点
|
||||
ArrayList<String> list2 = CollUtil.newArrayList("1", "2", "3", "4");
|
||||
String join2 = IterUtil.join(list2.iterator(), ":", "\"", "\"");
|
||||
Assert.assertEquals("\"1\":\"2\":\"3\":\"4\"", join2);
|
||||
@@ -44,6 +45,13 @@ public class IterUtilTest {
|
||||
Assert.assertEquals("1:2:3:4", join);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinWithNullTest() {
|
||||
ArrayList<String> list = CollUtil.newArrayList("1", null, "3", "4");
|
||||
String join = IterUtil.join(list.iterator(), ":", String::valueOf);
|
||||
Assert.assertEquals("1:null:3:4", join);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToListMap() {
|
||||
Map<String, List<String>> expectedMap = new HashMap<>();
|
||||
|
@@ -1,58 +1,58 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import cn.hutool.core.io.resource.ClassPathResource;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.io.resource.ClassPathResource;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* ClassPath资源读取测试
|
||||
* @author Looly
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class ClassPathResourceTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void readStringTest() throws IOException{
|
||||
public void readStringTest() {
|
||||
ClassPathResource resource = new ClassPathResource("test.properties");
|
||||
String content = resource.readUtf8Str();
|
||||
Assert.assertTrue(StrUtil.isNotEmpty(content));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void readStringTest2() throws IOException{
|
||||
public void readStringTest2() {
|
||||
// 读取classpath根目录测试
|
||||
ClassPathResource resource = new ClassPathResource("/");
|
||||
String content = resource.readUtf8Str();
|
||||
Assert.assertTrue(StrUtil.isNotEmpty(content));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void readTest() throws IOException{
|
||||
public void readTest() throws IOException {
|
||||
ClassPathResource resource = new ClassPathResource("test.properties");
|
||||
Properties properties = new Properties();
|
||||
properties.load(resource.getStream());
|
||||
|
||||
|
||||
Assert.assertEquals("1", properties.get("a"));
|
||||
Assert.assertEquals("2", properties.get("b"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void readFromJarTest() throws IOException{
|
||||
public void readFromJarTest() {
|
||||
//测试读取junit的jar包下的LICENSE-junit.txt文件
|
||||
final ClassPathResource resource = new ClassPathResource("LICENSE-junit.txt");
|
||||
|
||||
|
||||
String result = resource.readUtf8Str();
|
||||
Assert.assertNotNull(result);
|
||||
|
||||
|
||||
//二次读取测试,用于测试关闭流对再次读取的影响
|
||||
result = resource.readUtf8Str();
|
||||
Assert.assertNotNull(result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getAbsTest() {
|
||||
final ClassPathResource resource = new ClassPathResource("LICENSE-junit.txt");
|
||||
|
@@ -0,0 +1,30 @@
|
||||
package cn.hutool.core.text;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class StrJoinerTest {
|
||||
|
||||
@Test
|
||||
public void joinIntArrayTest(){
|
||||
int[] a = {1,2,3,4,5};
|
||||
final StrJoiner append = StrJoiner.of(",").append(a);
|
||||
Assert.assertEquals("1,2,3,4,5", append.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinEmptyTest(){
|
||||
List<String> list = new ArrayList<>();
|
||||
final StrJoiner append = StrJoiner.of(",").append(list);
|
||||
Assert.assertEquals("", append.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noJoinTest(){
|
||||
final StrJoiner append = StrJoiner.of(",");
|
||||
Assert.assertEquals("", append.toString());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user