Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mazerunner test for the OnSend callback #1523

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ID>TooGenericExceptionThrown:CrashHandlerScenario.kt$CrashHandlerScenario$throw RuntimeException("CrashHandlerScenario")</ID>
<ID>TooGenericExceptionThrown:CustomHttpClientFlushScenario.kt$CustomHttpClientFlushScenario$throw RuntimeException("ReportCacheScenario")</ID>
<ID>TooGenericExceptionThrown:DisableAutoDetectErrorsScenario.kt$DisableAutoDetectErrorsScenario$throw RuntimeException("Should never appear")</ID>
<ID>TooGenericExceptionThrown:OnSendCallbackScenario.kt$OnSendCallbackScenario$throw RuntimeException("Unhandled Error")</ID>
<ID>TooGenericExceptionThrown:ReportCacheScenario.kt$ReportCacheScenario$throw RuntimeException("ReportCacheScenario")</ID>
<ID>TooGenericExceptionThrown:StartupCrashFlushScenario.kt$StartupCrashFlushScenario$throw RuntimeException("Regular crash")</ID>
<ID>TooGenericExceptionThrown:StartupCrashFlushScenario.kt$StartupCrashFlushScenario$throw RuntimeException("Startup crash")</ID>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.bugsnag.android;

import java.util.Collections;

public class TestOnSendCallback implements OnSendCallback {
@Override
public boolean onSend(Event event) {
event.addMetadata("mazerunner", Collections.singletonMap("onSendCallback", "true"));
return true;
}

public void register(Configuration config) {
config.addOnSend(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Configuration
import com.bugsnag.android.TestOnSendCallback
import java.lang.RuntimeException

internal class OnSendCallbackScenario(
config: Configuration,
context: Context,
eventMetadata: String
) : Scenario(config, context, eventMetadata) {
override fun startBugsnag(startBugsnagOnly: Boolean) {
TestOnSendCallback().register(config)
super.startBugsnag(startBugsnagOnly)
}

override fun startScenario() {
super.startScenario()

if (eventMetadata != "start-only") {
throw RuntimeException("Unhandled Error")
}
}
}
10 changes: 10 additions & 0 deletions features/full_tests/onsend_callback.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: OnSend Callbacks can alter Events before upload

Scenario: Handled exception with altered by OnSendCallback
When I run "OnSendCallbackScenario" and relaunch the app
And I configure the app to run in the "start-only" state
And I configure Bugsnag for "OnSendCallbackScenario"
Then I wait to receive an error
And the error payload field "events" is an array with 1 elements
And the exception "message" equals "Unhandled Error"
And the event "metaData.mazerunner.onSendCallback" equals "true"