Refactoring app response test with JUnit Assume #10537
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
FIX #10487
This PR proposes a minor improvement that could apply to two test cases in
AppResponseTest
(testSetExceptionWithEmptyStackTraceException
andtestAppResponseWithEmptyStackTraceException
). I will use testSetExceptionWithEmptyStackTraceException as an example.On line 68-71, it uses an if condition to check if a precondition is violated, i.e. “buildEmptyStackTraceException fail to construct NPE” If so, the test case return silently without any further execution. There could be two drawbacks to this:
The assume function, introduced after JUnit 4&5 is designed to check for test pre-condition. As mentioned in the JUnit 5's document:
Assume functions is a set of methods useful for stating assumptions about the conditions in which a test is meaningful. A failed assumption does not mean the code is broken, but that the test provides no useful information.
The if block could be replaced by After refactoring:
This makes the logic more explicit. Although this is a minor change, it can be applied to the two test cases in this
AppResponseTest
.Brief changelog
Replace
if (throwable == null) {return;}
withassumeFalse(throwable == null);
for better code comprehension.Verifying this change
Checklist