-
-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Tests for SpanId, add tests for SentryUUID and UUIDStringUtils
- Loading branch information
Showing
4 changed files
with
54 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.sentry | ||
|
||
import junit.framework.TestCase.assertEquals | ||
import kotlin.test.Test | ||
|
||
class SentryUUIDTest { | ||
|
||
@Test | ||
fun `generated SentryID is 32 characters long`() { | ||
val sentryId = SentryUUID.generateSentryId() | ||
assertEquals(32, sentryId.length) | ||
} | ||
|
||
@Test | ||
fun `generated SpanID is 16 characters long`() { | ||
val sentryId = SentryUUID.generateSpanId() | ||
assertEquals(16, sentryId.length) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.sentry | ||
|
||
import io.sentry.util.UUIDStringUtils | ||
import java.util.UUID | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class UUIDStringUtilsTest { | ||
|
||
@Test | ||
fun `UUID toString matches UUIDStringUtils to String`() { | ||
val uuid = UUID.randomUUID() | ||
val sentryIdString = uuid.toString().replace("-", "") | ||
assertEquals(sentryIdString, UUIDStringUtils.toSentryIdString(uuid)) | ||
} | ||
|
||
@Test | ||
fun `UUID toString matches UUIDStringUtils to String for SpanId`() { | ||
val uuid = UUID.randomUUID() | ||
val sentryIdString = uuid.toString().replace("-", "").substring(0, 16) | ||
assertEquals(sentryIdString, UUIDStringUtils.toSentrySpanIdString(uuid)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,36 @@ | ||
package io.sentry.protocol | ||
|
||
import io.sentry.SentryUUID | ||
import io.sentry.SpanId | ||
import io.sentry.util.StringUtils | ||
import org.mockito.Mockito | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.never | ||
import org.mockito.kotlin.times | ||
import java.util.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class SpanIdTest { | ||
|
||
@Test | ||
fun `UUID is not generated on initialization`() { | ||
val uuid = UUID.randomUUID() | ||
Mockito.mockStatic(UUID::class.java).use { utils -> | ||
utils.`when`<UUID> { UUID.randomUUID() }.thenReturn(uuid) | ||
fun `ID is not generated on initialization`() { | ||
val uuid = SentryUUID.generateSpanId() | ||
Mockito.mockStatic(SentryUUID::class.java).use { utils -> | ||
utils.`when`<String> { SentryUUID.generateSpanId() }.thenReturn(uuid) | ||
val ignored = SpanId() | ||
utils.verify({ UUID.randomUUID() }, never()) | ||
utils.verify({ SentryUUID.generateSpanId() }, never()) | ||
} | ||
} | ||
|
||
@Test | ||
fun `UUID is generated only once`() { | ||
val uuid = UUID.randomUUID() | ||
Mockito.mockStatic(java.util.UUID::class.java).use { utils -> | ||
utils.`when`<UUID> { UUID.randomUUID() }.thenReturn(uuid) | ||
fun `ID is generated only once`() { | ||
val uuid = SentryUUID.generateSpanId() | ||
Mockito.mockStatic(SentryUUID::class.java).use { utils -> | ||
utils.`when`<String> { SentryUUID.generateSpanId() }.thenReturn(uuid) | ||
val spanId = SpanId() | ||
val uuid1 = spanId.toString() | ||
val uuid2 = spanId.toString() | ||
|
||
assertEquals(uuid1, uuid2) | ||
utils.verify({ UUID.randomUUID() }, times(1)) | ||
} | ||
} | ||
|
||
@Test | ||
fun `normalizeUUID is only called once`() { | ||
Mockito.mockStatic(StringUtils::class.java).use { utils -> | ||
utils.`when`<Any> { StringUtils.normalizeUUID(any()) }.thenReturn("00000000000000000000000000000000") | ||
val spanId = SpanId() | ||
val uuid1 = spanId.toString() | ||
val uuid2 = spanId.toString() | ||
|
||
assertEquals(uuid1, uuid2) | ||
utils.verify({ StringUtils.normalizeUUID(any()) }, times(1)) | ||
utils.verify({ SentryUUID.generateSpanId() }, times(1)) | ||
} | ||
} | ||
} |