This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 1703c21006ccfc9af64ba31547373b5563705c02 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Thu Jun 12 08:26:46 2025 -0400 Sort members --- .../org/apache/commons/lang3/CachedRandomBits.java | 30 ++-- .../java/org/apache/commons/lang3/ClassUtils.java | 10 +- .../org/apache/commons/lang3/EnumUtilsTest.java | 12 +- .../commons/lang3/RandomStringUtilsTest.java | 16 +- .../org/apache/commons/lang3/RegExUtilsTest.java | 164 ++++++++++----------- .../commons/lang3/StringUtilsAbbreviateTest.java | 96 ++++++------ .../org/apache/commons/lang3/ValidateTest.java | 12 +- .../lang3/builder/ReflectionDiffBuilderTest.java | 24 +-- .../commons/lang3/time/FastDateParserTest.java | 18 +-- .../time/FastDateParser_TimeZoneStrategyTest.java | 10 +- 10 files changed, 196 insertions(+), 196 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/CachedRandomBits.java b/src/main/java/org/apache/commons/lang3/CachedRandomBits.java index 5b90a0ecb..8fb610664 100644 --- a/src/main/java/org/apache/commons/lang3/CachedRandomBits.java +++ b/src/main/java/org/apache/commons/lang3/CachedRandomBits.java @@ -37,21 +37,6 @@ */ final class CachedRandomBits { - private final Random random; - - private final byte[] cache; - - /** - * Index of the next bit in the cache to be used. - * - * <ul> - * <li>bitIndex=0 means the cache is fully random and none of the bits have been used yet.</li> - * <li>bitIndex=1 means that only the LSB of cache[0] has been used and all other bits can be used.</li> - * <li>bitIndex=8 means that only the 8 bits of cache[0] has been used.</li> - * </ul> - */ - private int bitIndex; - /** * The maximum size of the cache. * @@ -60,12 +45,27 @@ final class CachedRandomBits { * </p> */ private static final int MAX_CACHE_SIZE = Integer.MAX_VALUE >> 3; + /** Maximum number of bits that can be generated (size of an int) */ private static final int MAX_BITS = 32; + /** Mask to extract the bit offset within a byte (0-7) */ private static final int BIT_INDEX_MASK = 0x7; + /** Number of bits in a byte */ private static final int BITS_PER_BYTE = 8; + private final Random random; + private final byte[] cache; + /** + * Index of the next bit in the cache to be used. + * + * <ul> + * <li>bitIndex=0 means the cache is fully random and none of the bits have been used yet.</li> + * <li>bitIndex=1 means that only the LSB of cache[0] has been used and all other bits can be used.</li> + * <li>bitIndex=8 means that only the 8 bits of cache[0] has been used.</li> + * </ul> + */ + private int bitIndex; /** * Creates a new instance. * diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java index 621ff820f..43090b2db 100644 --- a/src/main/java/org/apache/commons/lang3/ClassUtils.java +++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java @@ -50,11 +50,6 @@ */ public class ClassUtils { - /** - * The maximum number of array dimensions. - */ - private static final int MAX_DIMENSIONS = 255; - /** * Inclusivity literals for {@link #hierarchy(Class, Interfaces)}. * @@ -69,6 +64,11 @@ public enum Interfaces { EXCLUDE } + /** + * The maximum number of array dimensions. + */ + private static final int MAX_DIMENSIONS = 255; + private static final Comparator<Class<?>> COMPARATOR = (o1, o2) -> Objects.compare(getName(o1), getName(o2), String::compareTo); /** diff --git a/src/test/java/org/apache/commons/lang3/EnumUtilsTest.java b/src/test/java/org/apache/commons/lang3/EnumUtilsTest.java index 1bc1be606..bbbc762f3 100644 --- a/src/test/java/org/apache/commons/lang3/EnumUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/EnumUtilsTest.java @@ -36,6 +36,12 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +enum Enum64 { + A00, A01, A02, A03, A04, A05, A06, A07, A08, A09, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, + A23, A24, A25, A26, A27, A28, A29, A30, A31, A32, A33, A34, A35, A36, A37, A38, A39, A40, A41, A42, A43, A44, A45, + A46, A47, A48, A49, A50, A51, A52, A53, A54, A55, A56, A57, A58, A59, A60, A61, A62, A63 +} + /** */ class EnumUtilsTest extends AbstractLangTest { @@ -601,12 +607,6 @@ void testProcessBitVectors_nullClass() { } -enum Enum64 { - A00, A01, A02, A03, A04, A05, A06, A07, A08, A09, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, - A23, A24, A25, A26, A27, A28, A29, A30, A31, A32, A33, A34, A35, A36, A37, A38, A39, A40, A41, A42, A43, A44, A45, - A46, A47, A48, A49, A50, A51, A52, A53, A54, A55, A56, A57, A58, A59, A60, A61, A62, A63 -} - enum Month { JAN(1), FEB(2), MAR(3), APR(4), MAY(5), JUN(6), JUL(7), AUG(8), SEP(9), OCT(10), NOV(11), DEC(12); diff --git a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java index dfddca746..b1128d0a3 100644 --- a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java @@ -218,6 +218,14 @@ void testHomogeneity(final RandomStringUtils rsu) { assertTrue(chiSquare(expected, counts) < 23.025850929940457d, "test homogeneity -- will fail about 1 in 100,000 times"); } + @ParameterizedTest + @ValueSource(ints = {MAX_SAFE_COUNT, MAX_SAFE_COUNT + 1}) + @EnabledIfSystemProperty(named = "test.large.heap", matches = "true") + void testHugeStrings(final int expectedLength) { + final String hugeString = RandomStringUtils.random(expectedLength); + assertEquals(expectedLength, hugeString.length(), "hugeString.length() == expectedLength"); + } + /** * Checks if the string got by {@link RandomStringUtils#random(int)} can be converted to UTF-8 and back without loss. * @@ -807,12 +815,4 @@ void testRandomWithChars(final RandomStringUtils rsu) { assertNotEquals(r1, r3); assertNotEquals(r2, r3); } - - @ParameterizedTest - @ValueSource(ints = {MAX_SAFE_COUNT, MAX_SAFE_COUNT + 1}) - @EnabledIfSystemProperty(named = "test.large.heap", matches = "true") - void testHugeStrings(final int expectedLength) { - final String hugeString = RandomStringUtils.random(expectedLength); - assertEquals(expectedLength, hugeString.length(), "hugeString.length() == expectedLength"); - } } diff --git a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java index 46705c4b8..2386f3b11 100644 --- a/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RegExUtilsTest.java @@ -67,26 +67,6 @@ void testRemoveAll() { assertEquals("", RegExUtils.removeAll((CharSequence) "<A>\nxy\n</A>", Pattern.compile("<A>.*</A>", Pattern.DOTALL))); } - @Test - void testRemoveAllDeprecated() { - assertNull(RegExUtils.removeAll(null, Pattern.compile(""))); - assertEquals("any", RegExUtils.removeAll("any", (Pattern) null)); - - assertEquals("any", RegExUtils.removeAll("any", Pattern.compile(""))); - assertEquals("", RegExUtils.removeAll("any", Pattern.compile(".*"))); - assertEquals("", RegExUtils.removeAll("any", Pattern.compile(".+"))); - assertEquals("", RegExUtils.removeAll("any", Pattern.compile(".?"))); - - assertEquals("A\nB", RegExUtils.removeAll("A<__>\n<__>B", Pattern.compile("<.*>"))); - assertEquals("AB", RegExUtils.removeAll("A<__>\n<__>B", Pattern.compile("(?s)<.*>"))); - assertEquals("ABC123", RegExUtils.removeAll("ABCabc123abc", Pattern.compile("[a-z]"))); - - assertEquals("AB", RegExUtils.removeAll("A<__>\n<__>B", Pattern.compile("<.*>", Pattern.DOTALL))); - assertEquals("AB", RegExUtils.removeAll("A<__>\\n<__>B", Pattern.compile("<.*>"))); - assertEquals("", RegExUtils.removeAll("<A>x\\ny</A>", Pattern.compile("<A>.*</A>"))); - assertEquals("", RegExUtils.removeAll("<A>\nxy\n</A>", Pattern.compile("<A>.*</A>", Pattern.DOTALL))); - } - @Test void testRemoveAll_StringString() { assertNull(RegExUtils.removeAll(null, "")); @@ -107,6 +87,26 @@ void testRemoveAll_StringString() { "RegExUtils.removeAll expecting PatternSyntaxException"); } + @Test + void testRemoveAllDeprecated() { + assertNull(RegExUtils.removeAll(null, Pattern.compile(""))); + assertEquals("any", RegExUtils.removeAll("any", (Pattern) null)); + + assertEquals("any", RegExUtils.removeAll("any", Pattern.compile(""))); + assertEquals("", RegExUtils.removeAll("any", Pattern.compile(".*"))); + assertEquals("", RegExUtils.removeAll("any", Pattern.compile(".+"))); + assertEquals("", RegExUtils.removeAll("any", Pattern.compile(".?"))); + + assertEquals("A\nB", RegExUtils.removeAll("A<__>\n<__>B", Pattern.compile("<.*>"))); + assertEquals("AB", RegExUtils.removeAll("A<__>\n<__>B", Pattern.compile("(?s)<.*>"))); + assertEquals("ABC123", RegExUtils.removeAll("ABCabc123abc", Pattern.compile("[a-z]"))); + + assertEquals("AB", RegExUtils.removeAll("A<__>\n<__>B", Pattern.compile("<.*>", Pattern.DOTALL))); + assertEquals("AB", RegExUtils.removeAll("A<__>\\n<__>B", Pattern.compile("<.*>"))); + assertEquals("", RegExUtils.removeAll("<A>x\\ny</A>", Pattern.compile("<A>.*</A>"))); + assertEquals("", RegExUtils.removeAll("<A>\nxy\n</A>", Pattern.compile("<A>.*</A>", Pattern.DOTALL))); + } + @Test void testRemoveFirst() { assertNull(RegExUtils.removeFirst((CharSequence) null, Pattern.compile(""))); @@ -123,22 +123,6 @@ void testRemoveFirst() { assertEquals("ABC123abc", RegExUtils.removeFirst((CharSequence) "ABCabc123abc", Pattern.compile("[a-z]+"))); } - @Test - void testRemoveFirstDeprecated() { - assertNull(RegExUtils.removeFirst(null, Pattern.compile(""))); - assertEquals("any", RegExUtils.removeFirst("any", (Pattern) null)); - - assertEquals("any", RegExUtils.removeFirst("any", Pattern.compile(""))); - assertEquals("", RegExUtils.removeFirst("any", Pattern.compile(".*"))); - assertEquals("", RegExUtils.removeFirst("any", Pattern.compile(".+"))); - assertEquals("bc", RegExUtils.removeFirst("abc", Pattern.compile(".?"))); - - assertEquals("A\n<__>B", RegExUtils.removeFirst("A<__>\n<__>B", Pattern.compile("<.*>"))); - assertEquals("AB", RegExUtils.removeFirst("A<__>\n<__>B", Pattern.compile("(?s)<.*>"))); - assertEquals("ABCbc123", RegExUtils.removeFirst("ABCabc123", Pattern.compile("[a-z]"))); - assertEquals("ABC123abc", RegExUtils.removeFirst("ABCabc123abc", Pattern.compile("[a-z]+"))); - } - @Test void testRemoveFirst_StringString() { assertNull(RegExUtils.removeFirst(null, "")); @@ -160,6 +144,22 @@ void testRemoveFirst_StringString() { "RegExUtils.removeFirst expecting PatternSyntaxException"); } + @Test + void testRemoveFirstDeprecated() { + assertNull(RegExUtils.removeFirst(null, Pattern.compile(""))); + assertEquals("any", RegExUtils.removeFirst("any", (Pattern) null)); + + assertEquals("any", RegExUtils.removeFirst("any", Pattern.compile(""))); + assertEquals("", RegExUtils.removeFirst("any", Pattern.compile(".*"))); + assertEquals("", RegExUtils.removeFirst("any", Pattern.compile(".+"))); + assertEquals("bc", RegExUtils.removeFirst("abc", Pattern.compile(".?"))); + + assertEquals("A\n<__>B", RegExUtils.removeFirst("A<__>\n<__>B", Pattern.compile("<.*>"))); + assertEquals("AB", RegExUtils.removeFirst("A<__>\n<__>B", Pattern.compile("(?s)<.*>"))); + assertEquals("ABCbc123", RegExUtils.removeFirst("ABCabc123", Pattern.compile("[a-z]"))); + assertEquals("ABC123abc", RegExUtils.removeFirst("ABCabc123abc", Pattern.compile("[a-z]+"))); + } + @Test void testRemovePattern() { assertNull(RegExUtils.removePattern((CharSequence) null, "")); @@ -219,31 +219,6 @@ void testReplaceAll() { assertEquals("Lorem_ipsum_dolor_sit", RegExUtils.replaceAll((CharSequence) "Lorem ipsum dolor sit", Pattern.compile("( +)([a-z]+)"), "_$2")); } - @Test - void testReplaceAllDeprecated() { - assertNull(RegExUtils.replaceAll(null, Pattern.compile(""), "")); - - assertEquals("any", RegExUtils.replaceAll("any", (Pattern) null, "")); - assertEquals("any", RegExUtils.replaceAll("any", Pattern.compile(""), null)); - - assertEquals("zzz", RegExUtils.replaceAll("", Pattern.compile(""), "zzz")); - assertEquals("zzz", RegExUtils.replaceAll("", Pattern.compile(".*"), "zzz")); - assertEquals("", RegExUtils.replaceAll("", Pattern.compile(".+"), "zzz")); - assertEquals("ZZaZZbZZcZZ", RegExUtils.replaceAll("abc", Pattern.compile(""), "ZZ")); - - assertEquals("z\nz", RegExUtils.replaceAll("<__>\n<__>", Pattern.compile("<.*>"), "z")); - assertEquals("z", RegExUtils.replaceAll("<__>\n<__>", Pattern.compile("(?s)<.*>"), "z")); - - assertEquals("z", RegExUtils.replaceAll("<__>\n<__>", Pattern.compile("<.*>", Pattern.DOTALL), "z")); - assertEquals("z", RegExUtils.replaceAll("<__>\\n<__>", Pattern.compile("<.*>"), "z")); - assertEquals("X", RegExUtils.replaceAll("<A>\nxy\n</A>", Pattern.compile("<A>.*</A>", Pattern.DOTALL), "X")); - - assertEquals("ABC___123", RegExUtils.replaceAll("ABCabc123", Pattern.compile("[a-z]"), "_")); - assertEquals("ABC_123", RegExUtils.replaceAll("ABCabc123", Pattern.compile("[^A-Z0-9]+"), "_")); - assertEquals("ABC123", RegExUtils.replaceAll("ABCabc123", Pattern.compile("[^A-Z0-9]+"), "")); - assertEquals("Lorem_ipsum_dolor_sit", RegExUtils.replaceAll("Lorem ipsum dolor sit", Pattern.compile("( +)([a-z]+)"), "_$2")); - } - @Test void testReplaceAll_StringStringString() { assertNull(RegExUtils.replaceAll(null, "", "")); @@ -270,6 +245,31 @@ void testReplaceAll_StringStringString() { "RegExUtils.replaceAll expecting PatternSyntaxException"); } + @Test + void testReplaceAllDeprecated() { + assertNull(RegExUtils.replaceAll(null, Pattern.compile(""), "")); + + assertEquals("any", RegExUtils.replaceAll("any", (Pattern) null, "")); + assertEquals("any", RegExUtils.replaceAll("any", Pattern.compile(""), null)); + + assertEquals("zzz", RegExUtils.replaceAll("", Pattern.compile(""), "zzz")); + assertEquals("zzz", RegExUtils.replaceAll("", Pattern.compile(".*"), "zzz")); + assertEquals("", RegExUtils.replaceAll("", Pattern.compile(".+"), "zzz")); + assertEquals("ZZaZZbZZcZZ", RegExUtils.replaceAll("abc", Pattern.compile(""), "ZZ")); + + assertEquals("z\nz", RegExUtils.replaceAll("<__>\n<__>", Pattern.compile("<.*>"), "z")); + assertEquals("z", RegExUtils.replaceAll("<__>\n<__>", Pattern.compile("(?s)<.*>"), "z")); + + assertEquals("z", RegExUtils.replaceAll("<__>\n<__>", Pattern.compile("<.*>", Pattern.DOTALL), "z")); + assertEquals("z", RegExUtils.replaceAll("<__>\\n<__>", Pattern.compile("<.*>"), "z")); + assertEquals("X", RegExUtils.replaceAll("<A>\nxy\n</A>", Pattern.compile("<A>.*</A>", Pattern.DOTALL), "X")); + + assertEquals("ABC___123", RegExUtils.replaceAll("ABCabc123", Pattern.compile("[a-z]"), "_")); + assertEquals("ABC_123", RegExUtils.replaceAll("ABCabc123", Pattern.compile("[^A-Z0-9]+"), "_")); + assertEquals("ABC123", RegExUtils.replaceAll("ABCabc123", Pattern.compile("[^A-Z0-9]+"), "")); + assertEquals("Lorem_ipsum_dolor_sit", RegExUtils.replaceAll("Lorem ipsum dolor sit", Pattern.compile("( +)([a-z]+)"), "_$2")); + } + @Test void testReplaceFirst() { assertNull(RegExUtils.replaceFirst((CharSequence) null, Pattern.compile(""), "")); @@ -291,27 +291,6 @@ void testReplaceFirst() { assertEquals("Lorem_ipsum dolor sit", RegExUtils.replaceFirst((CharSequence) "Lorem ipsum dolor sit", Pattern.compile("( +)([a-z]+)"), "_$2")); } - @Test - void testReplaceFirstDeprecated() { - assertNull(RegExUtils.replaceFirst(null, Pattern.compile(""), "")); - - assertEquals("any", RegExUtils.replaceFirst("any", (Pattern) null, "")); - assertEquals("any", RegExUtils.replaceFirst("any", Pattern.compile(""), null)); - - assertEquals("zzz", RegExUtils.replaceFirst("", Pattern.compile(""), "zzz")); - assertEquals("zzz", RegExUtils.replaceFirst("", Pattern.compile(".*"), "zzz")); - assertEquals("", RegExUtils.replaceFirst("", Pattern.compile(".+"), "zzz")); - assertEquals("ZZabc", RegExUtils.replaceFirst("abc", Pattern.compile(""), "ZZ")); - - assertEquals("z\n<__>", RegExUtils.replaceFirst("<__>\n<__>", Pattern.compile("<.*>"), "z")); - assertEquals("z", RegExUtils.replaceFirst("<__>\n<__>", Pattern.compile("(?s)<.*>"), "z")); - - assertEquals("ABC_bc123", RegExUtils.replaceFirst("ABCabc123", Pattern.compile("[a-z]"), "_")); - assertEquals("ABC_123abc", RegExUtils.replaceFirst("ABCabc123abc", Pattern.compile("[^A-Z0-9]+"), "_")); - assertEquals("ABC123abc", RegExUtils.replaceFirst("ABCabc123abc", Pattern.compile("[^A-Z0-9]+"), "")); - assertEquals("Lorem_ipsum dolor sit", RegExUtils.replaceFirst("Lorem ipsum dolor sit", Pattern.compile("( +)([a-z]+)"), "_$2")); - } - @Test void testReplaceFirst_StringStringString() { assertNull(RegExUtils.replaceFirst(null, "", "")); @@ -339,6 +318,27 @@ void testReplaceFirst_StringStringString() { "RegExUtils.replaceFirst expecting PatternSyntaxException"); } + @Test + void testReplaceFirstDeprecated() { + assertNull(RegExUtils.replaceFirst(null, Pattern.compile(""), "")); + + assertEquals("any", RegExUtils.replaceFirst("any", (Pattern) null, "")); + assertEquals("any", RegExUtils.replaceFirst("any", Pattern.compile(""), null)); + + assertEquals("zzz", RegExUtils.replaceFirst("", Pattern.compile(""), "zzz")); + assertEquals("zzz", RegExUtils.replaceFirst("", Pattern.compile(".*"), "zzz")); + assertEquals("", RegExUtils.replaceFirst("", Pattern.compile(".+"), "zzz")); + assertEquals("ZZabc", RegExUtils.replaceFirst("abc", Pattern.compile(""), "ZZ")); + + assertEquals("z\n<__>", RegExUtils.replaceFirst("<__>\n<__>", Pattern.compile("<.*>"), "z")); + assertEquals("z", RegExUtils.replaceFirst("<__>\n<__>", Pattern.compile("(?s)<.*>"), "z")); + + assertEquals("ABC_bc123", RegExUtils.replaceFirst("ABCabc123", Pattern.compile("[a-z]"), "_")); + assertEquals("ABC_123abc", RegExUtils.replaceFirst("ABCabc123abc", Pattern.compile("[^A-Z0-9]+"), "_")); + assertEquals("ABC123abc", RegExUtils.replaceFirst("ABCabc123abc", Pattern.compile("[^A-Z0-9]+"), "")); + assertEquals("Lorem_ipsum dolor sit", RegExUtils.replaceFirst("Lorem ipsum dolor sit", Pattern.compile("( +)([a-z]+)"), "_$2")); + } + @Test void testReplacePattern() { assertNull(RegExUtils.replacePattern((CharSequence) null, "", "")); diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java index abb9dda4e..a14da4782 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java @@ -30,54 +30,6 @@ */ class StringUtilsAbbreviateTest { - /** - * Tests <a href="LANG-1770">https://issues.apache.org/jira/projects/LANG/issues/LANG-1770</a>. - */ - @Test - void testEmoji() { - // @formatter:off - final String[] expectedResultsFox = { - "🦊...", // 4 - "🦊🦊...", - "🦊🦊🦊...", - "🦊🦊🦊🦊...", - "🦊🦊🦊🦊🦊...", - "🦊🦊🦊🦊🦊🦊...", - "🦊🦊🦊🦊🦊🦊🦊...", // 10 - }; - final String[] expectedResultsFamilyWithCodepoints = { - "👩...", - "👩🏻...", - "👩🏻...", // zero width joiner - "👩🏻👨...", - "👩🏻👨🏻...", - "👩🏻👨🏻...", - "👩🏻👨🏻👦..." - }; - final String[] expectedResultsFamilyWithGrapheme = { - "👩🏻👨🏻👦🏻👦🏻...", // 4 - "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼...", - "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽...", - "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾...", - "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾👩🏿👨🏿👦🏿👦🏿...", - "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾👩🏿👨🏿👦🏿👦🏿👩🏻👨🏻👦🏻👦🏻...", - "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾👩🏿👨🏿👦🏿👦🏿👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼..." // 10 - }; - // @formatter:on - for (int i = 4; i <= 10; i++) { - final String abbreviateResult = StringUtils.abbreviate("🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊", i); - assertNotNull(abbreviateResult); - // assertEquals(expectedResultsFox[i - 4], abbreviateResult); - } - for (int i = 4; i <= 10; i++) { - final String abbreviateResult = StringUtils.abbreviate( - "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾👩🏿👨🏿👦🏿👦🏿👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾👩🏿👨🏿👦🏿👦🏿", - i); - assertNotNull(abbreviateResult); - // assertEquals(expectedResultsFamilyWithCodepoints[i - 4], abbreviateResult); - } - } - private void assertAbbreviateWithAbbrevMarkerAndOffset(final String expected, final String abbrevMarker, final int offset, final int maxWidth) { final String abcdefghijklmno = "abcdefghijklmno"; final String message = "abbreviate(String,String,int,int) failed"; @@ -242,4 +194,52 @@ void testAbbreviateMiddle() { assertEquals("a..f", StringUtils.abbreviateMiddle("abcdef", "..", 4)); assertEquals("ab.ef", StringUtils.abbreviateMiddle("abcdef", ".", 5)); } + + /** + * Tests <a href="LANG-1770">https://issues.apache.org/jira/projects/LANG/issues/LANG-1770</a>. + */ + @Test + void testEmoji() { + // @formatter:off + final String[] expectedResultsFox = { + "🦊...", // 4 + "🦊🦊...", + "🦊🦊🦊...", + "🦊🦊🦊🦊...", + "🦊🦊🦊🦊🦊...", + "🦊🦊🦊🦊🦊🦊...", + "🦊🦊🦊🦊🦊🦊🦊...", // 10 + }; + final String[] expectedResultsFamilyWithCodepoints = { + "👩...", + "👩🏻...", + "👩🏻...", // zero width joiner + "👩🏻👨...", + "👩🏻👨🏻...", + "👩🏻👨🏻...", + "👩🏻👨🏻👦..." + }; + final String[] expectedResultsFamilyWithGrapheme = { + "👩🏻👨🏻👦🏻👦🏻...", // 4 + "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼...", + "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽...", + "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾...", + "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾👩🏿👨🏿👦🏿👦🏿...", + "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾👩🏿👨🏿👦🏿👦🏿👩🏻👨🏻👦🏻👦🏻...", + "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾👩🏿👨🏿👦🏿👦🏿👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼..." // 10 + }; + // @formatter:on + for (int i = 4; i <= 10; i++) { + final String abbreviateResult = StringUtils.abbreviate("🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊", i); + assertNotNull(abbreviateResult); + // assertEquals(expectedResultsFox[i - 4], abbreviateResult); + } + for (int i = 4; i <= 10; i++) { + final String abbreviateResult = StringUtils.abbreviate( + "👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾👩🏿👨🏿👦🏿👦🏿👩🏻👨🏻👦🏻👦🏻👩🏼👨🏼👦🏼👦🏼👩🏽👨🏽👦🏽👦🏽👩🏾👨🏾👦🏾👦🏾👩🏿👨🏿👦🏿👦🏿", + i); + assertNotNull(abbreviateResult); + // assertEquals(expectedResultsFamilyWithCodepoints[i - 4], abbreviateResult); + } + } } diff --git a/src/test/java/org/apache/commons/lang3/ValidateTest.java b/src/test/java/org/apache/commons/lang3/ValidateTest.java index abc222117..205dcea6a 100644 --- a/src/test/java/org/apache/commons/lang3/ValidateTest.java +++ b/src/test/java/org/apache/commons/lang3/ValidateTest.java @@ -727,33 +727,33 @@ void shouldThrowExceptionWithGivenMessageForFalseExpression() { } @Nested - final class WithObjectTemplate { + final class WithMessageSupplier { @Test void shouldNotThrowForTrueExpression() { - Validate.isTrue(true, "MSG", "Object 1", "Object 2"); + Validate.isTrue(true, () -> "MSG"); } @Test void shouldThrowExceptionWithDoubleInsertedIntoTemplateMessageForFalseExpression() { final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> Validate.isTrue(false, "MSG %s %s", "Object 1", "Object 2")); + () -> Validate.isTrue(false, () -> String.format("MSG %s %s", "Object 1", "Object 2"))); assertEquals("MSG Object 1 Object 2", ex.getMessage()); } } @Nested - final class WithMessageSupplier { + final class WithObjectTemplate { @Test void shouldNotThrowForTrueExpression() { - Validate.isTrue(true, () -> "MSG"); + Validate.isTrue(true, "MSG", "Object 1", "Object 2"); } @Test void shouldThrowExceptionWithDoubleInsertedIntoTemplateMessageForFalseExpression() { final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> Validate.isTrue(false, () -> String.format("MSG %s %s", "Object 1", "Object 2"))); + () -> Validate.isTrue(false, "MSG %s %s", "Object 1", "Object 2")); assertEquals("MSG Object 1 Object 2", ex.getMessage()); } } diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionDiffBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionDiffBuilderTest.java index 373fce7fb..202bb21fa 100644 --- a/src/test/java/org/apache/commons/lang3/builder/ReflectionDiffBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionDiffBuilderTest.java @@ -217,18 +217,6 @@ void testNoDifferences() { assertEquals(0, firstObject.diffDeprecated(secondObject).getNumberOfDiffs()); } - @Test - void testRetention() throws Exception { - // The following should not retain memory. - for (int i = 0; i < Integer.getInteger("testRecursive", 10_000); i++) { - final Class<?> clazz = TestClassBuilder.defineSimpleClass(getClass().getPackage().getName(), i); - final Object firstObject = clazz.newInstance(); - final Object secondObject = clazz.newInstance(); - final ReflectionDiffBuilder<Object> reflectionDiffBuilder = new ReflectionDiffBuilder<>(firstObject, secondObject, SHORT_STYLE); - assertNotNull(reflectionDiffBuilder.build()); - } - } - @Test void testNoDifferencesDiffExcludeAnnotatedField() { final TypeTestClass firstObject = new TypeTestClass(); @@ -282,6 +270,18 @@ void testPrimitiveDifference() { assertEquals(1, list.getNumberOfDiffs()); } + @Test + void testRetention() throws Exception { + // The following should not retain memory. + for (int i = 0; i < Integer.getInteger("testRecursive", 10_000); i++) { + final Class<?> clazz = TestClassBuilder.defineSimpleClass(getClass().getPackage().getName(), i); + final Object firstObject = clazz.newInstance(); + final Object secondObject = clazz.newInstance(); + final ReflectionDiffBuilder<Object> reflectionDiffBuilder = new ReflectionDiffBuilder<>(firstObject, secondObject, SHORT_STYLE); + assertNotNull(reflectionDiffBuilder.build()); + } + } + @Test void testTransientFieldDifference() { final TypeTestClass firstObject = new TypeTestClass(); diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java index f09ae4fd7..23da33965 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDateParserTest.java @@ -106,15 +106,6 @@ private enum Expected1806 { private static final Locale SWEDEN = new Locale("sv", "SE"); - @BeforeEach - @AfterEach - void clear() { - AbstractFormatCache.clear(); - FastDateFormat.clear(); - FastDateParser.clear(); - FastDatePrinter.clear(); - } - static void checkParse(final Locale locale, final Calendar cal, final SimpleDateFormat simpleDateFormat, final DateParser dateParser) { final String formattedDate = simpleDateFormat.format(cal.getTime()); @@ -162,6 +153,15 @@ private static Calendar initializeCalendar(final TimeZone timeZone) { private final TriFunction<String, TimeZone, Locale, DateParser> dateParserProvider = (format, timeZone, locale) -> new FastDateParser(format, timeZone, locale, null); + @BeforeEach + @AfterEach + void clear() { + AbstractFormatCache.clear(); + FastDateFormat.clear(); + FastDateParser.clear(); + FastDatePrinter.clear(); + } + private DateParser getDateInstance(final int dateStyle, final Locale locale) { return getInstance(null, AbstractFormatCache.getPatternForStyle(Integer.valueOf(dateStyle), null, locale), TimeZone.getDefault(), Locale.getDefault()); } diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java index 8a78de18a..47815c68a 100644 --- a/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java +++ b/src/test/java/org/apache/commons/lang3/time/FastDateParser_TimeZoneStrategyTest.java @@ -182,6 +182,11 @@ private void testTimeZoneStrategyPattern_TimeZone_getAvailableIDs(final Locale l } } + @Test + void testTimeZoneStrategyPattern_zh_HK_Hans() throws ParseException { + testTimeZoneStrategyPattern("zh_HK_#Hans", "?????????"); + } + /** * Breaks randomly on GitHub for Locale "pt_PT", TimeZone "Etc/UTC" if we do not check if the Locale's language is "undetermined". * @@ -198,11 +203,6 @@ void testTimeZoneStrategyPatternPortugal() throws ParseException { testTimeZoneStrategyPattern("pt_PT", "Horário do Meridiano de Greenwich"); } - @Test - void testTimeZoneStrategyPattern_zh_HK_Hans() throws ParseException { - testTimeZoneStrategyPattern("zh_HK_#Hans", "?????????"); - } - /** * Breaks randomly on GitHub for Locale "sr_ME_#Cyrl", TimeZone "Etc/UTC" if we do not check if the Locale's language is "undetermined". *