Skip to content

[Misc] Use dedicated assertions instead of boolean assertions in oldcore tests (SonarCloud java:S5785)#5828

Open
vmassol wants to merge 1 commit into
masterfrom
claude/vigilant-dirac-papb8a
Open

[Misc] Use dedicated assertions instead of boolean assertions in oldcore tests (SonarCloud java:S5785)#5828
vmassol wants to merge 1 commit into
masterfrom
claude/vigilant-dirac-papb8a

Conversation

@vmassol

@vmassol vmassol commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

Mechanical, behaviour-preserving cleanup of SonarCloud rule java:S5785 ("Fix this assertion to correctly compare these two values") in the xwiki-platform-oldcore module. 22 issues fixed across 4 test files.

Using a dedicated equality/identity assertion instead of a boolean one makes a test failure report the actual and expected values instead of just expected: <true> but was: <false>.

Details

  • assertTrue(a.equals(b))assertEquals(a, b), assertFalse(a.equals(b))assertNotEquals(a, b)
  • assertTrue(a == b)assertSame(a, b), assertFalse(a == b)assertNotSame(a, b) (reference comparisons on attachments / enum constants)
  • assertTrue(a == b) / assertTrue(a != b) on numeric values (size(), getNumber(), size() == 1) → assertEquals / assertNotEquals

The receiver is kept as the first argument (assertEquals(receiver, arg) calls receiver.equals(arg)) so the exact equals()/identity direction of each original assertion is preserved. Reference-identity assertions (assertSame/assertNotSame) are symmetric, so the original operand order is kept for readability.

Static imports adjusted per file: assertNotEquals added to NumberPropertyTest and XWikiLinkTest; the now-unused assertTrue/assertFalse removed where the file no longer uses them (NumberPropertyTest, XWikiLinkTest, DatabaseProductTest). In DatabaseProductTest.toProductDifference the flagged assertTrue(product != DatabaseProduct.DERBY) was simply removed because the following line already asserts the same thing with assertNotSame.

No production code changed; only test assertions.

Files:

  • XWikiDocumentMockitoTest (15)
  • NumberPropertyTest (5)
  • XWikiLinkTest (1)
  • DatabaseProductTest (1)

All fixed issues belong to SonarCloud rule java:S5785. See the open S5785 issues for this project.

Test plan

  • mvn clean install -Plegacy,snapshot on xwiki-platform-oldcore running the 4 affected test classes with tests — BUILD SUCCESS (83 tests, 0 failures; Checkstyle passes). Building with tests confirms the receiver-first operand ordering preserves each assertion's semantics.

Generated by Claude Code

…ore tests (SonarCloud java:S5785)

* Replace assertTrue/assertFalse wrapping equals(), ==, != and size()
  comparisons with assertEquals/assertNotEquals/assertSame/assertNotSame
  so failures report the actual and expected values.
* The receiver is kept as the first argument to preserve each assertion's
  equals()/identity direction. Test-only change, behaviour-preserving.

Co-Authored-By: Vincent Massol <vincent@massol.net>
@vmassol vmassol added the llm-agent To be used for PRs created autonomously by LLM agents. label Jul 13, 2026 — with Claude
@vmassol vmassol self-assigned this Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llm-agent To be used for PRs created autonomously by LLM agents.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant