Skip to content

Commit

Permalink
fix: ✅ Test update with the changes in ecoCode rules
Browse files Browse the repository at this point in the history
  • Loading branch information
alograg committed Jan 18, 2024
1 parent 00bb38f commit 9287e3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void checkNumberRules() {
final JavaCheckRegistrar registrar = new JavaCheckRegistrar();
registrar.register(context);

assertThat(context.checkClasses()).hasSize(19);
assertThat(context.checkClasses()).hasSize(15);
assertThat(context.testCheckClasses()).isEmpty();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,17 @@ class JavaRulesDefinitionTest {
private RulesDefinition.Repository repository;
private RulesDefinition.Context context;

private int rulesSize;

@BeforeEach
void init() {
// TODO: Remove this check after Git repo split
/*
On an IDE (like IntelliJ), if the developer runs the unit tests without building/generating the Maven goals on the
"ecocode-rules-specifications" module before, the unit tests will not see the generated HTML descriptions (from ASCIIDOC files).
The developer must therefore configure his IDE to build the `ecocode-rules-specifications` module before launching the Tests.
When the `java-plugin` submodule is in a specific Git repository, `ecocode-rules-specifications` will be fetched from a classic
external Maven dependency. There will therefore no longer be any need to perform this specific configuration.
*/
if (JavaRulesDefinition.class.getResource("/io/ecocode/rules/java/EC4.json") == null) {
String message = "'ecocode-rules-specification' resources corrupted. Please check build of 'ecocode-rules-specification' module";
if (System.getProperties().keySet().stream().anyMatch(k -> k.toString().startsWith("idea."))) {
message += "\n\nOn 'IntelliJ IDEA':" +
"\n1. go to settings :" +
"\n > Build, Execution, Deployment > Build Tools > Maven > Runner" +
"\n2. check option:" +
"\n > Delegate IDE build/run actions to Maven" +
"\n3. Click on menu: " +
"\n > Build > Build Project"
;
}
fail(message);
}

final SonarRuntime sonarRuntime = mock(SonarRuntime.class);
doReturn(Version.create(0, 0)).when(sonarRuntime).getApiVersion();
JavaRulesDefinition rulesDefinition = new JavaRulesDefinition(sonarRuntime);
RulesDefinition.Context context = new RulesDefinition.Context();
rulesDefinition.define(context);
repository = context.repository(rulesDefinition.repositoryKey());
rulesSize = 15;
}

@Test
Expand All @@ -78,12 +57,12 @@ void testMetadata() {
assertThat(repository.name()).isEqualTo("ecoCode");
assertThat(repository.language()).isEqualTo("java");
assertThat(repository.key()).isEqualTo("ecocode-java");
assertThat(repository.rules()).hasSize(19);
assertThat(repository.rules()).hasSize(rulesSize);
}

@Test
void testRegistredRules() {
assertThat(repository.rules()).hasSize(19);
assertThat(repository.rules()).hasSize(rulesSize);
}

@Test
Expand Down

0 comments on commit 9287e3c

Please sign in to comment.