Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-44314][BUILD][CORE][TESTS] Add a new checkstyle rule to prohib…
…it the use of `@Test(expected = ExpectedException.class)` ### What changes were proposed in this pull request? This pr add a new java checkstyle rule ``` <module name="RegexpSinglelineJava"> <property name="format" value="Test\(expected"/> <property name="message" value="Please use the `assertThrows` method to test for exceptions." /> </module> ``` to prohibit the use of Test(expected = ExpectedException.class) ### Why are the changes needed? Refer to https://github.com/junit-team/junit4/wiki/Exception-testing Junit 4 does not recommend `Specifying the expected annotation via the Test annotation.`, ``` The expected parameter should be used with care. The above test will pass if any code in the method throws IndexOutOfBoundsException. Using the method you also cannot test the value of the message in the exception, or the state of a domain object after the exception has been thrown. For these reasons, the previous approaches are recommended. ``` And `Using assertThrows Method` is recommended. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? - Pass Github Actions - Manual checked: run `dev/lint-java` without change `RemoteBlockPushResolverSuite.java` ``` Checkstyle checks failed at following occurrences: [ERROR] src/test/java/org/apache/spark/network/shuffle/RemoteBlockPushResolverSuite.java:[284] (regexp) RegexpSinglelineJava: Please use the `assertThrows` method to test for exceptions. [ERROR] src/test/java/org/apache/spark/network/shuffle/RemoteBlockPushResolverSuite.java:[301] (regexp) RegexpSinglelineJava: Please use the `assertThrows` method to test for exceptions. ``` Closes apache#41872 from LuciferYang/SPARK-44314. Authored-by: yangjie01 <[email protected]> Signed-off-by: yangjie01 <[email protected]>
- Loading branch information