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

Broken assertSame/assertNotSame after #2460 #2616

Closed
2 of 7 tasks
Axinet opened this issue Jul 22, 2021 · 1 comment
Closed
2 of 7 tasks

Broken assertSame/assertNotSame after #2460 #2616

Axinet opened this issue Jul 22, 2021 · 1 comment

Comments

@Axinet
Copy link

Axinet commented Jul 22, 2021

TestNG Version 7.4

Expected behavior

assertNotSame(object1, object2) should pass, when object1 != object2 && object1.equals(object2)

Actual behavior

After merging 841ae94 (issue #2460) it looks like replacing actual==expected / actual!=expected to equals/ !equals went too far and broken one of common Assetions. Its a strong backward incompatible change in behaviour between 7.3 and 7.4

Is the issue reproductible on runner?

(Probably everywhere, tested on two)

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

Test case sample

Please, share the test case (as small as possible) which shows the issue

Problem is present for any custom object which has implemented its own equals method.

import java.util.Objects;

import org.testng.Assert;
import org.testng.annotations.Test;

public class BrokenNotSameTest {
	static class MyObject {
		private final String myName;

		MyObject(String myName) {
			this.myName = myName;
		}

		@Override
		public boolean equals(Object o) {
			if (this == o) {
				return true;
			}
			if (o == null || getClass() != o.getClass()) {
				return false;
			}
			MyObject myObject = (MyObject) o;
			return Objects.equals(myName, myObject.myName);
		}

		@Override
		public int hashCode() {
			return Objects.hash(myName);
		}
	}

	@Test
	public static void assertNotSamePass73Fails74() {
		MyObject instance1 = new MyObject("someName");
		MyObject instance2 = new MyObject("someName");
		Assert.assertNotSame(instance1, instance2);
	}

	@Test
	public static void assertSameInstancesFails73Pass74() {
		MyObject instance1 = new MyObject("someName");
		MyObject instance2 = new MyObject("someName");
		Assert.assertSame(instance1, instance2);
	}
}
@juherr
Copy link
Member

juherr commented Jul 24, 2021

Duplicate of #2486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants