Replace JUnit ExpectedException with assertThrows and More

jSparrow 3.24.0 & jSparrow Maven Plugin 3.1.0

Winter Solstice Release

Three new refactoring rules

The winter solstice jSparrow release adds new refactoring rules and opens a new chapter in refactoring towards JUnit 5:

Replace JUnit ExpectedException with assertThrows

In JUnit 4.13, the ExpectedException.none() rule is deprecated. The recommended alternative is to use assertThrows(). This new jSparrow rule performs such a transformation automatically.

is transformed to:

Replace JUnit Expected Annotation Property with assertThrows

Using the expected annotation property for testing the thrown exceptions is rather misleading. Often it becomes unclear which part of the test code is responsible for throwing the exception. This rule aims to overcome this problem by replacing the expected annotation property with assertThrows.

is transformed to:

Use Files.writeString

Java 11 introduced Files.writeString(Path, CharSequence, Charset, OpenOption…) for writing small text files in an efficient manner. This rule replaces BufferedWriters that are used to write a single value into a file, with Files.write(…).

is transformed to:

jSparrow provides now a total of 90 automatic refactoring rules.

Find out more information in the Release Notes for jSparrow Eclipse and jSparrow Maven!

“First do it, then do it right, then do it better.” ― Addy Osmani

Happy Coding!