Skip to content

Commit

Permalink
remove kotlin setOf() and replace it with HashSet<>() + add()
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanosiano committed Oct 17, 2024
1 parent 9182d86 commit cce1fd2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FragmentLifecycleIntegration(

constructor(application: Application) : this(
application = application,
filterFragmentLifecycleBreadcrumbs = FragmentLifecycleState.values().toSet(),
filterFragmentLifecycleBreadcrumbs = FragmentLifecycleState.states,
enableAutoFragmentLifecycleTracing = false
)

Expand All @@ -34,7 +34,7 @@ class FragmentLifecycleIntegration(
enableAutoFragmentLifecycleTracing: Boolean
) : this(
application = application,
filterFragmentLifecycleBreadcrumbs = FragmentLifecycleState.values().toSet()
filterFragmentLifecycleBreadcrumbs = FragmentLifecycleState.states
.takeIf { enableFragmentLifecycleBreadcrumbs }
.orEmpty(),
enableAutoFragmentLifecycleTracing = enableAutoFragmentLifecycleTracing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,21 @@ enum class FragmentLifecycleState(internal val breadcrumbName: String) {
STOPPED("stopped"),
VIEW_DESTROYED("view destroyed"),
DESTROYED("destroyed"),
DETACHED("detached")
DETACHED("detached");

companion object {
val states = HashSet<FragmentLifecycleState>().apply {
add(ATTACHED)
add(SAVE_INSTANCE_STATE)
add(CREATED)
add(VIEW_CREATED)
add(STARTED)
add(RESUMED)
add(PAUSED)
add(STOPPED)
add(VIEW_DESTROYED)
add(DESTROYED)
add(DETACHED)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SentryFragmentLifecycleCallbacks(
enableAutoFragmentLifecycleTracing: Boolean
) : this(
hub = hub,
filterFragmentLifecycleBreadcrumbs = FragmentLifecycleState.values().toSet()
filterFragmentLifecycleBreadcrumbs = FragmentLifecycleState.states
.takeIf { enableFragmentLifecycleBreadcrumbs }
.orEmpty(),
enableAutoFragmentLifecycleTracing = enableAutoFragmentLifecycleTracing
Expand All @@ -42,7 +42,7 @@ class SentryFragmentLifecycleCallbacks(
enableAutoFragmentLifecycleTracing: Boolean = false
) : this(
hub = HubAdapter.getInstance(),
filterFragmentLifecycleBreadcrumbs = FragmentLifecycleState.values().toSet()
filterFragmentLifecycleBreadcrumbs = FragmentLifecycleState.states
.takeIf { enableFragmentLifecycleBreadcrumbs }
.orEmpty(),
enableAutoFragmentLifecycleTracing = enableAutoFragmentLifecycleTracing
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.sentry.android.fragment

import kotlin.test.Test
import kotlin.test.assertEquals

class FragmentLifecycleStateTest {
@Test
fun `states contains all states`() {
assertEquals(FragmentLifecycleState.states, FragmentLifecycleState.values().toSet())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SentryFragmentLifecycleCallbacksTest {
val span = mock<ISpan>()

fun getSut(
loggedFragmentLifecycleStates: Set<FragmentLifecycleState> = FragmentLifecycleState.values().toSet(),
loggedFragmentLifecycleStates: Set<FragmentLifecycleState> = FragmentLifecycleState.states,
enableAutoFragmentLifecycleTracing: Boolean = false,
tracesSampleRate: Double? = 1.0,
isAdded: Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ import kotlin.LazyThreadSafetyMode.NONE
public open class DefaultReplayBreadcrumbConverter : ReplayBreadcrumbConverter {
internal companion object {
private val snakecasePattern by lazy(NONE) { "_[a-z]".toRegex() }
private val supportedNetworkData by lazy(NONE) {
setOf(
"status_code",
"method",
"response_content_length",
"request_content_length",
"http.response_content_length",
"http.request_content_length"
)
private val supportedNetworkData = HashSet<String>().apply {
add("status_code")
add("method")
add("response_content_length")
add("request_content_length")
add("http.response_content_length")
add("http.request_content_length")
}
}

Expand Down

0 comments on commit cce1fd2

Please sign in to comment.