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


The following commit(s) were added to refs/heads/master by this push:
     new 089b43a  [LANG-1426] Corrected usage examples in Javadocs (#458)
089b43a is described below

commit 089b43a0a6de2d6ae49840aec3805aee2c309001
Author: Mikko Maunu <[email protected]>
AuthorDate: Wed Sep 25 16:32:10 2019 +0200

    [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
---
 src/main/java/org/apache/commons/lang3/StringUtils.java     |  8 +++++---
 src/test/java/org/apache/commons/lang3/StringUtilsTest.java | 10 +++++-----
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java 
b/src/main/java/org/apache/commons/lang3/StringUtils.java
index 03f7478..fe2d78f 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -9039,6 +9039,7 @@ public class StringUtils {
      * @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 class StringUtils {
      * 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 class StringUtils {
      * 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) {
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java 
b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
index 1967c00..9f36c6d 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
@@ -2956,15 +2956,15 @@ public class StringUtilsTest {
     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 class StringUtilsTest {
         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));

Reply via email to