This commit is contained in:
Looly
2024-04-27 23:35:42 +08:00
parent 284bb06416
commit 6c55464dc9
2 changed files with 40 additions and 6 deletions

View File

@@ -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);
}