Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Merged
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
added unit tests for sentry level parsing
  • Loading branch information
Manoel Aranda Neto committed Oct 29, 2019
commit cb9803f14b3633332b1a65b3d67b27cbb261b1f6
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.google.gson.internal.LinkedTreeMap
import com.nhaarman.mockitokotlin2.mock
import io.sentry.core.DateUtils
import io.sentry.core.SentryEvent
import io.sentry.core.SentryLevel
import io.sentry.core.protocol.Contexts
import io.sentry.core.protocol.Device
import java.io.StringWriter
Expand Down Expand Up @@ -200,6 +201,33 @@ class AndroidSerializerTest {
assertEquals(Device.DeviceOrientation.LANDSCAPE, Device.DeviceOrientation.valueOf(orientation.toUpperCase())) // here too
}

@Test
fun `when serializing a SentryLevel, it should become a sentry level string`() {
val sentryEvent = generateEmptySentryEvent()
sentryEvent.eventId = null
sentryEvent.timestamp = null
sentryEvent.level = SentryLevel.DEBUG

val expected = "{\"level\":\"debug\"}"

val actual = serializeToString(sentryEvent)

assertEquals(expected, actual)
}

@Test
fun `when deserializing a sentry level string, it should become a SentryLevel`() {
val sentryEvent = generateEmptySentryEvent()
sentryEvent.eventId = null
sentryEvent.timestamp = null

val jsonEvent = "{\"level\":\"debug\"}"

val actual = serializer.deserializeEvent(jsonEvent)

assertEquals(SentryLevel.DEBUG, actual.level)
}

private fun generateEmptySentryEvent(): SentryEvent {
return SentryEvent().apply {
contexts = null
Expand Down