11package io.ably.lib.objects.integration
22
3- import com.google.gson.JsonArray
4- import com.google.gson.JsonObject
53import io.ably.lib.objects.*
6- import io.ably.lib.objects.Binary
74import io.ably.lib.objects.integration.helpers.State
85import io.ably.lib.objects.integration.helpers.fixtures.initializeRootMap
96import io.ably.lib.objects.integration.helpers.simulateObjectDelete
107import io.ably.lib.objects.integration.setup.IntegrationTest
11- import io.ably.lib.objects.size
128import io.ably.lib.objects.state.ObjectsStateEvent
13- import io.ably.lib.objects.type.counter.LiveCounter
149import io.ably.lib.objects.type.livecounter.DefaultLiveCounter
1510import io.ably.lib.objects.type.livemap.DefaultLiveMap
16- import io.ably.lib.objects.type.map.LiveMap
1711import io.ably.lib.objects.type.map.LiveMapUpdate
1812import kotlinx.coroutines.test.runTest
1913import org.junit.Test
@@ -79,81 +73,81 @@ class DefaultLiveObjectsTest : IntegrationTest() {
7973
8074 // Assert Counter Objects
8175 // Test emptyCounter - should have initial value of 0
82- val emptyCounter = rootMap.get(" emptyCounter" ) as LiveCounter
76+ val emptyCounter = rootMap.get(" emptyCounter" )?.asLiveCounter
8377 assertNotNull(emptyCounter)
8478 assertEquals(0.0 , emptyCounter.value())
8579
8680 // Test initialValueCounter - should have initial value of 10
87- val initialValueCounter = rootMap.get(" initialValueCounter" ) as LiveCounter
81+ val initialValueCounter = rootMap.get(" initialValueCounter" )?.asLiveCounter
8882 assertNotNull(initialValueCounter)
8983 assertEquals(10.0 , initialValueCounter.value())
9084
9185 // Test referencedCounter - should have initial value of 20
92- val referencedCounter = rootMap.get(" referencedCounter" ) as LiveCounter
86+ val referencedCounter = rootMap.get(" referencedCounter" )?.asLiveCounter
9387 assertNotNull(referencedCounter)
9488 assertEquals(20.0 , referencedCounter.value())
9589
9690 // Assert Map Objects
9791 // Test emptyMap - should be an empty map
98- val emptyMap = rootMap.get(" emptyMap" ) as LiveMap
92+ val emptyMap = rootMap.get(" emptyMap" )?.asLiveMap
9993 assertNotNull(emptyMap)
10094 assertEquals(0L , emptyMap.size())
10195
10296 // Test referencedMap - should contain one key "counterKey" pointing to referencedCounter
103- val referencedMap = rootMap.get(" referencedMap" ) as LiveMap
97+ val referencedMap = rootMap.get(" referencedMap" )?.asLiveMap
10498 assertNotNull(referencedMap)
10599 assertEquals(1L , referencedMap.size())
106- val referencedMapCounter = referencedMap.get(" counterKey" ) as LiveCounter
100+ val referencedMapCounter = referencedMap.get(" counterKey" )?.asLiveCounter
107101 assertNotNull(referencedMapCounter)
108102 assertEquals(20.0 , referencedMapCounter.value()) // Should point to the same counter with value 20
109103
110104 // Test valuesMap - should contain all primitive data types and one map reference
111- val valuesMap = rootMap.get(" valuesMap" ) as LiveMap
105+ val valuesMap = rootMap.get(" valuesMap" )?.asLiveMap
112106 assertNotNull(valuesMap)
113107 assertEquals(13L , valuesMap.size()) // Should have 13 entries
114108
115109 // Assert string values
116- assertEquals(" stringValue" , valuesMap.get(" string" ))
117- assertEquals(" " , valuesMap.get(" emptyString" ))
110+ assertEquals(" stringValue" , valuesMap.get(" string" )?.asString )
111+ assertEquals(" " , valuesMap.get(" emptyString" )?.asString )
118112
119113 // Assert binary values
120- val bytesValue = valuesMap.get(" bytes" ) as Binary
114+ val bytesValue = valuesMap.get(" bytes" )?.asBinary
121115 assertNotNull(bytesValue)
122- val expectedBinary = Binary ( " eyJwcm9kdWN0SWQiOiAiMDAxIiwgInByb2R1Y3ROYW1lIjogImNhciJ9" .toByteArray() )
123- assertEquals(expectedBinary, bytesValue ) // Should contain encoded JSON data
116+ val expectedBinary = " eyJwcm9kdWN0SWQiOiAiMDAxIiwgInByb2R1Y3ROYW1lIjogImNhciJ9" .toByteArray()
117+ assertEquals(expectedBinary.contentEquals(bytesValue), true ) // Should contain encoded JSON data
124118
125- val emptyBytesValue = valuesMap.get(" emptyBytes" ) as Binary
119+ val emptyBytesValue = valuesMap.get(" emptyBytes" )?.asBinary
126120 assertNotNull(emptyBytesValue)
127- assertEquals(0 , emptyBytesValue.size() ) // Should be empty byte array
121+ assertEquals(0 , emptyBytesValue.size) // Should be empty byte array
128122
129123 // Assert numeric values
130- assertEquals(99999999.0 , valuesMap.get(" maxSafeNumber" ))
131- assertEquals(- 99999999.0 , valuesMap.get(" negativeMaxSafeNumber" ))
132- assertEquals(1.0 , valuesMap.get(" number" ))
133- assertEquals(0.0 , valuesMap.get(" zero" ))
124+ assertEquals(99999999.0 , valuesMap.get(" maxSafeNumber" )?.asNumber )
125+ assertEquals(- 99999999.0 , valuesMap.get(" negativeMaxSafeNumber" )?.asNumber )
126+ assertEquals(1.0 , valuesMap.get(" number" )?.asNumber )
127+ assertEquals(0.0 , valuesMap.get(" zero" )?.asNumber )
134128
135129 // Assert boolean values
136- assertEquals(true , valuesMap.get(" true" ))
137- assertEquals(false , valuesMap.get(" false" ))
130+ assertEquals(true , valuesMap.get(" true" )?.asBoolean )
131+ assertEquals(false , valuesMap.get(" false" )?.asBoolean )
138132
139133 // Assert JSON object value - should contain {"foo": "bar"}
140- val jsonObjectValue = valuesMap.get(" object" ) as JsonObject
134+ val jsonObjectValue = valuesMap.get(" object" )?.asJsonObject
141135 assertNotNull(jsonObjectValue)
142136 assertEquals(" bar" , jsonObjectValue.get(" foo" ).asString)
143137
144138 // Assert JSON array value - should contain ["foo", "bar", "baz"]
145- val jsonArrayValue = valuesMap.get(" array" ) as JsonArray
139+ val jsonArrayValue = valuesMap.get(" array" )?.asJsonArray
146140 assertNotNull(jsonArrayValue)
147141 assertEquals(3 , jsonArrayValue.size())
148142 assertEquals(" foo" , jsonArrayValue[0 ].asString)
149143 assertEquals(" bar" , jsonArrayValue[1 ].asString)
150144 assertEquals(" baz" , jsonArrayValue[2 ].asString)
151145
152146 // Assert map reference - should point to the same referencedMap
153- val mapRefValue = valuesMap.get(" mapRef" ) as LiveMap
147+ val mapRefValue = valuesMap.get(" mapRef" )?.asLiveMap
154148 assertNotNull(mapRefValue)
155149 assertEquals(1L , mapRefValue.size())
156- val mapRefCounter = mapRefValue.get(" counterKey" ) as LiveCounter
150+ val mapRefCounter = mapRefValue.get(" counterKey" )?.asLiveCounter
157151 assertNotNull(mapRefCounter)
158152 assertEquals(20.0 , mapRefCounter.value()) // Should point to the same counter with value 20
159153 }
@@ -176,7 +170,7 @@ class DefaultLiveObjectsTest : IntegrationTest() {
176170 assertEquals(6L , rootMap.size()) // Should have 6 entries initially
177171
178172 // Remove the "referencedCounter" from the root map
179- val refCounter = rootMap.get(" referencedCounter" ) as LiveCounter
173+ val refCounter = rootMap.get(" referencedCounter" )?.asLiveCounter
180174 assertNotNull(refCounter)
181175 // Subscribe to counter updates to verify removal
182176 val counterUpdates = mutableListOf<Double >()
@@ -193,7 +187,7 @@ class DefaultLiveObjectsTest : IntegrationTest() {
193187 assertEquals(- 20.0 , counterUpdates[0 ]) // The update should indicate counter was removed with value 20
194188
195189 // Remove the "referencedMap" from the root map
196- val referencedMap = rootMap.get(" referencedMap" ) as LiveMap
190+ val referencedMap = rootMap.get(" referencedMap" )?.asLiveMap
197191 assertNotNull(referencedMap)
198192 // Subscribe to map updates to verify removal
199193 val mapUpdates = mutableListOf<Map <String , LiveMapUpdate .Change >>()
@@ -214,7 +208,7 @@ class DefaultLiveObjectsTest : IntegrationTest() {
214208 assertEquals(LiveMapUpdate .Change .REMOVED , updatedMap.values.first()) // Should indicate removal
215209
216210 // Remove the "valuesMap" from the root map
217- val valuesMap = rootMap.get(" valuesMap" ) as LiveMap
211+ val valuesMap = rootMap.get(" valuesMap" )?.asLiveMap
218212 assertNotNull(valuesMap)
219213 // Subscribe to map updates to verify removal
220214 val valuesMapUpdates = mutableListOf<Map <String , LiveMapUpdate .Change >>()
0 commit comments