11package io.ably.lib.objects.integration
22
3- import io.ably.lib.objects.type.counter.LiveCounter
4- import io.ably.lib.objects.type.map.LiveMap
53import io.ably.lib.objects.assertWaiter
64import io.ably.lib.objects.integration.helpers.ObjectId
75import io.ably.lib.objects.integration.helpers.fixtures.createUserEngagementMatrixMap
@@ -29,64 +27,64 @@ class DefaultLiveCounterTest: IntegrationTest() {
2927 val rootMap = channel.objects.root
3028
3129 // Get the user map object from the root map
32- val userMap = rootMap.get(" user" ) as LiveMap
30+ val userMap = rootMap.get(" user" )?.asLiveMap
3331 assertNotNull(userMap, " User map should be synchronized" )
3432 assertEquals(7L , userMap.size(), " User map should contain 7 top-level entries" )
3533
3634 // Assert direct counter objects at the top level of the user map
3735 // Test profileViews counter - should have initial value of 127
38- val profileViewsCounter = userMap.get(" profileViews" ) as LiveCounter
36+ val profileViewsCounter = userMap.get(" profileViews" )?.asLiveCounter
3937 assertNotNull(profileViewsCounter, " Profile views counter should exist" )
4038 assertEquals(127.0 , profileViewsCounter.value(), " Profile views counter should have initial value of 127" )
4139
4240 // Test postLikes counter - should have initial value of 45
43- val postLikesCounter = userMap.get(" postLikes" ) as LiveCounter
41+ val postLikesCounter = userMap.get(" postLikes" )?.asLiveCounter
4442 assertNotNull(postLikesCounter, " Post likes counter should exist" )
4543 assertEquals(45.0 , postLikesCounter.value(), " Post likes counter should have initial value of 45" )
4644
4745 // Test commentCount counter - should have initial value of 23
48- val commentCountCounter = userMap.get(" commentCount" ) as LiveCounter
46+ val commentCountCounter = userMap.get(" commentCount" )?.asLiveCounter
4947 assertNotNull(commentCountCounter, " Comment count counter should exist" )
5048 assertEquals(23.0 , commentCountCounter.value(), " Comment count counter should have initial value of 23" )
5149
5250 // Test followingCount counter - should have initial value of 89
53- val followingCountCounter = userMap.get(" followingCount" ) as LiveCounter
51+ val followingCountCounter = userMap.get(" followingCount" )?.asLiveCounter
5452 assertNotNull(followingCountCounter, " Following count counter should exist" )
5553 assertEquals(89.0 , followingCountCounter.value(), " Following count counter should have initial value of 89" )
5654
5755 // Test followersCount counter - should have initial value of 156
58- val followersCountCounter = userMap.get(" followersCount" ) as LiveCounter
56+ val followersCountCounter = userMap.get(" followersCount" )?.asLiveCounter
5957 assertNotNull(followersCountCounter, " Followers count counter should exist" )
6058 assertEquals(156.0 , followersCountCounter.value(), " Followers count counter should have initial value of 156" )
6159
6260 // Test loginStreak counter - should have initial value of 7
63- val loginStreakCounter = userMap.get(" loginStreak" ) as LiveCounter
61+ val loginStreakCounter = userMap.get(" loginStreak" )?.asLiveCounter
6462 assertNotNull(loginStreakCounter, " Login streak counter should exist" )
6563 assertEquals(7.0 , loginStreakCounter.value(), " Login streak counter should have initial value of 7" )
6664
6765 // Assert the nested engagement metrics map
68- val engagementMetrics = userMap.get(" engagementMetrics" ) as LiveMap
66+ val engagementMetrics = userMap.get(" engagementMetrics" )?.asLiveMap
6967 assertNotNull(engagementMetrics, " Engagement metrics map should exist" )
7068 assertEquals(4L , engagementMetrics.size(), " Engagement metrics map should contain 4 counter entries" )
7169
7270 // Assert counter objects within the engagement metrics map
7371 // Test totalShares counter - should have initial value of 34
74- val totalSharesCounter = engagementMetrics.get(" totalShares" ) as LiveCounter
72+ val totalSharesCounter = engagementMetrics.get(" totalShares" )?.asLiveCounter
7573 assertNotNull(totalSharesCounter, " Total shares counter should exist" )
7674 assertEquals(34.0 , totalSharesCounter.value(), " Total shares counter should have initial value of 34" )
7775
7876 // Test totalBookmarks counter - should have initial value of 67
79- val totalBookmarksCounter = engagementMetrics.get(" totalBookmarks" ) as LiveCounter
77+ val totalBookmarksCounter = engagementMetrics.get(" totalBookmarks" )?.asLiveCounter
8078 assertNotNull(totalBookmarksCounter, " Total bookmarks counter should exist" )
8179 assertEquals(67.0 , totalBookmarksCounter.value(), " Total bookmarks counter should have initial value of 67" )
8280
8381 // Test totalReactions counter - should have initial value of 189
84- val totalReactionsCounter = engagementMetrics.get(" totalReactions" ) as LiveCounter
82+ val totalReactionsCounter = engagementMetrics.get(" totalReactions" )?.asLiveCounter
8583 assertNotNull(totalReactionsCounter, " Total reactions counter should exist" )
8684 assertEquals(189.0 , totalReactionsCounter.value(), " Total reactions counter should have initial value of 189" )
8785
8886 // Test dailyActiveStreak counter - should have initial value of 12
89- val dailyActiveStreakCounter = engagementMetrics.get(" dailyActiveStreak" ) as LiveCounter
87+ val dailyActiveStreakCounter = engagementMetrics.get(" dailyActiveStreak" )?.asLiveCounter
9088 assertNotNull(dailyActiveStreakCounter, " Daily active streak counter should exist" )
9189 assertEquals(12.0 , dailyActiveStreakCounter.value(), " Daily active streak counter should have initial value of 12" )
9290
@@ -130,7 +128,7 @@ class DefaultLiveCounterTest: IntegrationTest() {
130128 assertWaiter { rootMap.get(" testCounter" ) != null }
131129
132130 // Assert initial state after creation
133- val testCounter = rootMap.get(" testCounter" ) as LiveCounter
131+ val testCounter = rootMap.get(" testCounter" )?.asLiveCounter
134132 assertNotNull(testCounter, " Test counter should be created and accessible" )
135133 assertEquals(10.0 , testCounter.value(), " Counter should have initial value of 10" )
136134
@@ -201,7 +199,7 @@ class DefaultLiveCounterTest: IntegrationTest() {
201199 assertNotNull(testCounter, " Counter should still be accessible at the end" )
202200
203201 // Verify we can still access it from the root map
204- val finalCounterCheck = rootMap.get(" testCounter" ) as LiveCounter
202+ val finalCounterCheck = rootMap.get(" testCounter" )?.asLiveCounter
205203 assertNotNull(finalCounterCheck, " Counter should still be accessible from root map" )
206204 assertEquals(30.0 , finalCounterCheck.value(), " Final counter value should be 30 when accessed from root map" )
207205 }
@@ -215,11 +213,11 @@ class DefaultLiveCounterTest: IntegrationTest() {
215213 val channel = getRealtimeChannel(channelName)
216214 val rootMap = channel.objects.root
217215
218- val userEngagementMap = rootMap.get(" userMatrix" ) as LiveMap
219- assertEquals(4L , userEngagementMap.size(), " User engagement map should contain 4 top-level entries" )
216+ val userEngagementMap = rootMap.get(" userMatrix" )?.asLiveMap
217+ assertEquals(4L , userEngagementMap!! .size(), " User engagement map should contain 4 top-level entries" )
220218
221- val totalReactions = userEngagementMap.get(" totalReactions" ) as LiveCounter
222- assertEquals(189.0 , totalReactions.value(), " Total reactions counter should have initial value of 189" )
219+ val totalReactions = userEngagementMap.get(" totalReactions" )?.asLiveCounter
220+ assertEquals(189.0 , totalReactions!! .value(), " Total reactions counter should have initial value of 189" )
223221
224222 // Subscribe to changes on the totalReactions counter
225223 val counterUpdates = mutableListOf<Double >()
0 commit comments