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

All KiwiPreconditions methods should accept the same message template placeholders #984

Closed
12 tasks done
sleberknight opened this issue May 20, 2023 · 0 comments · Fixed by #1003
Closed
12 tasks done
Assignees
Labels
enhancement A request for change or improvement to an existing feature
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented May 20, 2023

The following methods in KiwiPreconditions only accept %s as the placeholder in error message templates:

  • checkPositive(int value, String errorMessageTemplate, Object... errorMessageArgs)
  • checkPositive(long value, String errorMessageTemplate, Object... errorMessageArgs)
  • checkPositiveOrZero(int value, String errorMessageTemplate, Object... errorMessageArgs)
  • checkPositiveOrZero(long value, String errorMessageTemplate, Object... errorMessageArgs)
  • requirePositive(int value, String errorMessageTemplate, Object... errorMessageArgs)
  • requirePositive(long value, String errorMessageTemplate, Object... errorMessageArgs)
  • requirePositiveOrZero(int value, String errorMessageTemplate, Object... errorMessageArgs)
  • requirePositiveOrZero(long value, String errorMessageTemplate, Object... errorMessageArgs)
  • checkValidPort(int port, String errorMessageTemplate, Object... errorMessageArgs)
  • requireValidPort(int port, String errorMessageTemplate, Object... errorMessageArgs)
  • checkValidNonZeroPort(int port, String errorMessageTemplate, Object... errorMessageArgs)
  • requireValidNonZeroPort(int port, String errorMessageTemplate, Object... errorMessageArgs)

The reason is that they directly use Guava's Preconditions which accepts only %s placeholders.

Other methods in KiwiPreconditions use KiwiStrings#format under the covers and therefore accept either %s or {} as placeholders (since that is how KiwiStrings#format behaves).

We should change the above methods to work like the ones that accept either placeholder, and document the behavior as the other methods do already, e.g. they say the template behaves according to how KiwiStrings#format(String, Object...) handles placeholders.

This isn't really a 🐞 ; it's more of an omission, which also isn't documented, so I've labeled it as an enhancement instead.

All tests of methods that use a message template should verify that both placeholders work.

@sleberknight sleberknight added the enhancement A request for change or improvement to an existing feature label May 20, 2023
@sleberknight sleberknight self-assigned this May 20, 2023
@sleberknight sleberknight added this to the 2.7.0 milestone May 30, 2023
@sleberknight sleberknight modified the milestone: 2.7.0 Aug 5, 2023
sleberknight added a commit that referenced this issue Aug 5, 2023
All KiwiPreconditions methods should accept the same message template
placeholders as the other methods in the class, as specified by the
KiwiStrings#format method.

Closes #984
sleberknight added a commit that referenced this issue Aug 5, 2023
…ers (#1003)

All KiwiPreconditions methods should accept the same message template
placeholders as the other methods in the class, as specified by the
KiwiStrings#format method.

Closes #984
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A request for change or improvement to an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant