diff --git a/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java b/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java index 7e239d1cc9..aa6cf35811 100644 --- a/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java @@ -797,6 +797,20 @@ class ObjectUtilsTests { assertThat(ObjectUtils.containsConstant(Tropes.values(), "foo", true)).isFalse(); } + @Test + void containsElement() { + Object[] array = {"foo", "bar", 42, new String[] {"baz", "quux"}}; + + assertThat(ObjectUtils.containsElement(null, "foo")).isFalse(); + assertThat(ObjectUtils.containsElement(array, null)).isFalse(); + assertThat(ObjectUtils.containsElement(array, "bogus")).isFalse(); + + assertThat(ObjectUtils.containsElement(array, "foo")).isTrue(); + assertThat(ObjectUtils.containsElement(array, "bar")).isTrue(); + assertThat(ObjectUtils.containsElement(array, 42)).isTrue(); + assertThat(ObjectUtils.containsElement(array, new String[] {"baz", "quux"})).isTrue(); + } + @Test void caseInsensitiveValueOf() { assertThat(ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "foo")).isEqualTo(Tropes.FOO); @@ -807,20 +821,6 @@ class ObjectUtilsTests { .withMessage("Constant [bogus] does not exist in enum type org.springframework.util.ObjectUtilsTests$Tropes"); } - @Test - void containsElement() { - String keyObject = "key"; - String[] array = {"foo", "bar", "Bar", keyObject}; - - String fakeObject = "fake"; - - assertThat(ObjectUtils.containsElement(null, keyObject)).isFalse(); - - assertThat(ObjectUtils.containsElement(array, keyObject)).isTrue(); - - assertThat(ObjectUtils.containsElement(array, fakeObject)).isFalse(); - } - private void assertEqualHashCodes(int expected, Object array) { int actual = ObjectUtils.nullSafeHashCode(array); assertThat(actual).isEqualTo(expected);