mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add test
This commit is contained in:
parent
7baac80d32
commit
185764ec75
@ -1,5 +1,7 @@
|
||||
package cn.hutool.core.text;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -27,4 +29,53 @@ public class StrJoinerTest {
|
||||
final StrJoiner append = StrJoiner.of(",");
|
||||
Assert.assertEquals("", append.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinMultiArrayTest(){
|
||||
final StrJoiner append = StrJoiner.of(",");
|
||||
append.append(new Object[]{ListUtil.of("1", "2"),
|
||||
CollUtil.newHashSet("3", "4")
|
||||
});
|
||||
Assert.assertEquals("1,2,3,4", append.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinNullModeTest(){
|
||||
StrJoiner append = StrJoiner.of(",")
|
||||
.setNullMode(StrJoiner.NullMode.IGNORE)
|
||||
.append("1")
|
||||
.append((Object)null)
|
||||
.append("3");
|
||||
Assert.assertEquals("1,3", append.toString());
|
||||
|
||||
append = StrJoiner.of(",")
|
||||
.setNullMode(StrJoiner.NullMode.TO_EMPTY)
|
||||
.append("1")
|
||||
.append((Object)null)
|
||||
.append("3");
|
||||
Assert.assertEquals("1,,3", append.toString());
|
||||
|
||||
append = StrJoiner.of(",")
|
||||
.setNullMode(StrJoiner.NullMode.NULL_STRING)
|
||||
.append("1")
|
||||
.append((Object)null)
|
||||
.append("3");
|
||||
Assert.assertEquals("1,null,3", append.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinWrapTest(){
|
||||
StrJoiner append = StrJoiner.of(",", "[", "]")
|
||||
.append("1")
|
||||
.append("2")
|
||||
.append("3");
|
||||
Assert.assertEquals("[1,2,3]", append.toString());
|
||||
|
||||
append = StrJoiner.of(",", "[", "]")
|
||||
.setWrapElement(true)
|
||||
.append("1")
|
||||
.append("2")
|
||||
.append("3");
|
||||
Assert.assertEquals("[1],[2],[3]", append.toString());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user