Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WICKET-7011 Swap assertion arguments to conform to expected vs actual #546

Merged
merged 2 commits into from
Nov 12, 2022
Merged

WICKET-7011 Swap assertion arguments to conform to expected vs actual #546

merged 2 commits into from
Nov 12, 2022

Conversation

@timtebeek
Copy link
Contributor Author

Might have found an issue in AppendingStringBuffer; the equals method does not return the same when comparing String with AppendingStringBuffer, as when you compare AppendingStringBuffer with String.

When you change:

diff --git a/wicket-util/src/test/java/org/apache/wicket/util/string/AppendingStringBufferTest.java b/wicket-util/src/test/java/org/apache/wicket/util/string/AppendingStringBufferTest.java
index 7eedb46fed..e1ac4b0883 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/string/AppendingStringBufferTest.java
+++ b/wicket-util/src/test/java/org/apache/wicket/util/string/AppendingStringBufferTest.java
@@ -67,7 +67,7 @@ public class AppendingStringBufferTest
                AppendingStringBuffer asb = new AppendingStringBuffer("123456789");
                StringBuilder sb = new StringBuilder("123456789");
                assertEquals(asb, sb);
-               assertEquals(asb, "123456789");
+               assertEquals("123456789", asb);
 
                sb = new StringBuilder("01234567890");
                assertNotEquals(asb, sb);

You get:

[ERROR] Failures: 
[ERROR]   AppendingStringBufferTest.equalsToCharSequence:70
  expected: java.lang.String@52cb4f50<123456789>
  but was: org.apache.wicket.util.string.AppendingStringBuffer@25a5c7db<123456789>

Might be worth creating a separate issue for.

@martin-g
Copy link
Member

Might be worth creating a separate issue for.

Is it possible to do anything about it at our side ?
AppendingStringBuffer#equals() has logic to compare against any CharSequence.
java.lang.String (Java 17) does not have such logic.
Maybe we should open an issue at OpenJDK ?!

@timtebeek
Copy link
Contributor Author

Not sure if there's much we could do; the assertions end up calling:

static boolean objectsAreEqual(Object obj1, Object obj2) {
	if (obj1 == null) {
		return (obj2 == null);
	}
	return obj1.equals(obj2);
}

And I understand that AppendingStringBuffer indeed has some alternative handling.

For the test specifically we could maybe go with

diff --git a/wicket-util/src/test/java/org/apache/wicket/util/string/AppendingStringBufferTest.java b/wicket-util/src/test/java/org/apache/wicket/util/string/AppendingStringBufferTest.java
index 7eedb46fed..e1ac4b0883 100644
--- a/wicket-util/src/test/java/org/apache/wicket/util/string/AppendingStringBufferTest.java
+++ b/wicket-util/src/test/java/org/apache/wicket/util/string/AppendingStringBufferTest.java
@@ -67,7 +67,7 @@ public class AppendingStringBufferTest
                AppendingStringBuffer asb = new AppendingStringBuffer("123456789");
                StringBuilder sb = new StringBuilder("123456789");
                assertEquals(asb, sb);
-               assertEquals(asb, "123456789");
+               assertEquals("123456789", asb.toString());
 
                sb = new StringBuilder("01234567890");
                assertNotEquals(asb, sb);

That way you won't get the change suggested again in the future.

@martin-g
Copy link
Member

I'm fine with this solution!

@timtebeek
Copy link
Contributor Author

Thanks for the quick review! I've kept the AppendingStringBufferTest changes out of this PR for now, to keep things simple.

@bitstorm bitstorm merged commit e403284 into apache:master Nov 12, 2022
@timtebeek timtebeek deleted the WICKET-7011_swap_assertion_arguments branch November 17, 2022 10:46
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.

3 participants