diff --git a/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityDecoderTest.java b/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityDecoderTest.java deleted file mode 100644 index 88355eadade..00000000000 --- a/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityDecoderTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.springframework.web.util; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class HtmlCharacterEntityDecoderTest { - - @Test - @DisplayName("Should correctly unescape Unicode supplementary characters") - void unescapeHandlesSupplementaryCharactersCorrectly() { - // Arrange: Prepare test cases with the 'grinning face' emoji (😀, U+1F600). - String expectedCharacter = "😀"; - String decimalEntity = "😀"; - String hexEntity = "😀"; - - // Act: Call the HtmlUtils.htmlUnescape method to get the actual results. - String actualResultFromDecimal = HtmlUtils.htmlUnescape(decimalEntity); - String actualResultFromHex = HtmlUtils.htmlUnescape(hexEntity); - - // Assert: Verify that the actual results match the expected character. - assertEquals(expectedCharacter, actualResultFromDecimal, "Decimal entity was not converted correctly."); - assertEquals(expectedCharacter, actualResultFromHex, "Hexadecimal entity was not converted correctly."); - } - - @Test - @DisplayName("Should correctly unescape basic and named HTML entities") - void unescapeHandlesBasicEntities() { - // Arrange - String input = "<p>Tom & Jerry's "Show"</p>"; - String expectedOutput = "
Tom & Jerry's \"Show\"
"; - - // Act - String actualOutput = HtmlUtils.htmlUnescape(input); - - // Assert - assertEquals(expectedOutput, actualOutput, "Basic HTML entities were not unescaped correctly."); - } - -} - diff --git a/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityDecoderTests.java b/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityDecoderTests.java new file mode 100644 index 00000000000..8aa45a08a66 --- /dev/null +++ b/spring-web/src/test/java/org/springframework/web/util/HtmlCharacterEntityDecoderTests.java @@ -0,0 +1,53 @@ +/* + * Copyright 2002-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.web.util; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + + +/** + * Tests for {@link HtmlCharacterEntityDecoder}. + */ +class HtmlCharacterEntityDecoderTests { + + @Test + void unescapeHandlesSupplementaryCharactersAsDecimal() { + String expectedCharacter = "😀"; + String decimalEntity = "😀"; + String actualResultFromDecimal = HtmlUtils.htmlUnescape(decimalEntity); + assertThat(actualResultFromDecimal).as("Decimal entity was not converted correctly.").isEqualTo(expectedCharacter); + } + + @Test + void unescapeHandlesSupplementaryCharactersAsHexadecimal() { + String expectedCharacter = "😀"; + String hexEntity = "😀"; + String actualResultFromHex = HtmlUtils.htmlUnescape(hexEntity); + assertThat(actualResultFromHex).as("Hexadecimal entity was not converted correctly.").isEqualTo(expectedCharacter); + } + + @Test + void unescapeHandlesBasicEntities() { + String input = "<p>Tom & Jerry's "Show"</p>"; + String expectedOutput = "Tom & Jerry's \"Show\"
"; + String actualOutput = HtmlUtils.htmlUnescape(input); + assertThat(actualOutput).as("Basic HTML entities were not unescaped correctly.").isEqualTo(expectedOutput); + } + +}