From 284bb0641637a257db71522bd2ef56012fe4c631 Mon Sep 17 00:00:00 2001 From: Looly Date: Sat, 27 Apr 2024 23:18:58 +0800 Subject: [PATCH] add test --- .../dromara/hutool/core/array/ArrayUtil.java | 2 +- .../hutool/core/array/ArrayUtilTest.java | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/hutool-core/src/main/java/org/dromara/hutool/core/array/ArrayUtil.java b/hutool-core/src/main/java/org/dromara/hutool/core/array/ArrayUtil.java index ee121bb52..ac49bfcd3 100644 --- a/hutool-core/src/main/java/org/dromara/hutool/core/array/ArrayUtil.java +++ b/hutool-core/src/main/java/org/dromara/hutool/core/array/ArrayUtil.java @@ -1152,7 +1152,7 @@ public class ArrayUtil extends PrimitiveArrayUtil { } // endregion - // region ----- indexOf and lastIndexOf and contains + // region ----- indexOf and lastIndexOf /** * 返回数组中指定元素所在位置,未找到返回{@link #INDEX_NOT_FOUND} diff --git a/hutool-core/src/test/java/org/dromara/hutool/core/array/ArrayUtilTest.java b/hutool-core/src/test/java/org/dromara/hutool/core/array/ArrayUtilTest.java index 0162c71d7..6f3f41e16 100644 --- a/hutool-core/src/test/java/org/dromara/hutool/core/array/ArrayUtilTest.java +++ b/hutool-core/src/test/java/org/dromara/hutool/core/array/ArrayUtilTest.java @@ -163,12 +163,60 @@ public class ArrayUtilTest { public void containsAllTest() { final Integer[] a = {1, 2, 3, 4, 3, 6}; boolean contains = ArrayUtil.containsAll(a, 4, 2, 6); + // 提供的可变参数中元素顺序不需要一致 Assertions.assertTrue(contains); contains = ArrayUtil.containsAll(a, 1, 2, 3, 5); Assertions.assertFalse(contains); } + @Test + void containsIgnoreCaseTest() { + final String[] keys = {"a", "B", "c"}; + final boolean b = ArrayUtil.containsIgnoreCase(keys, "b"); + Assertions.assertTrue(b); + } + + @Test + public void testContainsIgnoreCaseWithEmptyArray() { + final CharSequence[] array = new CharSequence[0]; + final CharSequence value = "test"; + final boolean result = ArrayUtil.containsIgnoreCase(array, value); + Assertions.assertFalse(result, "Expected the result to be false for an empty array."); + } + + @Test + public void testContainsIgnoreCaseWithNullValue() { + final CharSequence[] array = {"Hello", "World"}; + final CharSequence value = null; + final boolean result = ArrayUtil.containsIgnoreCase(array, value); + Assertions.assertFalse(result, "Expected the result to be false when the value is null."); + } + + @Test + public void testContainsIgnoreCaseWithExistingValue() { + final CharSequence[] array = {"Hello", "World"}; + final CharSequence value = "world"; + final boolean result = ArrayUtil.containsIgnoreCase(array, value); + Assertions.assertTrue(result, "Expected the result to be true when the value exists in the array."); + } + + @Test + public void testContainsIgnoreCaseWithNonExistingValue() { + final CharSequence[] array = {"Hello", "World"}; + final CharSequence value = "Java"; + final boolean result = ArrayUtil.containsIgnoreCase(array, value); + Assertions.assertFalse(result, "Expected the result to be false when the value does not exist in the array."); + } + + @Test + public void testContainsIgnoreCaseWithCaseSensitiveValue() { + final CharSequence[] array = {"Hello", "World"}; + final CharSequence value = "HELLO"; + final boolean result = ArrayUtil.containsIgnoreCase(array, value); + Assertions.assertTrue(result, "Expected the result to be true when the value exists in the array with different case sensitivity."); + } + @Test public void zipTest() { final String[] keys = {"a", "b", "c"}; @@ -525,6 +573,13 @@ public class ArrayUtilTest { Assertions.assertEquals("c", o); } + @Test + public void getByPredicateTest() { + final String[] a = {"a", "b", "c"}; + final Object o = ArrayUtil.get(a, "b"::equals); + Assertions.assertEquals("b", o); + } + @Test public void replaceTest() { final String[] a = {"1", "2", "3", "4"};