mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
add test
This commit is contained in:
parent
284bb06416
commit
6c55464dc9
@ -145,7 +145,7 @@ public class StrJoiner implements Appendable, Serializable {
|
||||
/**
|
||||
* 设置分隔符
|
||||
*
|
||||
* @param delimiter 分隔符
|
||||
* @param delimiter 分隔符,{@code null}表示无连接符,直接拼接
|
||||
* @return this
|
||||
*/
|
||||
public StrJoiner setDelimiter(final CharSequence delimiter) {
|
||||
@ -422,7 +422,9 @@ public class StrJoiner implements Appendable, Serializable {
|
||||
*/
|
||||
private Appendable prepare() throws IOException {
|
||||
if (hasContent) {
|
||||
this.appendable.append(delimiter);
|
||||
if(null != delimiter){
|
||||
this.appendable.append(delimiter);
|
||||
}
|
||||
} else {
|
||||
if (null == this.appendable) {
|
||||
this.appendable = new StringBuilder();
|
||||
|
@ -13,7 +13,6 @@
|
||||
package org.dromara.hutool.core.array;
|
||||
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.core.util.CharsetUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -26,10 +25,9 @@ import java.util.*;
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
@SuppressWarnings("ConstantValue")
|
||||
public class ArrayUtilTest {
|
||||
|
||||
@SuppressWarnings("DataFlowIssue")
|
||||
@SuppressWarnings({"DataFlowIssue", "ConstantValue"})
|
||||
@Test
|
||||
public void isEmptyTest() {
|
||||
final int[] a = {};
|
||||
@ -330,6 +328,41 @@ public class ArrayUtilTest {
|
||||
Assertions.assertEquals("aa,bb,cc,dd", join2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinWithNullElement() {
|
||||
final String[] array = { "Java", null, "Python" };
|
||||
final String result = ArrayUtil.join(array, ", ", value -> value == null ? "null" : value);
|
||||
Assertions.assertEquals("Java, null, Python", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinWithEmptyArray() {
|
||||
final String[] array = {};
|
||||
final String result = ArrayUtil.join(array, ", ", String::toUpperCase);
|
||||
Assertions.assertEquals("", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinWithoutEditor() {
|
||||
final Integer[] array = { 1, 2, 3 };
|
||||
final String result = ArrayUtil.join(array, ", ");
|
||||
Assertions.assertEquals("1, 2, 3", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinWithEditor() {
|
||||
final String[] array = { "java", "scala", "kotlin" };
|
||||
final String result = ArrayUtil.join(array, " -> ", String::toUpperCase);
|
||||
Assertions.assertEquals("JAVA -> SCALA -> KOTLIN", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinWithNullConjunction() {
|
||||
final String[] array = { "one", "two", "three" };
|
||||
final String result = ArrayUtil.join(array, null, value -> value + "!");
|
||||
Assertions.assertEquals("one!two!three!", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getArrayTypeTest() {
|
||||
Class<?> arrayType = ArrayUtil.getArrayType(int.class);
|
||||
@ -656,7 +689,6 @@ public class ArrayUtilTest {
|
||||
void setOrPaddingTest(){
|
||||
final String[] arr = new String[0];
|
||||
final String[] newArr = ArrayUtil.setOrPadding(arr, 2, "Good");
|
||||
Console.log(newArr);
|
||||
Assertions.assertArrayEquals(new String[]{null, null, "Good"}, newArr);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user