[JENKINS-73690] Avoid null Enum to throw an exception#577
[JENKINS-73690] Avoid null Enum to throw an exception#577Wadeck wants to merge 2 commits intojenkinsci:masterfrom
Conversation
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)) |
There was a problem hiding this comment.
Can you use assertThrows for cleaner and less code in both these tests?
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
Imo you don't need to add harder to read code because existing code is hard to read.
There was a problem hiding this comment.
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.
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