Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing and adding DateUtils exception Javadocs #871

Merged
merged 1 commit into from
Mar 27, 2022

Conversation

dvmarcilio
Copy link
Contributor

@dvmarcilio dvmarcilio commented Mar 27, 2022

Hello! This is another PR fixing inconsistent NullPointerException/IllegalArgumentException exception javadocs.
I added several new assertions on the tests when I noticed that they were missing.

While I was at it, I took the time to add some new documentation (and tests) on the range of methods such as DateUtils.setMonth(). I often misremember that months start with 0 and days start with 1.

* @throws NullPointerException if the date is null
* @throws IllegalArgumentException if {@code amount} is not in the range
*  {@code 0 <= amount <= 11}
* @since 2.4
*/
public static Date setMonths(final Date date, final int amount) {
final String outsideOfRangeAssertionMessage = "DateUtils.setMonths did not throw an expected IllegalArgumentException 
        for amount outside of range 0 to 11.";
assertThrows(
        IllegalArgumentException.class,
        () -> DateUtils.setMonths(BASE_DATE, 12),
        outsideOfRangeAssertionMessage);
assertThrows(
        IllegalArgumentException.class,
        () -> DateUtils.setMonths(BASE_DATE, -1),
        outsideOfRangeAssertionMessage);

assertThrows(NullPointerException.class, () -> DateUtils.setMonths(null, 0));

Thanks for taking the time to review this.

@garydgregory garydgregory changed the title Fixing and adding DateUtils exception javadocs Fixing and adding DateUtils exception Javadocs Mar 27, 2022
@garydgregory garydgregory merged commit 75bb103 into apache:master Mar 27, 2022
asfgit pushed a commit that referenced this pull request Mar 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants