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

[JENKINS-73690] Avoid null Enum to throw an exception #577

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Wadeck
Copy link
Contributor

@Wadeck Wadeck commented Aug 27, 2024

JENKINS-73690
#578

It's expected to be supported as there is an option to make the QueryParameter required. Positive test cases added as well.

Testing done

Tested using (new) unit tests, no manual tests outside that.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • [n/a] Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

It's expected to be supported as there is an option to make the QueryParameter required.
Positive test cases added as well.
mr.getParameterMap().put("status", null);
RequestImpl req = new RequestImpl(new Stapler(), mr, Collections.emptyList(), null);
try {
new Function.InstanceFunction(getClass().getMethod("doRequireEnum", StaplerRequest.class, Status.class))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use assertThrows for cleaner and less code in both these tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the pattern used in that class file, for the testMismatchingTypes test case.

I usually prefer consistent style. Only occurrence of assertThrows is in Stapler2Test, compared to ~20 other occurrences of try/catch.

In a new project or if I was refactoring, yes I would have used assertThrows :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo you don't need to add harder to read code because existing code is hard to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depend on the perspective. If you look only at the diff, yes I agree, but if you look at the whole file, having different style make it harder. I expect to have more people reading the whole file compared to people reading only this PR/delta.

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.

5 participants