From 999f876b9b5c3e284c3801bf8aa94161572f97a9 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 8 Dec 2025 12:07:21 +0100 Subject: [PATCH 1/6] Enable test which can be enabled now --- .../org/apache/commons/text/OssFuzzTest.java | Bin 16930 -> 16771 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/src/test/java/org/apache/commons/text/OssFuzzTest.java b/src/test/java/org/apache/commons/text/OssFuzzTest.java index 0b4e1a555ab1e9c074ea7fcebda4e188184551da..c3772e5a372d8e65be74c83afeb17071e84024fa 100644 GIT binary patch delta 30 mcmZ3~!r0u*xFMN&au@UE$p(&+n^&;-*i6=R44XW`aS{Nt5etO? delta 89 zcmZo}W?a<5xFMOD(U%%PKaJD5!lV)2@+ Date: Mon, 8 Dec 2025 14:04:39 +0100 Subject: [PATCH 2/6] Ensure test does not fail on non-US default locale --- .../commons/text/lookup/DateStringLookupTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java b/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java index cd358a34b0..b4f5bfbbcd 100644 --- a/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java +++ b/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java @@ -25,6 +25,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -42,9 +43,16 @@ void testBadFormat() { @Test void testDefault() throws ParseException { - final String formatted = DateStringLookup.INSTANCE.apply(null); - DateFormat.getInstance().parse(formatted); // throws ParseException + Locale prev = Locale.getDefault(); + try { + // ensure that date-parser uses English/American presets + Locale.setDefault(Locale.US); + final String formatted = DateStringLookup.INSTANCE.apply(null); + DateFormat.getInstance().parse(formatted); // throws ParseException + } finally { + Locale.setDefault(prev); + } } @Test From f9e51657d634a8273ee50ccd54b04c718708ef41 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 8 Dec 2025 15:23:16 +0100 Subject: [PATCH 3/6] Cover a few lines/branches Add some more tests to cover a bit more. Also apply some IDE-suggestions, assert-order, simplify assertions. --- .../commons/text/StringSubstitutorTest.java | 9 ++++- .../commons/text/TextStringBuilderTest.java | 7 ++++ .../apache/commons/text/WordUtilsTest.java | 30 ++++++++++++++++- .../text/lookup/StringLookupFactoryTest.java | 15 +++++++++ .../similarity/IntersectionResultTest.java | 11 ++++++- .../similarity/LevenshteinResultsTest.java | 17 ++++++++++ .../LongestCommonSubsequenceTest.java | 5 +++ .../translate/CharSequenceTranslatorTest.java | 18 ++++++++-- .../text/translate/OctalUnescaperTest.java | 33 +++++++++++++++++++ .../translate/SinglePassTranslatorTest.java | 14 ++++++-- .../text/translate/UnicodeUnescaperTest.java | 7 ++++ 11 files changed, 159 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java index 75f112ba6b..37ef5c23ee 100644 --- a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java +++ b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java @@ -193,7 +193,7 @@ public void setUp() throws Exception { } @AfterEach - public void tearDown() throws Exception { + public void tearDown() { values = null; } @@ -1085,4 +1085,11 @@ void testSubstitutePreserveEscape() throws IOException { assertEqualsCharSeq("value $${escaped}", replace(sub, org)); } + @Test + void testToString() { + final StringSubstitutor s = new StringSubstitutor(null, "prefix", "suffix"); + String str = s.toString(); + assertTrue(str.contains("\"prefix\""), + "Had: " + str); + } } diff --git a/src/test/java/org/apache/commons/text/TextStringBuilderTest.java b/src/test/java/org/apache/commons/text/TextStringBuilderTest.java index ff2cc7d00b..1900c19d68 100644 --- a/src/test/java/org/apache/commons/text/TextStringBuilderTest.java +++ b/src/test/java/org/apache/commons/text/TextStringBuilderTest.java @@ -550,6 +550,13 @@ void testConstructorCharSequence() { assertEquals(length, sb.toCharArray().length); } + @Test + void testConstructorCharSequenceNull() { + final TextStringBuilder sb = new TextStringBuilder((CharSequence) null); + assertEquals(TextStringBuilder.CAPACITY, sb.capacity()); + assertEquals(0, sb.toCharArray().length); + } + @Test void testConstructorDefault() { final TextStringBuilder sb = new TextStringBuilder(); diff --git a/src/test/java/org/apache/commons/text/WordUtilsTest.java b/src/test/java/org/apache/commons/text/WordUtilsTest.java index facbf31c33..73273d181f 100644 --- a/src/test/java/org/apache/commons/text/WordUtilsTest.java +++ b/src/test/java/org/apache/commons/text/WordUtilsTest.java @@ -177,14 +177,16 @@ void testConstructor() { @Test void testContainsAllWords_StringString() { - assertFalse(WordUtils.containsAllWords(null, (String) null)); + assertFalse(WordUtils.containsAllWords(null)); assertFalse(WordUtils.containsAllWords(null, "")); assertFalse(WordUtils.containsAllWords(null, "ab")); + assertFalse(WordUtils.containsAllWords("")); assertFalse(WordUtils.containsAllWords("", (String) null)); assertFalse(WordUtils.containsAllWords("", "")); assertFalse(WordUtils.containsAllWords("", "ab")); + assertFalse(WordUtils.containsAllWords("foo")); assertFalse(WordUtils.containsAllWords("foo", (String) null)); assertFalse(WordUtils.containsAllWords("bar", "")); assertFalse(WordUtils.containsAllWords("zzabyycdxx", "by")); @@ -321,6 +323,32 @@ void testInitialsSurrogatePairs() { new char[] { '\uD800', '\uDF14', '\uD800', '\uDF18' })); } + @Deprecated + @Test + void testIsDelimiter() { + assertFalse(WordUtils.isDelimiter('.', null)); + assertTrue(WordUtils.isDelimiter(' ', null)); + + assertFalse(WordUtils.isDelimiter(' ', new char[] { '.' })); + assertTrue(WordUtils.isDelimiter('.', new char[] { '.' })); + + assertFalse(WordUtils.isDelimiter(' ', new char[] { '.', '_', 'a' })); + assertTrue(WordUtils.isDelimiter('.', new char[] { '.', '_', 'a', '.' })); + } + + @Deprecated + @Test + void testIsDelimiterCodePoint() { + assertFalse(WordUtils.isDelimiter((int) '.', null)); + assertTrue(WordUtils.isDelimiter((int) ' ', null)); + + assertFalse(WordUtils.isDelimiter((int) ' ', new char[] { '.' })); + assertTrue(WordUtils.isDelimiter((int) '.', new char[] { '.' })); + + assertFalse(WordUtils.isDelimiter((int) ' ', new char[] { '.', '_', 'a' })); + assertTrue(WordUtils.isDelimiter((int) '.', new char[] { '.', '_', 'a', '.' })); + } + @Test void testLANG1292() { // Prior to fix, this was throwing StringIndexOutOfBoundsException diff --git a/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java b/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java index bdc6cac1f3..02ca994e3b 100644 --- a/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java +++ b/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java @@ -257,6 +257,16 @@ void testSingletons() { assertSame(XmlEncoderStringLookup.INSTANCE, stringLookupFactory.xmlEncoderStringLookup()); } + /** + * Tests that we return the singleton. + */ + @Deprecated + @Test + void testDeprecatedSingletons() { + final StringLookupFactory stringLookupFactory = StringLookupFactory.INSTANCE; + assertSame(StringLookupFactory.INSTANCE_BASE64_DECODER, stringLookupFactory.base64StringLookup()); + } + @Test void testXmlStringLookup() { final StringLookupFactory stringLookupFactory = StringLookupFactory.INSTANCE; @@ -279,4 +289,9 @@ void testXmlStringLookupExternalEntityOn() { assertEquals(XmlStringLookupTest.DATA, StringLookupFactory.INSTANCE.xmlStringLookup(XmlStringLookupTest.EMPTY_MAP).apply(key).trim()); } + @Test + void testClear() { + // this will clear out the global cache in ConstantStringLookup + StringLookupFactory.clear(); + } } diff --git a/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java b/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java index 5bb15d6b87..51b56db400 100644 --- a/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java +++ b/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java @@ -36,7 +36,7 @@ void testEquals() { }; // Test a different instance with same values - Assertions.assertEquals(results[0], new IntersectionResult(0, 0, 0)); + Assertions.assertEquals(new IntersectionResult(0, 0, 0), results[0]); final Object something = new Object(); for (int i = 0; i < results.length; i++) { @@ -45,6 +45,15 @@ void testEquals() { for (int j = 0; j < results.length; j++) { Assertions.assertEquals(results[i].equals(results[j]), i == j); } + + // IntelliJ would like to optimize this, but it would make + // the test useless as assertNotEquals() handles null itself + //noinspection ConstantValue,SimplifiableAssertion + Assertions.assertFalse(results[i].equals(null), + "Should not be Equal to null"); + //noinspection AssertBetweenInconvertibleTypes + Assertions.assertNotEquals("Test", results[i], + "Should not be Equal to a different type of object"); } } diff --git a/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java b/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java index af8f5d92ba..7d61f21e6e 100644 --- a/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java +++ b/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java @@ -40,6 +40,15 @@ void testEqualsReturningFalse() { assertFalse(levenshteinResults.equals(levenshteinResultsTwo)); } + @Test + void testEqualsDifferentDistance() { + final Integer integerOne = 1662; + final Integer integerTwo = 1164; + final LevenshteinResults levenshteinResults = new LevenshteinResults(integerOne, integerOne, integerOne, integerOne); + final LevenshteinResults levenshteinResultsTwo = new LevenshteinResults(integerTwo, integerOne, integerOne, integerOne); + assertFalse(levenshteinResults.equals(levenshteinResultsTwo)); + } + @Test void testEqualsSameObject() { final Integer integer = 1662; @@ -62,4 +71,12 @@ void testEqualsWithNull() { assertFalse(levenshteinResults.equals(null)); } + @Test + void testEqualsWithDifferentObject() { + final Integer integer = -647; + final LevenshteinResults levenshteinResults = new LevenshteinResults(integer, null, null, integer); + //noinspection EqualsBetweenInconvertibleTypes + assertFalse(levenshteinResults.equals("Test")); + } + } diff --git a/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java b/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java index 2ca0a4b994..4be91d47fc 100644 --- a/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java @@ -89,6 +89,8 @@ void testLogestCommonSubsequence() { assertEquals("", subject.logestCommonSubsequence("", "")); assertEquals("", subject.logestCommonSubsequence("left", "")); assertEquals("", subject.logestCommonSubsequence("", "right")); + assertEquals("", subject.logestCommonSubsequence("l", "a")); + assertEquals("", subject.logestCommonSubsequence("left", "a")); assertEquals("fog", subject.logestCommonSubsequence("frog", "fog")); assertEquals("", subject.logestCommonSubsequence("fly", "ant")); assertEquals("h", subject.logestCommonSubsequence("elephant", "hippo")); @@ -106,6 +108,8 @@ void testLongestCommonSubsequence() { assertEquals("", subject.longestCommonSubsequence("", "")); assertEquals("", subject.longestCommonSubsequence("left", "")); assertEquals("", subject.longestCommonSubsequence("", "right")); + assertEquals("", subject.longestCommonSubsequence("l", "a")); + assertEquals("", subject.longestCommonSubsequence("left", "a")); assertEquals("fog", subject.longestCommonSubsequence("frog", "fog")); assertEquals("", subject.longestCommonSubsequence("fly", "ant")); assertEquals("h", subject.longestCommonSubsequence("elephant", "hippo")); @@ -136,6 +140,7 @@ void testLongestCommonSubsequenceApply() { } @Test + @Deprecated void testLongestCommonSubstringLengthArray() { assertArrayEquals(new int[][]{ {0, 0, 0, 0}, {0, 1, 1, 1}, {0, 1, 2, 2}}, subject.longestCommonSubstringLengthArray("ab", "abc")); } diff --git a/src/test/java/org/apache/commons/text/translate/CharSequenceTranslatorTest.java b/src/test/java/org/apache/commons/text/translate/CharSequenceTranslatorTest.java index 7585f71df1..3bb3328377 100644 --- a/src/test/java/org/apache/commons/text/translate/CharSequenceTranslatorTest.java +++ b/src/test/java/org/apache/commons/text/translate/CharSequenceTranslatorTest.java @@ -17,9 +17,11 @@ package org.apache.commons.text.translate; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; +import java.io.UncheckedIOException; import java.io.Writer; import org.junit.jupiter.api.Test; @@ -46,8 +48,20 @@ void testWith() throws IOException { final CharSequenceTranslator charSequenceTranslatorThree = new TestCharSequenceTranslator(); final CharSequenceTranslator aggregatedTranslator = charSequenceTranslatorOne.with(charSequenceTranslatorTwo, charSequenceTranslatorThree); aggregatedTranslator.translate("", 0, null); - assertTrue(aggregatedTranslator instanceof AggregateTranslator); + assertInstanceOf(AggregateTranslator.class, aggregatedTranslator); assertEquals(3, translateInvocationCounter); } + @Test + void testIOException() { + final CharSequenceTranslator translator = new CharSequenceTranslator() { + @Override + public int translate(CharSequence input, int index, Writer writer) throws IOException { + throw new IOException("Test exception"); + } + }; + + assertThrows(UncheckedIOException.class, + () -> translator.translate(".")); + } } diff --git a/src/test/java/org/apache/commons/text/translate/OctalUnescaperTest.java b/src/test/java/org/apache/commons/text/translate/OctalUnescaperTest.java index e9b78b44b7..625ae0a2bd 100644 --- a/src/test/java/org/apache/commons/text/translate/OctalUnescaperTest.java +++ b/src/test/java/org/apache/commons/text/translate/OctalUnescaperTest.java @@ -38,6 +38,10 @@ void testBetween() { result = oue.translate(input); assertEquals("\377", result, "Failed to unescape octal characters via the between method"); + input = "\\777"; + result = oue.translate(input); + assertEquals("\777", result, "Failed to unescape octal characters via the between method"); + input = "\\377 and"; result = oue.translate(input); assertEquals("\377 and", result, "Failed to unescape octal characters via the between method"); @@ -79,4 +83,33 @@ void testBetween() { assertEquals("\\999", result, "Failed to ignore an out of range octal character via the between method"); } + @Test + void testInvalid() { + final OctalUnescaper oue = new OctalUnescaper(); + + String input = "\\4a"; + String result = oue.translate(input); + assertEquals("\4a", result, "Failed to unescape octal characters via the between method"); + } + + @Test + void testHighLowSurrogate() { + final OctalUnescaper oue = new OctalUnescaper(); + + String input = "\\377\uD800and"; + String result = oue.translate(input); + assertEquals("\377\uD800and", result, "Failed to unescape octal characters via the between method"); + + input = "\\377\uD83D\uDE80and"; + result = oue.translate(input); + assertEquals("\377\uD83D\uDE80and", result, "Failed to unescape octal characters via the between method"); + + input = "\\377\uD83D\uDC00and"; + result = oue.translate(input); + assertEquals("\377\uD83D\uDC00and", result, "Failed to unescape octal characters via the between method"); + + input = "\\377\uD83D"; + result = oue.translate(input); + assertEquals("\377\uD83D", result, "Failed to unescape octal characters via the between method"); + } } diff --git a/src/test/java/org/apache/commons/text/translate/SinglePassTranslatorTest.java b/src/test/java/org/apache/commons/text/translate/SinglePassTranslatorTest.java index 37e6fdebd0..12ade3f325 100644 --- a/src/test/java/org/apache/commons/text/translate/SinglePassTranslatorTest.java +++ b/src/test/java/org/apache/commons/text/translate/SinglePassTranslatorTest.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.io.IOException; import java.io.StringWriter; import java.io.Writer; @@ -34,7 +33,7 @@ class SinglePassTranslatorTest { private final SinglePassTranslator dummyTranslator = new SinglePassTranslator() { @Override - void translateWhole(final CharSequence input, final Writer writer) throws IOException { + void translateWhole(final CharSequence input, final Writer writer) { // noop } }; @@ -63,4 +62,15 @@ void testTranslateThrowsIllegalArgumentException() { assertThrows(IllegalArgumentException.class, () -> dummyTranslator.translate("(,Fk", 647, null)); } + @Test + void testTranslateThrowsIllegalArgumentExceptionWithNonAnonymousClass() { + assertThrows(IllegalArgumentException.class, () -> new TestTranslator().translate("(,Fk", 647, null)); + } + + private static final class TestTranslator extends SinglePassTranslator { + @Override + void translateWhole(final CharSequence input, final Writer writer) { + // noop + } + } } diff --git a/src/test/java/org/apache/commons/text/translate/UnicodeUnescaperTest.java b/src/test/java/org/apache/commons/text/translate/UnicodeUnescaperTest.java index cd106c66c4..911d0f9f27 100644 --- a/src/test/java/org/apache/commons/text/translate/UnicodeUnescaperTest.java +++ b/src/test/java/org/apache/commons/text/translate/UnicodeUnescaperTest.java @@ -49,4 +49,11 @@ void testUuuuu() { final String result = escaper.translate(input); assertEquals("G", result, "Failed to unescape Unicode characters with many 'u' characters"); } + + @Test + void testTooShort() { + final UnicodeUnescaper escaper = new UnicodeUnescaper(); + final String input = "\\u"; + assertThrows(IllegalArgumentException.class, () -> escaper.translate(input)); + } } From 357cc74b1b8a3dc43ee96fd8fb59358a89fb0b68 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Fri, 12 Dec 2025 08:16:22 +0100 Subject: [PATCH 4/6] Adjust based on review comments Remove added @Deprecated Remove comments which silence warnings in IDEs Inline local variables --- .../java/org/apache/commons/text/StringSubstitutorTest.java | 3 +-- src/test/java/org/apache/commons/text/WordUtilsTest.java | 2 -- .../apache/commons/text/lookup/StringLookupFactoryTest.java | 4 +--- .../commons/text/similarity/IntersectionResultTest.java | 4 ---- .../commons/text/similarity/LevenshteinResultsTest.java | 1 - .../commons/text/similarity/LongestCommonSubsequenceTest.java | 1 - .../apache/commons/text/translate/UnicodeUnescaperTest.java | 4 +--- 7 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java index 37ef5c23ee..4022fc3da1 100644 --- a/src/test/java/org/apache/commons/text/StringSubstitutorTest.java +++ b/src/test/java/org/apache/commons/text/StringSubstitutorTest.java @@ -1089,7 +1089,6 @@ void testSubstitutePreserveEscape() throws IOException { void testToString() { final StringSubstitutor s = new StringSubstitutor(null, "prefix", "suffix"); String str = s.toString(); - assertTrue(str.contains("\"prefix\""), - "Had: " + str); + assertTrue(str.contains("\"prefix\""), "Had: " + str); } } diff --git a/src/test/java/org/apache/commons/text/WordUtilsTest.java b/src/test/java/org/apache/commons/text/WordUtilsTest.java index 73273d181f..5ae96de47a 100644 --- a/src/test/java/org/apache/commons/text/WordUtilsTest.java +++ b/src/test/java/org/apache/commons/text/WordUtilsTest.java @@ -323,7 +323,6 @@ void testInitialsSurrogatePairs() { new char[] { '\uD800', '\uDF14', '\uD800', '\uDF18' })); } - @Deprecated @Test void testIsDelimiter() { assertFalse(WordUtils.isDelimiter('.', null)); @@ -336,7 +335,6 @@ void testIsDelimiter() { assertTrue(WordUtils.isDelimiter('.', new char[] { '.', '_', 'a', '.' })); } - @Deprecated @Test void testIsDelimiterCodePoint() { assertFalse(WordUtils.isDelimiter((int) '.', null)); diff --git a/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java b/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java index 02ca994e3b..43e6f237f1 100644 --- a/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java +++ b/src/test/java/org/apache/commons/text/lookup/StringLookupFactoryTest.java @@ -260,11 +260,9 @@ void testSingletons() { /** * Tests that we return the singleton. */ - @Deprecated @Test void testDeprecatedSingletons() { - final StringLookupFactory stringLookupFactory = StringLookupFactory.INSTANCE; - assertSame(StringLookupFactory.INSTANCE_BASE64_DECODER, stringLookupFactory.base64StringLookup()); + assertSame(StringLookupFactory.INSTANCE_BASE64_DECODER, StringLookupFactory.INSTANCE.base64StringLookup()); } @Test diff --git a/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java b/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java index 51b56db400..d5b3e3eafa 100644 --- a/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java +++ b/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java @@ -46,12 +46,8 @@ void testEquals() { Assertions.assertEquals(results[i].equals(results[j]), i == j); } - // IntelliJ would like to optimize this, but it would make - // the test useless as assertNotEquals() handles null itself - //noinspection ConstantValue,SimplifiableAssertion Assertions.assertFalse(results[i].equals(null), "Should not be Equal to null"); - //noinspection AssertBetweenInconvertibleTypes Assertions.assertNotEquals("Test", results[i], "Should not be Equal to a different type of object"); } diff --git a/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java b/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java index 7d61f21e6e..ac93db0605 100644 --- a/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java +++ b/src/test/java/org/apache/commons/text/similarity/LevenshteinResultsTest.java @@ -75,7 +75,6 @@ void testEqualsWithNull() { void testEqualsWithDifferentObject() { final Integer integer = -647; final LevenshteinResults levenshteinResults = new LevenshteinResults(integer, null, null, integer); - //noinspection EqualsBetweenInconvertibleTypes assertFalse(levenshteinResults.equals("Test")); } diff --git a/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java b/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java index 4be91d47fc..8063c911e7 100644 --- a/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java +++ b/src/test/java/org/apache/commons/text/similarity/LongestCommonSubsequenceTest.java @@ -140,7 +140,6 @@ void testLongestCommonSubsequenceApply() { } @Test - @Deprecated void testLongestCommonSubstringLengthArray() { assertArrayEquals(new int[][]{ {0, 0, 0, 0}, {0, 1, 1, 1}, {0, 1, 2, 2}}, subject.longestCommonSubstringLengthArray("ab", "abc")); } diff --git a/src/test/java/org/apache/commons/text/translate/UnicodeUnescaperTest.java b/src/test/java/org/apache/commons/text/translate/UnicodeUnescaperTest.java index 911d0f9f27..f20d710678 100644 --- a/src/test/java/org/apache/commons/text/translate/UnicodeUnescaperTest.java +++ b/src/test/java/org/apache/commons/text/translate/UnicodeUnescaperTest.java @@ -52,8 +52,6 @@ void testUuuuu() { @Test void testTooShort() { - final UnicodeUnescaper escaper = new UnicodeUnescaper(); - final String input = "\\u"; - assertThrows(IllegalArgumentException.class, () -> escaper.translate(input)); + assertThrows(IllegalArgumentException.class, () -> new UnicodeUnescaper().translate("\\u")); } } From e3bdad21ee8b6e5f57463eacb128169ac057efff Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Fri, 12 Dec 2025 08:16:29 +0100 Subject: [PATCH 5/6] Revert "Ensure test does not fail on non-US default locale" This reverts commit 5a6af9ed28cc7523044150a5b57b109fbfc28cd8. --- .../commons/text/lookup/DateStringLookupTest.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java b/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java index b4f5bfbbcd..cd358a34b0 100644 --- a/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java +++ b/src/test/java/org/apache/commons/text/lookup/DateStringLookupTest.java @@ -25,7 +25,6 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.Locale; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -43,16 +42,9 @@ void testBadFormat() { @Test void testDefault() throws ParseException { - Locale prev = Locale.getDefault(); - try { - // ensure that date-parser uses English/American presets - Locale.setDefault(Locale.US); + final String formatted = DateStringLookup.INSTANCE.apply(null); + DateFormat.getInstance().parse(formatted); // throws ParseException - final String formatted = DateStringLookup.INSTANCE.apply(null); - DateFormat.getInstance().parse(formatted); // throws ParseException - } finally { - Locale.setDefault(prev); - } } @Test From ca2ea27dbb7cc932db4afa825590c690f18aad03 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Fri, 12 Dec 2025 08:43:33 +0100 Subject: [PATCH 6/6] Some more minor adjustments of added tests based on code review --- .../commons/text/similarity/IntersectionResultTest.java | 6 ++---- .../apache/commons/text/translate/OctalUnescaperTest.java | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java b/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java index d5b3e3eafa..70230b86cb 100644 --- a/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java +++ b/src/test/java/org/apache/commons/text/similarity/IntersectionResultTest.java @@ -46,10 +46,8 @@ void testEquals() { Assertions.assertEquals(results[i].equals(results[j]), i == j); } - Assertions.assertFalse(results[i].equals(null), - "Should not be Equal to null"); - Assertions.assertNotEquals("Test", results[i], - "Should not be Equal to a different type of object"); + Assertions.assertFalse(results[i].equals(null), "Should not be Equal to null"); + Assertions.assertNotEquals("Test", results[i], "Should not be Equal to a different type of object"); } } diff --git a/src/test/java/org/apache/commons/text/translate/OctalUnescaperTest.java b/src/test/java/org/apache/commons/text/translate/OctalUnescaperTest.java index 625ae0a2bd..1f7d4b7be3 100644 --- a/src/test/java/org/apache/commons/text/translate/OctalUnescaperTest.java +++ b/src/test/java/org/apache/commons/text/translate/OctalUnescaperTest.java @@ -86,16 +86,14 @@ void testBetween() { @Test void testInvalid() { final OctalUnescaper oue = new OctalUnescaper(); - - String input = "\\4a"; - String result = oue.translate(input); + final String input = "\\4a"; + final String result = oue.translate(input); assertEquals("\4a", result, "Failed to unescape octal characters via the between method"); } @Test void testHighLowSurrogate() { final OctalUnescaper oue = new OctalUnescaper(); - String input = "\\377\uD800and"; String result = oue.translate(input); assertEquals("\377\uD800and", result, "Failed to unescape octal characters via the between method");