Skip to content

refactor: de-duplicate choice-list initializers, fix Sonar, add tests#37

Open
fbourasse wants to merge 1 commit into
masterfrom
review/dedup-initializers-tests
Open

refactor: de-duplicate choice-list initializers, fix Sonar, add tests#37
fbourasse wants to merge 1 commit into
masterfrom
review/dedup-initializers-tests

Conversation

@fbourasse

Copy link
Copy Markdown

Summary

Blind multi-dimensional review of the bootstrap4 module. SonarQube quality gate was ERROR (duplicated_lines_density 32.1% vs 3% threshold) and is now OK (0%), with 23 issues resolved and the first bootstrap4-components unit tests added.

Code quality / duplication (the gate blocker)

  • The three choice-list initializers (ButtonTypeInitializer, NavbarRootInitializer, GridTypeInitializer) were ~90% identical (duplicate setKey/getKey/getStringRendering ×2 plus boilerplate). Extracted a shared AbstractChoiceListInitializerRenderer base class; each concrete class now only declares its @Component, default key, and its specific choice list via a helper. Project duplication dropped 32.1% → 0.0%.
  • Removed the unused logger fields (S1068), applied the diamond operator (S2293), and extracted the repeated addMixin literal to a constant (S1192 CRITICAL).

Bug / BLOCKER

  • SwitchToLanguageTag declared a private String languageCode field that shadowed the inherited AbstractJahiaTag.languageCode (Sonar BLOCKER S2387). Verified via javap that the superclass exposes a usable protected field + accessors; removed the local field and redundant accessors, and added the missing @Override annotations (S1161). Rendered <a> output is unchanged.

Tests & coverage

  • First unit tests for bootstrap4-components: 16 tests (JUnit 4 + Mockito) covering all three initializers (value names/order, addMixin mapping, null-context empty list, string rendering) and the Functions taglib helper. JaCoCo coverage wiring.

Behavior

  • No functional change: choice-list values, keys, mixins, and rendering output are identical.

Test plan

  • mvn clean install (JDK 17, full reactor) — BUILD SUCCESS, 16/16 tests
  • SonarQube gate OK (duplication 0%, 0 open issues)
  • N/A Cypress — no E2E harness in this module

- Extract AbstractChoiceListInitializerRenderer base class for the ButtonType/
  NavbarRoot/GridType initializers (~90% duplicated) — project duplication
  32% -> 0%, clearing the duplicated_lines_density gate. Remove unused loggers,
  apply diamond operator, extract the addMixin literal to a constant.
- SwitchToLanguageTag: remove the languageCode field shadowing
  AbstractJahiaTag.languageCode (Sonar BLOCKER S2387); add @OverRide.
- Add first bootstrap4-components unit tests (JUnit 4 + Mockito, 16) + JaCoCo.

Signed-off-by: Florent BOURASSE <fbourasse@jahia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant