Skip to content

Commit 841ea33

Browse files
SONARJAVA-5144 Update Custom rules documentation to match MyJavaFileCheckRegistrarTest (#4903)
1 parent fed5ece commit 841ea33

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

docs/CUSTOM_RULES_101.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,23 +565,34 @@ public class MyJavaFileCheckRegistrar implements CheckRegistrar {
565565
}
566566
```
567567

568-
Now, because we added a new rule, we also need to update our tests to make sure it is taken into account.
569-
To do so, navigate to its corresponding test class, named `MyJavaFileCheckRegistrarTest`, and update the expected number of rules from 8 to 9.
568+
To do so, navigate to its corresponding test class, named `MyJavaFileCheckRegistrarTest`, add your rule key to the end of the mainRuleKeys list and your rule class name at the end of the mainCheckClasses list.
570569

571570
```java
572571

573572
class MyJavaFileCheckRegistrarTest {
574573

575574
@Test
576-
void checkNumberRules() {
577-
CheckRegistrar.RegistrarContext context = new CheckRegistrar.RegistrarContext();
575+
void checkRegisteredRulesKeysAndClasses() {
576+
TestCheckRegistrarContext context = new TestCheckRegistrarContext();
578577

579578
MyJavaFileCheckRegistrar registrar = new MyJavaFileCheckRegistrar();
580579
registrar.register(context);
581580

582-
assertThat(context.checkClasses()).hasSize(8); // change it to 9, we added a new one!
583-
assertThat(context.testCheckClasses()).isEmpty();
581+
assertThat(context.mainRuleKeys).extracting(RuleKey::toString).containsExactly(
582+
// other rules...
583+
"mycompany-java:MyFirstCustomRule");
584+
585+
assertThat(context.mainCheckClasses).extracting(Class::getSimpleName).containsExactly(
586+
// other rules...
587+
"MyFirstCustomCheck");
588+
589+
assertThat(context.testRuleKeys).extracting(RuleKey::toString).containsExactly(
590+
"mycompany-java:NoIfStatementInTests");
591+
592+
assertThat(context.testCheckClasses).extracting(Class::getSimpleName).containsExactly(
593+
"NoIfStatementInTestsRule");
584594
}
595+
585596
}
586597
```
587598

0 commit comments

Comments
 (0)