mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-10 12:05:06 +00:00
[LANG-1426] Corrected usage examples in Javadocs (#458)
* [LANG-1426] Corrected usage examples in Javadocs * [LANG-1426] Added @throws Javadoc, corrected verb from check to truncate and consistently mimicking exception message in assertion message
This commit is contained in:
parent
46b381eb4b
commit
089b43a0a6
@ -9039,6 +9039,7 @@ public static String trimToNull(final String str) {
|
||||
* @param str the String to truncate, may be null
|
||||
* @param maxWidth maximum length of result String, must be positive
|
||||
* @return truncated String, {@code null} if null String input
|
||||
* @throws IllegalArgumentException If {@code maxWidth} is less than {@code 0}
|
||||
* @since 3.5
|
||||
*/
|
||||
public static String truncate(final String str, final int maxWidth) {
|
||||
@ -9075,8 +9076,8 @@ public static String truncate(final String str, final int maxWidth) {
|
||||
* StringUtils.truncate("raspberry peach", 10, 15) = "peach"
|
||||
* StringUtils.truncate("abcdefghijklmno", 0, 10) = "abcdefghij"
|
||||
* StringUtils.truncate("abcdefghijklmno", -1, 10) = throws an IllegalArgumentException
|
||||
* StringUtils.truncate("abcdefghijklmno", Integer.MIN_VALUE, 10) = "abcdefghij"
|
||||
* StringUtils.truncate("abcdefghijklmno", Integer.MIN_VALUE, Integer.MAX_VALUE) = "abcdefghijklmno"
|
||||
* StringUtils.truncate("abcdefghijklmno", Integer.MIN_VALUE, 10) = throws an IllegalArgumentException
|
||||
* StringUtils.truncate("abcdefghijklmno", Integer.MIN_VALUE, Integer.MAX_VALUE) = throws an IllegalArgumentException
|
||||
* StringUtils.truncate("abcdefghijklmno", 0, Integer.MAX_VALUE) = "abcdefghijklmno"
|
||||
* StringUtils.truncate("abcdefghijklmno", 1, 10) = "bcdefghijk"
|
||||
* StringUtils.truncate("abcdefghijklmno", 2, 10) = "cdefghijkl"
|
||||
@ -9098,10 +9099,11 @@ public static String truncate(final String str, final int maxWidth) {
|
||||
* StringUtils.truncate("abcdefghij", -2, 4) = throws an IllegalArgumentException
|
||||
* </pre>
|
||||
*
|
||||
* @param str the String to check, may be null
|
||||
* @param str the String to truncate, may be null
|
||||
* @param offset left edge of source String
|
||||
* @param maxWidth maximum length of result String, must be positive
|
||||
* @return truncated String, {@code null} if null String input
|
||||
* @throws IllegalArgumentException If {@code offset} or {@code maxWidth} is less than {@code 0}
|
||||
* @since 3.5
|
||||
*/
|
||||
public static String truncate(final String str, final int offset, final int maxWidth) {
|
||||
|
@ -2956,15 +2956,15 @@ public void testTruncate_StringInt() {
|
||||
public void testTruncate_StringIntInt() {
|
||||
assertNull(StringUtils.truncate(null, 0, 12));
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> StringUtils.truncate(null, -1, 0), "maxWith cannot be negative");
|
||||
IllegalArgumentException.class, () -> StringUtils.truncate(null, -1, 0), "offset cannot be negative");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> StringUtils.truncate(null, -10, -4),
|
||||
"maxWith cannot be negative");
|
||||
"offset cannot be negative");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> StringUtils.truncate(null, Integer.MIN_VALUE, Integer.MIN_VALUE),
|
||||
"maxWith cannot be negative");
|
||||
"offset cannot be negative");
|
||||
assertNull(StringUtils.truncate(null, 10, 12));
|
||||
assertEquals("", StringUtils.truncate("", 0, 10));
|
||||
assertEquals("", StringUtils.truncate("", 2, 10));
|
||||
@ -3018,11 +3018,11 @@ public void testTruncate_StringIntInt() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> StringUtils.truncate("abcdefghij", -100, -100),
|
||||
"offset cannot be negative");
|
||||
"offset cannot be negative");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> StringUtils.truncate("abcdefghij", Integer.MIN_VALUE, Integer.MIN_VALUE),
|
||||
"offset cannot be negative");
|
||||
"offset cannot be negative");
|
||||
final String raspberry = "raspberry peach";
|
||||
assertEquals("peach", StringUtils.truncate(raspberry, 10, 15));
|
||||
assertEquals("abcdefghij", StringUtils.truncate("abcdefghijklmno", 0, 10));
|
||||
|
Loading…
x
Reference in New Issue
Block a user