Checkinging many XML strings, I use the ErrorCollector construction frequently. But still I do not understand how it works.
When I am declaring an ErrorCollector, I have to assign it at once:
@Rule
public ErrorCollector collector= new ErrorCollector();
If I want to refresh the collector before every test, I am putting an assignment
collector= new ErrorCollector();
in the @Before method. But thus the first assignment at the declaration is excessive. But I can't remove it.
What is the sense of this must-to-be-assignment? And how it works? I thought, that @Rule is about the declaration only?
@Matthew Farwell at What is the logic of @Rule(JUnit) declaration and assignment in a Groovy class says "In Java, the JUnit runner checks that the @Rule annotation is applied to a public non-static field or public non-static method which returns either a TestRule or MethodRule." But what is checked here is not the declaration, but the assignment and it is something that happens afterwards, after both building and test construction ?