Skip to content

Commit

Permalink
Allow getLastRunEndState() to be accessed via a synthetic property in…
Browse files Browse the repository at this point in the history
… Kotlin (#1282)

## Goal

Store the ability to access `getLastRunEndState()` via a synthetic read-only property in Kotlin as it was that way in previous versions thanks to the old Kotlin version that was used. 

We will revisit this in the next major version.

## Testing
Add integration tests that access the getter in the Java Embrace object via this
  • Loading branch information
bidetofevil authored Aug 21, 2024
1 parent b25b6de commit dce909e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package io.embrace.android.embracesdk.testcases
import android.os.Build.VERSION_CODES.TIRAMISU
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.Embrace.AppFramework
import io.embrace.android.embracesdk.Embrace.LastRunEndState
import io.embrace.android.embracesdk.IntegrationTestRule
import io.embrace.android.embracesdk.fakes.fakeNetworkSpanForwardingBehavior
import io.embrace.android.embracesdk.internal.config.remote.NetworkSpanForwardingRemoteConfig
Expand Down Expand Up @@ -126,6 +127,15 @@ internal class PublicApiTest {
}
}

@Test
fun `getLastRunEndState() behave as expected`() {
with(testRule) {
assertEquals(LastRunEndState.INVALID, embrace.lastRunEndState)
startSdk()
assertEquals(LastRunEndState.CLEAN_EXIT, embrace.lastRunEndState)
}
}

@Test
fun `ensure all generated W3C traceparent conforms to the expected format`() {
with(testRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public interface SdkStateApi {

public val currentSessionId: String?

public fun getLastRunEndState(): Embrace.LastRunEndState
public val lastRunEndState: Embrace.LastRunEndState
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,18 @@ internal class SdkStateApiDelegate(
return null
}

override fun getLastRunEndState(): Embrace.LastRunEndState = if (isStarted && crashVerifier != null) {
if (crashVerifier?.didLastRunCrash() == true) {
Embrace.LastRunEndState.CRASH
} else {
Embrace.LastRunEndState.CLEAN_EXIT
override val lastRunEndState: Embrace.LastRunEndState
get() {
return if (isStarted && crashVerifier != null) {
if (crashVerifier?.didLastRunCrash() == true) {
Embrace.LastRunEndState.CRASH
} else {
Embrace.LastRunEndState.CLEAN_EXIT
}
} else {
Embrace.LastRunEndState.INVALID
}
}
} else {
Embrace.LastRunEndState.INVALID
}

companion object {
private val appIdPattern: Pattern = Pattern.compile("^[A-Za-z0-9]{5}$")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.embrace.android.embracesdk.internal.api.delegate

import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.embrace.android.embracesdk.Embrace.LastRunEndState
import io.embrace.android.embracesdk.fakes.FakeEmbLogger
import io.embrace.android.embracesdk.fakes.FakeLogService
import io.embrace.android.embracesdk.fakes.FakePreferenceService
Expand Down Expand Up @@ -74,4 +75,10 @@ internal class SdkStateApiDelegateTest {
sessionIdTracker.sessionData = SessionData("test", true)
assertEquals("test", delegate.currentSessionId)
}

@Test
fun `last end state is invalid if SDK not enabled`() {
sdkCallChecker.started.set(false)
assertEquals(LastRunEndState.INVALID, delegate.lastRunEndState)
}
}

0 comments on commit dce909e

Please sign in to comment.