Skip to content

Commit

Permalink
Merge ae29ffc into 71ceb1b
Browse files Browse the repository at this point in the history
  • Loading branch information
tejasd authored Dec 5, 2024
2 parents 71ceb1b + ae29ffc commit c74729b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion firebase-crashlytics/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ package com.google.firebase.crashlytics {

public final class FirebaseCrashlyticsKt {
method @NonNull public static com.google.firebase.crashlytics.FirebaseCrashlytics getCrashlytics(@NonNull com.google.firebase.Firebase);
method public static void recordException(@NonNull com.google.firebase.crashlytics.FirebaseCrashlytics, @NonNull Throwable throwable, @NonNull kotlin.jvm.functions.Function1<? super com.google.firebase.crashlytics.KeyValueBuilder,kotlin.Unit> init);
method public static void setCustomKeys(@NonNull com.google.firebase.crashlytics.FirebaseCrashlytics, @NonNull kotlin.jvm.functions.Function1<? super com.google.firebase.crashlytics.KeyValueBuilder,kotlin.Unit> init);
}

public final class KeyValueBuilder {
ctor public KeyValueBuilder(@NonNull com.google.firebase.crashlytics.FirebaseCrashlytics crashlytics);
ctor @Deprecated public KeyValueBuilder(@NonNull com.google.firebase.crashlytics.FirebaseCrashlytics crashlytics);
method public void key(@NonNull String key, boolean value);
method public void key(@NonNull String key, double value);
method public void key(@NonNull String key, float value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,36 @@ class CrashlyticsTests {
@Test
fun keyValueBuilder() {
val keyValueBuilder = KeyValueBuilder()
keyValueBuilder.key("hello", "world")
keyValueBuilder.key("hello2", 23)
keyValueBuilder.key("hello3", 0.1)
keyValueBuilder.key("string", "world")
keyValueBuilder.key("int", Int.MAX_VALUE)
keyValueBuilder.key("float", Float.MAX_VALUE)
keyValueBuilder.key("boolean", true)
keyValueBuilder.key("double", Double.MAX_VALUE)
keyValueBuilder.key("long", Long.MAX_VALUE)

val result: Map<String, String> = keyValueBuilder.build().keysAndValues

assertThat(result).containsExactly("hello", "world", "hello2", "23", "hello3", "0.1")
val expectedKeys =
mapOf(
"string" to "world",
"int" to "${Int.MAX_VALUE}",
"float" to "${Float.MAX_VALUE}",
"boolean" to "${true}",
"double" to "${Double.MAX_VALUE}",
"long" to "${Long.MAX_VALUE}"
)
assertThat(result).isEqualTo(expectedKeys)
}

@Test
fun keyValueBuilder_withCrashlyticsInstance() {
@Suppress("DEPRECATION") val keyValueBuilder = KeyValueBuilder(Firebase.crashlytics)
keyValueBuilder.key("hello", "world")
keyValueBuilder.key("hello2", 23)
keyValueBuilder.key("hello3", 0.1)
keyValueBuilder.key("string", "world")
keyValueBuilder.key("int", Int.MAX_VALUE)
keyValueBuilder.key("float", Float.MAX_VALUE)
keyValueBuilder.key("boolean", true)
keyValueBuilder.key("double", Double.MAX_VALUE)
keyValueBuilder.key("long", Long.MAX_VALUE)

val result: Map<String, String> = keyValueBuilder.build().keysAndValues

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ val Firebase.crashlytics: FirebaseCrashlytics
fun FirebaseCrashlytics.setCustomKeys(init: KeyValueBuilder.() -> Unit) =
setCustomKeys(KeyValueBuilder().apply(init).build())

/** Records a non-fatal report to send to Crashlytics with additional custom keys */
fun FirebaseCrashlytics.recordException(throwable: Throwable, init: KeyValueBuilder.() -> Unit) =
recordException(throwable, KeyValueBuilder().apply(init).build())

/** @suppress */
@Keep
internal class FirebaseCrashlyticsKtxRegistrar : ComponentRegistrar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.firebase.crashlytics

/** Helper class to enable convenient syntax in [setCustomKeys] */
/** Helper class to enable convenient syntax in [setCustomKeys] and [recordException] */
class KeyValueBuilder
private constructor(
private val crashlytics: FirebaseCrashlytics?,
Expand Down

0 comments on commit c74729b

Please sign in to comment.