Skip to content

Commit

Permalink
Merge pull request #1523 from bugsnag/PLAT-7611/onsend-mazerunner-tests
Browse files Browse the repository at this point in the history
Mazerunner test for the OnSend callback
  • Loading branch information
lemnik authored Nov 24, 2021
2 parents 640d592 + 96bf0f0 commit 115eed7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
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"

0 comments on commit 115eed7

Please sign in to comment.