Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests for class
  • Loading branch information
bparrishMines committed Sep 24, 2025
commit 643f5477f0687f519734cb2724e0e9f7b3e63f4f
2 changes: 1 addition & 1 deletion packages/pigeon/lib/src/kotlin/templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ${kotlinInstanceManagerClassName(options)}(private val finalizationListene

// Extends WeakReference and overrides the `equals` and `hashCode` methods using identity rather
// than equality.
private class IdentityWeakReference<T : Any> : java.lang.ref.WeakReference<T> {
class IdentityWeakReference<T : Any> : java.lang.ref.WeakReference<T> {
private val savedHashCode: Int

constructor(instance: T) : this(instance, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ProxyApiTestsPigeonInstanceManager(

// Extends WeakReference and overrides the `equals` and `hashCode` methods using identity rather
// than equality.
private class IdentityWeakReference<T : Any> : java.lang.ref.WeakReference<T> {
class IdentityWeakReference<T : Any> : java.lang.ref.WeakReference<T> {
private val savedHashCode: Int

constructor(instance: T) : this(instance, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,30 @@ class InstanceManagerTest {
assertEquals(1L, instanceManager.getIdentifierForStrongReference(testObject2))
}

@Test
fun identityWeakReferenceAreEqualWithSameInstance() {
val testObject = Any()

assertEquals(
ProxyApiTestsPigeonInstanceManager.IdentityWeakReference(testObject),
ProxyApiTestsPigeonInstanceManager.IdentityWeakReference(testObject))
}

@Test
fun identityWeakReferenceRemainsEqualAfterGetReturnsNull() {
var testObject: Any? = Any()

val reference = ProxyApiTestsPigeonInstanceManager.IdentityWeakReference(testObject!!)

// To allow for object to be garbage collected.
@Suppress("UNUSED_VALUE")
testObject = null
Runtime.getRuntime().gc()

assertNull(reference.get())
assertEquals(reference, reference)
}

private fun createInstanceManager(): ProxyApiTestsPigeonInstanceManager {
return ProxyApiTestsPigeonInstanceManager.create(
object : ProxyApiTestsPigeonInstanceManager.PigeonFinalizationListener {
Expand Down