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: [email protected] With regards, Apache Git Services
