diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/ConstructorActivationTests.cs b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/ConstructorActivationTests.cs index 1fd51eff2e1..9b2bf94ee10 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/ConstructorActivationTests.cs +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/Java.Interop/ConstructorActivationTests.cs @@ -95,7 +95,7 @@ public void JavaSideContextConstructorForwardsArgument () new JValue (Application.Context))) { Assert.AreEqual (1, ConstructorActivationContextView.ConstructorInvocations); Assert.IsNotNull (instance.ContextValue); - Assert.AreEqual (Application.Context.Handle, instance.ContextValue.Handle); + AssertSameJavaObject (Application.Context, instance.ContextValue); } } @@ -110,7 +110,7 @@ public void JavaSideContextAttributeSetConstructorForwardsArguments () JValue.Zero)) { Assert.AreEqual (1, ConstructorActivationAttributeSetView.ConstructorInvocations); Assert.IsNotNull (instance.ContextValue); - Assert.AreEqual (Application.Context.Handle, instance.ContextValue.Handle); + AssertSameJavaObject (Application.Context, instance.ContextValue); Assert.IsNull (instance.AttributeSetValue); } } @@ -127,7 +127,7 @@ public void JavaSideContextAttributeSetStyleConstructorForwardsArguments () new JValue (42))) { Assert.AreEqual (1, ConstructorActivationStyledView.ConstructorInvocations); Assert.IsNotNull (instance.ContextValue); - Assert.AreEqual (Application.Context.Handle, instance.ContextValue.Handle); + AssertSameJavaObject (Application.Context, instance.ContextValue); Assert.IsNull (instance.AttributeSetValue); Assert.AreEqual (42, instance.DefStyleAttrValue); } @@ -474,7 +474,7 @@ public void JavaSideObjectArrayConstructorForwardsValues () Assert.IsNotNull (instance.ObjectArrayValue); Assert.AreEqual (2, instance.ObjectArrayValue.Length); Assert.AreEqual ("object-array-value", instance.ObjectArrayValue [0].ToString ()); - Assert.AreEqual (Application.Context.Handle, instance.ObjectArrayValue [1].Handle); + AssertSameJavaObject (Application.Context, instance.ObjectArrayValue [1]); } } @@ -564,6 +564,15 @@ static void AssertRegisteredSame (T instance) registered.Dispose (); } } + + static void AssertSameJavaObject (Java.Lang.Object expected, Java.Lang.Object actual) + { + Assert.IsNotNull (expected); + Assert.IsNotNull (actual); + Assert.IsTrue ( + JniEnvironment.Types.IsSameObject (expected.PeerReference, actual.PeerReference), + $"Expected Java object identity to match. Expected handle: {expected.Handle}, actual handle: {actual.Handle}."); + } } [Register ("net/dot/android/test/ConstructorActivationThrowing")]