Skip to content

Commit

Permalink
feat: rearrange leaveBreadcrumb param
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Mar 10, 2020
1 parent 96a40e1 commit c63c9f4
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void testLeaveStringBreadcrumbDirectlySendsMessage() {

@Test
public void testLeaveBreadcrumbSendsMessage() {
client.leaveBreadcrumb("Rollback", BreadcrumbType.LOG, new HashMap<String, Object>());
client.leaveBreadcrumb("Rollback", new HashMap<String, Object>(), BreadcrumbType.LOG);
StateEvent.AddBreadcrumb crumb = findMessageInQueue(StateEvent.AddBreadcrumb.class);
assertEquals(BreadcrumbType.LOG, crumb.getType());
assertEquals("Rollback", crumb.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.junit.Before;
import org.junit.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -110,7 +109,7 @@ public boolean onBreadcrumb(@NonNull Breadcrumb breadcrumb) {
});

client.leaveBreadcrumb("Foo");
client.leaveBreadcrumb("Hello", BreadcrumbType.USER, new HashMap<String, Object>());
client.leaveBreadcrumb("Hello", new HashMap<String, Object>(), BreadcrumbType.USER);
assertEquals(5, count[0]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,14 @@ public static void leaveBreadcrumb(@NonNull String message) {
/**
* Leave a "breadcrumb" log message representing an action or event which
* occurred in your app, to aid with debugging
*
* @param message A short label
* @param type A category for the breadcrumb
* @param metadata Additional diagnostic information about the app environment
* @param type A category for the breadcrumb
*/
public static void leaveBreadcrumb(@NonNull String message,
@NonNull BreadcrumbType type,
@NonNull Map<String, Object> metadata) {
getClient().leaveBreadcrumb(message, type, metadata);
@NonNull Map<String, Object> metadata,
@NonNull BreadcrumbType type) {
getClient().leaveBreadcrumb(message, metadata, type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public Unit invoke(Boolean hasConnection, String networkState) {
@SuppressWarnings("unchecked")
@Override
public Unit invoke(String activity, Map<String, ?> metadata) {
leaveBreadcrumb(activity, BreadcrumbType.STATE,
(Map<String, Object>) metadata);
leaveBreadcrumb(activity, (Map<String, Object>) metadata,
BreadcrumbType.STATE);
return null;
}
}
Expand Down Expand Up @@ -798,14 +798,13 @@ public void leaveBreadcrumb(@NonNull String message) {
/**
* Leave a "breadcrumb" log message representing an action or event which
* occurred in your app, to aid with debugging
*
* @param message A short label
* @param type A category for the breadcrumb
* @param metadata Additional diagnostic information about the app environment
* @param type A category for the breadcrumb
*/
public void leaveBreadcrumb(@NonNull String message,
@NonNull BreadcrumbType type,
@NonNull Map<String, Object> metadata) {
@NonNull Map<String, Object> metadata,
@NonNull BreadcrumbType type) {
if (message != null && type != null && metadata != null) {
breadcrumbState.add(new Breadcrumb(message, type, metadata, new Date(), logger));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

/**
* Used as the entry point for native code to allow proguard to obfuscate other areas if needed
Expand Down Expand Up @@ -181,7 +180,7 @@ public static void leaveBreadcrumb(@NonNull final String name,
if (name == null) {
return;
}
getClient().leaveBreadcrumb(name, type, new HashMap<String, Object>());
getClient().leaveBreadcrumb(name, new HashMap<String, Object>(), type);
}

/**
Expand All @@ -193,7 +192,7 @@ public static void leaveBreadcrumb(@NonNull final byte[] nameBytes,
return;
}
String name = new String(nameBytes, UTF8Charset);
getClient().leaveBreadcrumb(name, type, new HashMap<String, Object>());
getClient().leaveBreadcrumb(name, new HashMap<String, Object>(), type);
}

/**
Expand All @@ -203,7 +202,7 @@ public static void leaveBreadcrumb(@NonNull String message,
@NonNull String type,
@NonNull Map<String, Object> metadata) {
String typeName = type.toUpperCase(Locale.US);
getClient().leaveBreadcrumb(message, BreadcrumbType.valueOf(typeName), metadata);
getClient().leaveBreadcrumb(message, metadata, BreadcrumbType.valueOf(typeName));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void onReceive(@NonNull Context context, @NonNull Intent intent) {
if (type == null) {
type = BreadcrumbType.STATE;
}
client.leaveBreadcrumb(shortAction, type, meta);
client.leaveBreadcrumb(shortAction, meta, type);

} catch (Exception ex) {
logger.w("Failed to leave breadcrumb in SystemBroadcastReceiver: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ class BugsnagApiTest {

@Test
fun leaveBreadcrumb1() {
Bugsnag.leaveBreadcrumb("whoops", BreadcrumbType.LOG, mapOf())
verify(client, times(1)).leaveBreadcrumb("whoops", BreadcrumbType.LOG, mapOf())
Bugsnag.leaveBreadcrumb("whoops", mapOf(), BreadcrumbType.LOG)
verify(client, times(1)).leaveBreadcrumb("whoops", mapOf(), BreadcrumbType.LOG)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import org.mockito.junit.MockitoJUnitRunner;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -439,27 +437,27 @@ public void leaveBreadcrumbInvalid() {
@Test
public void leaveComplexBreadcrumbValid() {
HashMap<String, Object> metadata = new HashMap<>();
client.leaveBreadcrumb("foo", BreadcrumbType.NAVIGATION, metadata);
client.leaveBreadcrumb("foo", metadata, BreadcrumbType.NAVIGATION);
verify(breadcrumbState, times(1)).add(any(Breadcrumb.class));
}

@Test
public void leaveComplexBreadcrumbInvalid1() {
HashMap<String, Object> metadata = new HashMap<>();
client.leaveBreadcrumb(null, BreadcrumbType.NAVIGATION, metadata);
client.leaveBreadcrumb(null, metadata, BreadcrumbType.NAVIGATION);
verify(breadcrumbState, times(0)).add(any(Breadcrumb.class));
}

@Test
public void leaveComplexBreadcrumbInvalid2() {
HashMap<String, Object> metadata = new HashMap<>();
client.leaveBreadcrumb("foo", null, metadata);
client.leaveBreadcrumb("foo", metadata, null);
verify(breadcrumbState, times(0)).add(any(Breadcrumb.class));
}

@Test
public void leaveComplexBreadcrumbInvalid3() {
client.leaveBreadcrumb("foo", BreadcrumbType.NAVIGATION, null);
client.leaveBreadcrumb("foo", null, BreadcrumbType.NAVIGATION);
verify(breadcrumbState, times(0)).add(any(Breadcrumb.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ internal class NativeInterfaceApiTest {
@Test
fun leaveBreadcrumb() {
NativeInterface.leaveBreadcrumb("wow", BreadcrumbType.LOG)
verify(client, times(1)).leaveBreadcrumb("wow", BreadcrumbType.LOG, emptyMap())
verify(client, times(1)).leaveBreadcrumb("wow", emptyMap(), BreadcrumbType.LOG)
}

@Test
fun leaveBreadcrumbMetadata() {
NativeInterface.leaveBreadcrumb("wow", "log", mapOf(Pair("foo", "bar")))
verify(client, times(1)).leaveBreadcrumb(
"wow",
BreadcrumbType.LOG,
mapOf(Pair("foo", "bar"))
mapOf(Pair("foo", "bar")),
BreadcrumbType.LOG
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SystemBroadcastReceiverTest {
receiver.onReceive(context, intent)

val metadata = mapOf(Pair("Intent Action", "android.intent.action.AIRPLANE_MODE"))
verify(client, times(1)).leaveBreadcrumb("AIRPLANE_MODE", BreadcrumbType.STATE, metadata)
verify(client, times(1)).leaveBreadcrumb("AIRPLANE_MODE", metadata, BreadcrumbType.STATE)
}

@Test
Expand All @@ -51,7 +51,7 @@ class SystemBroadcastReceiverTest {
receiver.onReceive(context, intent)

val metadata = mapOf(Pair("Intent Action", "SomeTitle"), Pair("foo", "[bar]"))
verify(client, times(1)).leaveBreadcrumb("SomeTitle", BreadcrumbType.STATE, metadata)
verify(client, times(1)).leaveBreadcrumb("SomeTitle", metadata, BreadcrumbType.STATE)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class BugsnagReactNativePlugin : Plugin {
val type = BreadcrumbType.valueOf((map["type"] as String).toUpperCase(Locale.US))
val obj = map["metadata"] ?: emptyMap<String, Any>()
@Suppress("UNCHECKED_CAST")
client.leaveBreadcrumb(msg, type, obj as Map<String, Any>)
client.leaveBreadcrumb(msg, obj as Map<String, Any>, type)
}

fun startSession() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class LeaveBreadcrumbTest {

verify(client, times(1)).leaveBreadcrumb(
eq("JS: invoked API"),
eq(BreadcrumbType.REQUEST),
eq(metadata)
eq(metadata),
eq(BreadcrumbType.REQUEST)
)
}

Expand All @@ -57,8 +57,8 @@ class LeaveBreadcrumbTest {

verify(client, times(1)).leaveBreadcrumb(
eq("JS: invoked API"),
eq(BreadcrumbType.REQUEST),
eq(emptyMap())
eq(emptyMap()),
eq(BreadcrumbType.REQUEST)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class BreadcrumbScenario(config: Configuration,
super.run()
Bugsnag.leaveBreadcrumb("Hello Breadcrumb!")
val data = Collections.singletonMap("Foo", "Bar" as Any)
Bugsnag.leaveBreadcrumb("Another Breadcrumb", BreadcrumbType.USER, data)
Bugsnag.leaveBreadcrumb("Another Breadcrumb", data, BreadcrumbType.USER)
Bugsnag.notify(generateException())
}

Expand Down

0 comments on commit c63c9f4

Please sign in to comment.