Skip to content

Commit aa7ce20

Browse files
committed
[TEXT-239] TextStringBuilder.append(char[], int, int) uses wrong
variable in exception message #735 Use longer lines Keep test methods in AB order
1 parent a3e4306 commit aa7ce20

3 files changed

Lines changed: 21 additions & 36 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
4646
<release version="1.15.1" date="YYYY-MM-DD" description="This is a feature and maintenance release. Java 8 or later is required.">
4747
<!-- FIX -->
4848
<action type="fix" dev="ggregory" due-to="Dominik Stadler, Gary Gregory">Improve test coverage #732.</action>
49+
<action type="fix" dev="ggregory" issue="TEXT-239" due-to="Dominik Stadler, Gary Gregory">TextStringBuilder.append(char[], int, int) uses wrong variable in exception message #735.</action>
4950
<!-- ADD -->
5051
<!-- UPDATE -->
5152
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 93 to 96.</action>

src/test/java/org/apache/commons/text/StrBuilderTest.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,16 @@ void testEqualsIgnoreCase() {
834834
assertTrue(sb1.equalsIgnoreCase(sb2));
835835
}
836836

837+
@Test
838+
void testErrorMessageShowsCorrectVariable() {
839+
final StrBuilder sb = new StrBuilder("Hello");
840+
final char[] chars = { 'a', 'b', 'c' };
841+
StringIndexOutOfBoundsException ex = assertThrows(StringIndexOutOfBoundsException.class, () -> sb.append(chars, 1, 4));
842+
assertTrue(ex.getMessage().contains("length: 4"));
843+
ex = assertThrows(StringIndexOutOfBoundsException.class, () -> sb.append(chars, 7, 3));
844+
assertTrue(ex.getMessage().contains("startIndex: 7"));
845+
}
846+
837847
@Test
838848
void testGetChars() {
839849
final StrBuilder sb = new StrBuilder();
@@ -2016,22 +2026,4 @@ void testTrim() {
20162026
sb.clear().append("a b c");
20172027
assertEquals("a b c", sb.trim().toString());
20182028
}
2019-
2020-
@Test
2021-
void testErrorMessageShowsCorrectVariable() {
2022-
final StrBuilder sb = new StrBuilder("Hello");
2023-
final char[] chars = {'a', 'b', 'c'};
2024-
2025-
StringIndexOutOfBoundsException ex = assertThrows(
2026-
StringIndexOutOfBoundsException.class,
2027-
() -> sb.append(chars, 1, 4)
2028-
);
2029-
assertTrue(ex.getMessage().contains("length: 4"));
2030-
2031-
ex = assertThrows(
2032-
StringIndexOutOfBoundsException.class,
2033-
() -> sb.append(chars, 7, 3)
2034-
);
2035-
assertTrue(ex.getMessage().contains("startIndex: 7"));
2036-
}
20372029
}

src/test/java/org/apache/commons/text/TextStringBuilderTest.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,16 @@ void testEqualsIgnoreCase() {
989989
// TextStringBuilder("title".toUpperCase(turkish))));
990990
}
991991

992+
@Test
993+
void testErrorMessageShowsCorrectVariable() {
994+
final TextStringBuilder sb = new TextStringBuilder("Hello");
995+
final char[] chars = { 'a', 'b', 'c' };
996+
StringIndexOutOfBoundsException ex = assertThrows(StringIndexOutOfBoundsException.class, () -> sb.append(chars, 1, 4));
997+
assertTrue(ex.getMessage().contains("length: 4"));
998+
ex = assertThrows(StringIndexOutOfBoundsException.class, () -> sb.append(chars, 7, 3));
999+
assertTrue(ex.getMessage().contains("startIndex: 7"));
1000+
}
1001+
9921002
@Test
9931003
void testGetChars() {
9941004
final TextStringBuilder sb = new TextStringBuilder();
@@ -2392,22 +2402,4 @@ void testWrap_CharArray_Int_Exceptions() {
23922402
assertThrows(IllegalArgumentException.class, () -> TextStringBuilder.wrap("abc".toCharArray(), -1));
23932403
assertThrows(IllegalArgumentException.class, () -> TextStringBuilder.wrap(ArrayUtils.EMPTY_CHAR_ARRAY, 1));
23942404
}
2395-
2396-
@Test
2397-
void testErrorMessageShowsCorrectVariable() {
2398-
final TextStringBuilder sb = new TextStringBuilder("Hello");
2399-
final char[] chars = {'a', 'b', 'c'};
2400-
2401-
StringIndexOutOfBoundsException ex = assertThrows(
2402-
StringIndexOutOfBoundsException.class,
2403-
() -> sb.append(chars, 1, 4)
2404-
);
2405-
assertTrue(ex.getMessage().contains("length: 4"));
2406-
2407-
ex = assertThrows(
2408-
StringIndexOutOfBoundsException.class,
2409-
() -> sb.append(chars, 7, 3)
2410-
);
2411-
assertTrue(ex.getMessage().contains("startIndex: 7"));
2412-
}
24132405
}

0 commit comments

Comments
 (0)