-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
168 additions
and
5 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
sdk/src/androidTest/java/com/bugsnag/android/SessionTrackerStopResumeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.bugsnag.android | ||
|
||
import com.bugsnag.android.BugsnagTestUtils.generateClient | ||
import com.bugsnag.android.BugsnagTestUtils.generateConfiguration | ||
import com.bugsnag.android.BugsnagTestUtils.generateSessionStore | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertNotEquals | ||
import org.junit.Assert.assertNotNull | ||
import org.junit.Assert.assertNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class SessionTrackerStopResumeTest { | ||
|
||
private val configuration = generateConfiguration().also { | ||
it.autoCaptureSessions = false | ||
} | ||
private val sessionStore = generateSessionStore() | ||
private lateinit var tracker: SessionTracker | ||
|
||
@Before | ||
fun setUp() { | ||
tracker = SessionTracker(configuration, generateClient(), sessionStore) | ||
} | ||
|
||
/** | ||
* Verifies that a session can be resumed after it is stopped | ||
*/ | ||
@Test | ||
fun resumeFromStoppedSession() { | ||
tracker.startSession(false) | ||
val originalSession = tracker.currentSession | ||
assertNotNull(originalSession) | ||
|
||
tracker.stopSession() | ||
assertNull(tracker.currentSession) | ||
|
||
assertTrue(tracker.resumeSession()) | ||
assertEquals(originalSession, tracker.currentSession) | ||
} | ||
|
||
/** | ||
* Verifies that a new session is started when calling [SessionTracker.resumeSession], | ||
* if there is no stopped session | ||
*/ | ||
@Test | ||
fun resumeWithNoStoppedSession() { | ||
assertNull(tracker.currentSession) | ||
assertFalse(tracker.resumeSession()) | ||
assertNotNull(tracker.currentSession) | ||
} | ||
|
||
/** | ||
* Verifies that a new session can be created after the previous one is stopped | ||
*/ | ||
@Test | ||
fun startNewAfterStoppedSession() { | ||
tracker.startSession(false) | ||
val originalSession = tracker.currentSession | ||
|
||
tracker.stopSession() | ||
tracker.startSession(false) | ||
assertNotEquals(originalSession, tracker.currentSession) | ||
} | ||
|
||
/** | ||
* Verifies that calling [SessionTracker.resumeSession] multiple times only starts one session | ||
*/ | ||
@Test | ||
fun multipleResumesHaveNoEffect() { | ||
tracker.startSession(false) | ||
val original = tracker.currentSession | ||
tracker.stopSession() | ||
|
||
assertTrue(tracker.resumeSession()) | ||
assertEquals(original, tracker.currentSession) | ||
|
||
assertFalse(tracker.resumeSession()) | ||
assertEquals(original, tracker.currentSession) | ||
} | ||
|
||
/** | ||
* Verifies that calling [SessionTracker.stopSession] multiple times only stops one session | ||
*/ | ||
@Test | ||
fun multipleStopsHaveNoEffect() { | ||
tracker.startSession(false) | ||
assertNotNull(tracker.currentSession) | ||
|
||
tracker.stopSession() | ||
assertNull(tracker.currentSession) | ||
|
||
tracker.stopSession() | ||
assertNull(tracker.currentSession) | ||
} | ||
|
||
/** | ||
* Verifies that if a handled or unhandled error occurs when a session is stopped, the | ||
* error count is not updated | ||
*/ | ||
@Test | ||
fun stoppedSessionDoesNotIncrement() { | ||
tracker.startSession(false) | ||
tracker.incrementHandledError() | ||
tracker.incrementUnhandledError() | ||
assertEquals(1, tracker.currentSession?.handledCount) | ||
assertEquals(1, tracker.currentSession?.unhandledCount) | ||
|
||
tracker.stopSession() | ||
tracker.incrementHandledError() | ||
tracker.incrementUnhandledError() | ||
tracker.resumeSession() | ||
assertEquals(1, tracker.currentSession?.handledCount) | ||
assertEquals(1, tracker.currentSession?.unhandledCount) | ||
|
||
tracker.incrementHandledError() | ||
tracker.incrementUnhandledError() | ||
assertEquals(2, tracker.currentSession?.handledCount) | ||
assertEquals(2, tracker.currentSession?.unhandledCount) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters