Trying some variants of rules creation in a groovy file, I have come to the thought, that @Rule doesn't describe DECLARATION, but ASSIGNMENT. So, the runner, when loading the test, tries every rule for the correct assignment.
//Correct variants:
@Rule
public ErrorCollector collector1= new ErrorCollector();
public ErrorCollector collector2= null;
@Rule
collector2= new ErrorCollector();
public ErrorCollector collector3;
@Rule
collector3= new ErrorCollector();
// incorrect variants:
@Rule
public ErrorCollector collector4= null;
@Rule
public ErrorCollector collector5;
@Rule
public ErrorCollector collector5=somethingThatIsNotRule;
@Rule
public ErrorCollector collector5=anotherRule;
But, then I came to some paradoxial variants:
//these lines are not only taken by the runner, but also passed without errors:
public ErrorCollector collector6;
{
@Rule
collector6= null;
}
public ErrorCollector collector7=null;
{
@Rule
collector7= null;
}
What is the logic of it?
It seems as a bug in Runner - the runner makes an excessive check before constructing the test.