[Misc] Use assertEquals/assertNotEquals instead of boolean assertions in bridge and eventstream-api tests (SonarCloud java:S5785)#5824
Open
vmassol wants to merge 1 commit into
Open
Conversation
… in bridge and eventstream-api tests (SonarCloud java:S5785) Replace assertTrue(a.equals(b))/assertFalse(a.equals(b)) and assertTrue(x == 0)/assertTrue(x != 0) with assertEquals/assertNotEquals so that a failure reports the actual and expected values. The receiver is kept as the first argument to preserve the exact equals() direction (matters for the cross-type comparison against ActionExecutedEvent). 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") across two modules. 31 issues fixed in 3 test files.
Using a dedicated equality 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(x == 0)→assertEquals(0, x)andassertTrue(x != 0)→assertNotEquals(0, x)(hashCode checks)The receiver is kept as the first argument (
assertEquals(receiver, arg)callsreceiver.equals(arg)) so the exactequals()direction of each original assertion is preserved. This matters inActionExecutingEventTest.doesntEqualDifferentTypeOfAction, which compares anActionExecutingEventagainst anActionExecutedEvent(a different type).Static imports adjusted accordingly:
assertNotEqualsadded toActionExecutingEventTest; the now-unusedassertTrue/assertFalseremoved fromAbstractRecordableEventDescriptorTest;SimpleEventQueryTestkeeps both (still used elsewhere).No production code changed; only test assertions.
Files:
xwiki-platform-bridge—ActionExecutingEventTest(14)xwiki-platform-eventstream-api—SimpleEventQueryTest(12),AbstractRecordableEventDescriptorTest(5)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-bridgeandxwiki-platform-eventstream-apiwith tests — BUILD SUCCESS (all tests pass, Checkstyle passes). Building with tests confirms the receiver-first operand ordering preserves each assertion's semantics.Generated by Claude Code