[Misc] Use dedicated assertions instead of boolean assertions in oldcore tests (SonarCloud java:S5785)#5828
Open
vmassol wants to merge 1 commit into
Open
[Misc] Use dedicated assertions instead of boolean assertions in oldcore tests (SonarCloud java:S5785)#5828vmassol wants to merge 1 commit into
vmassol wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mechanical, behaviour-preserving cleanup of SonarCloud rule java:S5785 ("Fix this assertion to correctly compare these two values") in the
xwiki-platform-oldcoremodule. 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/assertNotEqualsThe receiver is kept as the first argument (
assertEquals(receiver, arg)callsreceiver.equals(arg)) so the exactequals()/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:
assertNotEqualsadded toNumberPropertyTestandXWikiLinkTest; the now-unusedassertTrue/assertFalseremoved where the file no longer uses them (NumberPropertyTest,XWikiLinkTest,DatabaseProductTest). InDatabaseProductTest.toProductDifferencethe flaggedassertTrue(product != DatabaseProduct.DERBY)was simply removed because the following line already asserts the same thing withassertNotSame.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,snapshotonxwiki-platform-oldcorerunning 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