File tree Expand file tree Collapse file tree 3 files changed +63
-12
lines changed
main/kotlin/com/google/firebase/sessions
test/kotlin/com/google/firebase/sessions Expand file tree Collapse file tree 3 files changed +63
-12
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,6 @@ import androidx.annotation.Discouraged
22
22
import com.google.firebase.FirebaseApp
23
23
import com.google.firebase.ktx.Firebase
24
24
import com.google.firebase.ktx.app
25
- import com.google.firebase.sessions.EventType.SESSION_START
26
25
27
26
class FirebaseSessions internal constructor(firebaseApp : FirebaseApp ) {
28
27
private val sessionGenerator = SessionGenerator (collectEvents = true )
@@ -42,16 +41,7 @@ class FirebaseSessions internal constructor(firebaseApp: FirebaseApp) {
42
41
43
42
private fun initiateSessionStart () {
44
43
val sessionState = sessionGenerator.generateNewSession()
45
- val sessionEvent =
46
- SessionEvent (
47
- eventType = SESSION_START ,
48
- sessionData =
49
- SessionInfo (
50
- sessionState.sessionId,
51
- sessionState.firstSessionId,
52
- sessionState.sessionIndex
53
- ),
54
- )
44
+ val sessionEvent = SessionEvent .sessionStart(sessionState)
55
45
56
46
Log .i(TAG , " Initiate session start: $sessionEvent " )
57
47
}
Original file line number Diff line number Diff line change @@ -29,7 +29,20 @@ internal data class SessionEvent(
29
29
30
30
/* * Information about the session triggering the event. */
31
31
val sessionData : SessionInfo ,
32
- )
32
+ ) {
33
+ companion object {
34
+ fun sessionStart (sessionState : SessionState ) =
35
+ SessionEvent (
36
+ eventType = EventType .SESSION_START ,
37
+ sessionData =
38
+ SessionInfo (
39
+ sessionState.sessionId,
40
+ sessionState.firstSessionId,
41
+ sessionState.sessionIndex,
42
+ ),
43
+ )
44
+ }
45
+ }
33
46
34
47
/* * Enum denoting all possible session event types. */
35
48
internal enum class EventType (val number : Int ) {
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2023 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com.google.firebase.sessions
18
+
19
+ import com.google.common.truth.Truth.assertThat
20
+ import org.junit.Test
21
+
22
+ class SessionEventTest {
23
+ @Test
24
+ fun sessionStart_populatesSessionStateCorrectly () {
25
+ val sessionState =
26
+ SessionState (
27
+ sessionId = " a1b2c3" ,
28
+ firstSessionId = " a1a1a1" ,
29
+ collectEvents = true ,
30
+ sessionIndex = 3 ,
31
+ )
32
+
33
+ val sessionEvent = SessionEvent .sessionStart(sessionState)
34
+
35
+ assertThat(sessionEvent)
36
+ .isEqualTo(
37
+ SessionEvent (
38
+ eventType = EventType .SESSION_START ,
39
+ sessionData =
40
+ SessionInfo (
41
+ sessionId = " a1b2c3" ,
42
+ firstSessionId = " a1a1a1" ,
43
+ sessionIndex = 3 ,
44
+ )
45
+ )
46
+ )
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments