Skip to content

Commit e6cf876

Browse files
committed
[ECO-5482] Added unit tests for for utilies
- Enhanced ObjectIdTest with testFromInitialValue test for object initialization - Added new test methods to UtilsTest for realtime operation utilities - Updated ObjectMessageSizeTest with realtime write operation size calculations
1 parent 2531ed2 commit e6cf876

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.junit.Test
1414
import kotlin.test.assertEquals
1515
import kotlin.test.assertNotNull
1616
import kotlin.test.assertNull
17+
import kotlin.test.assertTrue
1718
import kotlin.text.toByteArray
1819

1920
class DefaultLiveObjectsTest : IntegrationTest() {
@@ -114,7 +115,7 @@ class DefaultLiveObjectsTest : IntegrationTest() {
114115
val bytesValue = valuesMap.get("bytes")?.asBinary
115116
assertNotNull(bytesValue)
116117
val expectedBinary = "eyJwcm9kdWN0SWQiOiAiMDAxIiwgInByb2R1Y3ROYW1lIjogImNhciJ9".toByteArray()
117-
assertEquals(expectedBinary.contentEquals(bytesValue), true) // Should contain encoded JSON data
118+
assertTrue(expectedBinary.contentEquals(bytesValue)) // Should contain encoded JSON data
118119

119120
val emptyBytesValue = valuesMap.get("emptyBytes")?.asBinary
120121
assertNotNull(emptyBytesValue)

live-objects/src/test/kotlin/io/ably/lib/objects/unit/ObjectIdTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,24 @@ class ObjectIdTest {
5252
assertEquals(92_000, exception.errorInfo?.code)
5353
assertEquals(500, exception.errorInfo?.statusCode)
5454
}
55+
56+
@Test
57+
fun testFromInitialValue() {
58+
val objectType = ObjectType.Map
59+
val initialValue = "test-value"
60+
val nonce = "test-nonce"
61+
val msTimestamp = 1640995200000L
62+
63+
val objectId = ObjectId.fromInitialValue(objectType, initialValue, nonce, msTimestamp)
64+
// Verify the string format follows the expected pattern: type:hash@timestamp
65+
val objectIdString = objectId.toString()
66+
assertTrue(objectIdString.startsWith("map:"))
67+
assertTrue(objectIdString.contains("@"))
68+
assertTrue(objectIdString.endsWith(msTimestamp.toString()))
69+
70+
val expectedHash = "GSjv-adTaJPL8-382qF3JuIyE4TCc6QKIIqb577pz00"
71+
// Verify the hash value matches expected
72+
val hashPart = objectIdString.substring(4, objectIdString.indexOf("@"))
73+
assertEquals(expectedHash, hashPart)
74+
}
5575
}

live-objects/src/test/kotlin/io/ably/lib/objects/unit/ObjectMessageSizeTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class ObjectMessageSizeTest {
168168
}
169169
// Assert on error code and message
170170
assertEquals(40009, exception.errorInfo.code)
171-
val expectedMessage = "ObjectMessage size 66560 exceeds maximum allowed size of 65536 bytes"
171+
val expectedMessage = "ObjectMessages size 66560 exceeds maximum allowed size of 65536 bytes"
172172
assertEquals(expectedMessage, exception.errorInfo.message)
173173
}
174174
}

live-objects/src/test/kotlin/io/ably/lib/objects/unit/UtilsTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ import java.util.concurrent.CancellationException
1212

1313
class UtilsTest {
1414

15+
@Test
16+
fun testGenerateNonce() {
17+
// Test basic functionality
18+
val nonce1 = generateNonce()
19+
val nonce2 = generateNonce()
20+
21+
assertEquals(16, nonce1.length)
22+
assertEquals(16, nonce2.length)
23+
assertNotEquals(nonce1, nonce2) // Should be random
24+
25+
// Test character set
26+
val validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
27+
val nonce = generateNonce()
28+
nonce.forEach { char ->
29+
assertTrue("Nonce should only contain valid characters", validChars.contains(char))
30+
}
31+
}
32+
1533
@Test
1634
fun testStringByteSize() {
1735
// Test ASCII strings

0 commit comments

Comments
 (0)