Skip to content

Commit

Permalink
add manual/auto context scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Mar 1, 2018
1 parent 9545c4f commit c503f90
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
10 changes: 10 additions & 0 deletions features/auto_context.feature
@@ -0,0 +1,10 @@
Feature: Android support

Scenario: Automatic Context Tracking
When I run "AutoContextScenario" with the defaults
And I wait for 3 seconds
Then I should receive a request
And the request is a valid for the error reporting API
And the "Bugsnag-API-Key" header equals "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the exception "message" equals "AutoContextScenario"
And the event "context" equals "SecondActivity"
9 changes: 9 additions & 0 deletions features/manual_context.feature
@@ -0,0 +1,9 @@
Feature: Android support

Scenario: Manual Context Tracking
When I run "ManualContextScenario" with the defaults
Then I should receive a request
And the request is a valid for the error reporting API
And the "Bugsnag-API-Key" header equals "a35a2a72bd230ac0aa0f52715bbdc6aa"
And the exception "message" equals "ManualContextScenario"
And the event "context" equals "FooContext"
1 change: 1 addition & 0 deletions mazerunner/src/main/AndroidManifest.xml
Expand Up @@ -11,6 +11,7 @@

</intent-filter>
</activity>
<activity android:name=".SecondActivity"/>
</application>

</manifest>
@@ -0,0 +1,13 @@
package com.bugsnag.android.mazerunner

import android.app.Activity
import android.os.Bundle

class SecondActivity : Activity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}

}
@@ -0,0 +1,26 @@
package com.bugsnag.android.mazerunner.scenarios

import android.app.Activity
import android.content.Context
import android.content.Intent
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import com.bugsnag.android.mazerunner.SecondActivity

/**
* Sends a handled exception to Bugsnag, which includes automatic context.
*/
internal class AutoContextScenario(config: Configuration,
context: Context) : Scenario(config, context) {

override fun run() {
super.run()
context.startActivity(Intent(context, SecondActivity::class.java))

val a = context as Activity
a.window.decorView.postDelayed({
Bugsnag.notify(generateException())
}, 2000)
}

}
@@ -0,0 +1,20 @@
package com.bugsnag.android.mazerunner.scenarios

import android.content.Context
import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import com.bugsnag.android.mazerunner.scenarios.Scenario

/**
* Sends a handled exception to Bugsnag, which includes manual context.
*/
internal class ManualContextScenario(config: Configuration,
context: Context) : Scenario(config, context) {

override fun run() {
super.run()
Bugsnag.setContext("FooContext")
Bugsnag.notify(generateException())
}

}

0 comments on commit c503f90

Please sign in to comment.