[ 
https://issues.apache.org/jira/browse/LANG-1426?focusedWorklogId=312694&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-312694
 ]

ASF GitHub Bot logged work on LANG-1426:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 15/Sep/19 17:45
            Start Date: 15/Sep/19 17:45
    Worklog Time Spent: 10m 
      Work Description: mikkomaunu commented on issue #458: [LANG-1426] 
Corrected usage examples in Javadocs
URL: https://github.com/apache/commons-lang/pull/458#issuecomment-531585133
 
 
   Related theme, should one also fix tests that assert exceptions? Currently 
message does not describe too well why test failed, instead it often simply 
repeats Exception message. Also that does not alway match.
   
   For example. Following assertion uses "maxWith cannot be negative" as 
message. That does not describe why test failed. Also, because first argument 
is validated first, actual message in exception is "offset cannot be negative" 
   ```
   
   assertThrows(
                   IllegalArgumentException.class,
                   () -> StringUtils.truncate(null, Integer.MIN_VALUE, 
Integer.MIN_VALUE),
                   "maxWith cannot be negative");
   ```
   
   I see two approaches to fix this:
   1) improve message (less code, changing order of parameter validation does 
not affect tests):
   ```
           assertThrows(
                   IllegalArgumentException.class,
                   () -> StringUtils.truncate(null, Integer.MIN_VALUE, 
Integer.MIN_VALUE),
                   "Expected IllegalArgumentException when both offset and and 
maxWidth are negative");
   ```
   
   2) improve message and assert also Exception message (significantly more 
code, does not play well when code does have bunch of unrelated assertions in 
one test method):
   
   ```
           final IllegalArgumentException 
exceptionWhenOffsetAndMaxWidthAreNegative = assertThrows(
                   IllegalArgumentException.class,
                   () -> StringUtils.truncate(null, Integer.MIN_VALUE, 
Integer.MIN_VALUE),
                   "Expected IllegalArgumentException when both offset and and 
maxWidth are negative");
           assertEquals("offset cannot be negative", 
exceptionWhenOffsetAndMaxWidthAreNegative.getMessage(), "Wrong Exception 
message");
   ```
   
   When exception is thrown because maxWidth is negative, then there is 
misspelling: "maxWith cannot be negative";
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 312694)
    Time Spent: 50m  (was: 40m)

> JavaDoc issue on StringUtils.truncate
> -------------------------------------
>
>                 Key: LANG-1426
>                 URL: https://issues.apache.org/jira/browse/LANG-1426
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Jeff
>            Priority: Trivial
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Two of the examples on the method StringUtils.truncate(String, int, int) are 
> incorrect:
>  * StringUtils.truncate("abcdefghijklmno", Integer.MIN_VALUE, 10) = 
> "abcdefghij"
>  * StringUtils.truncate("abcdefghijklmno", Integer.MIN_VALUE, 
> Integer.MAX_VALUE) = "abcdefghijklmno"
> Both of the above actually throw IllegalArgumentException's.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)

Reply via email to