Skip to content

Commit 4e8cf0f

Browse files
authored
Implement fiam and fiamd Kotlin library. (#836)
* Implement fiam and fiamd Kotlin library.
1 parent 98afca2 commit 4e8cf0f

File tree

11 files changed

+383
-0
lines changed

11 files changed

+383
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
android.enableUnitTestBinaryResources=true
2+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
plugins {
16+
id 'firebase-library'
17+
id 'kotlin-android'
18+
}
19+
20+
firebaseLibrary {
21+
releaseWith project(':firebase-inappmessaging-display')
22+
publishJavadoc = false
23+
publishSources = true
24+
}
25+
26+
android {
27+
compileSdkVersion project.targetSdkVersion
28+
defaultConfig {
29+
minSdkVersion 16
30+
multiDexEnabled true
31+
targetSdkVersion project.targetSdkVersion
32+
versionName version
33+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
34+
}
35+
sourceSets {
36+
main.java.srcDirs += 'src/main/kotlin'
37+
test.java {
38+
srcDir 'src/test/kotlin'
39+
}
40+
}
41+
testOptions.unitTests.includeAndroidResources = true
42+
}
43+
44+
dependencies {
45+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
46+
47+
implementation project(':firebase-common')
48+
implementation project(':firebase-common:ktx')
49+
implementation project(':firebase-inappmessaging')
50+
implementation project(':firebase-inappmessaging-display')
51+
implementation 'androidx.annotation:annotation:1.1.0'
52+
53+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
54+
testImplementation 'junit:junit:4.12'
55+
testImplementation "com.google.truth:truth:$googleTruthVersion"
56+
testImplementation ("com.google.firebase:firebase-analytics:17.0.0") {
57+
exclude group: "com.google.firebase", module: "firebase-common"
58+
}
59+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.google.firebase.inappmessaging.display.ktx">
4+
<!--Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds-->
5+
<!--<uses-sdk android:minSdkVersion="14"/>-->
6+
<application>
7+
<service android:name="com.google.firebase.components.ComponentDiscoveryService" android:exported="false">
8+
<meta-data android:name="com.google.firebase.components:com.google.firebase.inappmessaging.display.ktx.FirebaseInAppMessagingDisplayKtxRegistrar"
9+
android:value="com.google.firebase.components.ComponentRegistrar" />
10+
</service>
11+
</application>
12+
</manifest>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.inappmessaging.display.ktx
16+
17+
import androidx.annotation.Keep
18+
import com.google.firebase.FirebaseApp
19+
import com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay
20+
import com.google.firebase.components.Component
21+
import com.google.firebase.components.ComponentRegistrar
22+
import com.google.firebase.ktx.Firebase
23+
import com.google.firebase.platforminfo.LibraryVersionComponent
24+
25+
/** Returns the [FirebaseInAppMessagingDisplay] instance of the default [FirebaseApp]. */
26+
val Firebase.inAppMessagingDisplay: FirebaseInAppMessagingDisplay
27+
get() = FirebaseInAppMessagingDisplay.getInstance()
28+
29+
internal const val LIBRARY_NAME: String = "fire-iamd-ktx"
30+
31+
/** @suppress */
32+
@Keep
33+
class FirebaseInAppMessagingDisplayKtxRegistrar : ComponentRegistrar {
34+
override fun getComponents(): List<Component<*>> =
35+
listOf(LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME))
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.inappmessaging.display.ktx
16+
17+
import com.google.common.truth.Truth.assertThat
18+
import com.google.firebase.FirebaseApp
19+
import com.google.firebase.FirebaseOptions
20+
import com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay
21+
import com.google.firebase.ktx.Firebase
22+
import com.google.firebase.ktx.app
23+
import com.google.firebase.ktx.initialize
24+
import com.google.firebase.platforminfo.UserAgentPublisher
25+
import org.junit.After
26+
import org.junit.Before
27+
import org.junit.Test
28+
import org.junit.runner.RunWith
29+
import org.robolectric.RobolectricTestRunner
30+
import org.robolectric.RuntimeEnvironment
31+
32+
const val APP_ID = "APP_ID"
33+
const val API_KEY = "API_KEY"
34+
35+
const val EXISTING_APP = "existing"
36+
37+
abstract class BaseTestCase {
38+
@Before
39+
fun setUp() {
40+
Firebase.initialize(
41+
RuntimeEnvironment.application,
42+
FirebaseOptions.Builder()
43+
.setApplicationId(APP_ID)
44+
.setApiKey(API_KEY)
45+
.setProjectId("123")
46+
.build()
47+
)
48+
49+
Firebase.initialize(
50+
RuntimeEnvironment.application,
51+
FirebaseOptions.Builder()
52+
.setApplicationId(APP_ID)
53+
.setApiKey(API_KEY)
54+
.setProjectId("123")
55+
.build(),
56+
EXISTING_APP
57+
)
58+
}
59+
60+
@After
61+
fun cleanUp() {
62+
FirebaseApp.clearInstancesForTest()
63+
}
64+
}
65+
66+
@RunWith(RobolectricTestRunner::class)
67+
class InAppMessagingDisplayTests : BaseTestCase() {
68+
69+
@Test
70+
fun `inAppMessagingDisplay should delegate to FirebaseInAppMessagingDisplay#getInstance()`() {
71+
assertThat(Firebase.inAppMessagingDisplay).isSameInstanceAs(FirebaseInAppMessagingDisplay.getInstance())
72+
}
73+
}
74+
75+
@RunWith(RobolectricTestRunner::class)
76+
class LibraryVersionTest : BaseTestCase() {
77+
@Test
78+
fun `library version should be registered with runtime`() {
79+
val publisher = Firebase.app.get(UserAgentPublisher::class.java)
80+
assertThat(publisher.userAgent).contains(LIBRARY_NAME)
81+
}
82+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
android.enableUnitTestBinaryResources=true
2+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
plugins {
16+
id 'firebase-library'
17+
id 'kotlin-android'
18+
}
19+
20+
firebaseLibrary {
21+
releaseWith project(':firebase-inappmessaging')
22+
publishJavadoc = false
23+
publishSources = true
24+
}
25+
26+
android {
27+
compileSdkVersion project.targetSdkVersion
28+
defaultConfig {
29+
minSdkVersion 16
30+
multiDexEnabled true
31+
targetSdkVersion project.targetSdkVersion
32+
versionName version
33+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
34+
}
35+
sourceSets {
36+
main.java.srcDirs += 'src/main/kotlin'
37+
test.java {
38+
srcDir 'src/test/kotlin'
39+
}
40+
}
41+
testOptions.unitTests.includeAndroidResources = true
42+
}
43+
44+
dependencies {
45+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
46+
47+
implementation project(':firebase-common')
48+
implementation project(':firebase-common:ktx')
49+
implementation project(':firebase-inappmessaging')
50+
implementation 'androidx.annotation:annotation:1.1.0'
51+
implementation 'com.google.android.gms:play-services-tasks:17.0.0'
52+
53+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
54+
testImplementation 'junit:junit:4.12'
55+
testImplementation "com.google.truth:truth:$googleTruthVersion"
56+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.google.firebase.inappmessaging.ktx">
4+
<!--Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds-->
5+
<!--<uses-sdk android:minSdkVersion="16"/>-->
6+
<application>
7+
<service android:name="com.google.firebase.components.ComponentDiscoveryService" android:exported="false">
8+
<meta-data android:name="com.google.firebase.components:com.google.firebase.inappmessaging.ktx.FirebaseInAppMessagingKtxRegistrar"
9+
android:value="com.google.firebase.components.ComponentRegistrar" />
10+
</service>
11+
</application>
12+
</manifest>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.inappmessaging.ktx
16+
17+
import androidx.annotation.Keep
18+
import com.google.firebase.FirebaseApp
19+
import com.google.firebase.inappmessaging.FirebaseInAppMessaging
20+
import com.google.firebase.components.Component
21+
import com.google.firebase.components.ComponentRegistrar
22+
23+
import com.google.firebase.ktx.Firebase
24+
import com.google.firebase.platforminfo.LibraryVersionComponent
25+
26+
/** Returns the [FirebaseInAppMessaging] instance of the default [FirebaseApp]. */
27+
val Firebase.inAppMessaging: FirebaseInAppMessaging
28+
get() = FirebaseInAppMessaging.getInstance()
29+
30+
internal const val LIBRARY_NAME: String = "fire-iam-ktx"
31+
32+
/** @suppress */
33+
@Keep
34+
class FirebaseInAppMessagingKtxRegistrar : ComponentRegistrar {
35+
override fun getComponents(): List<Component<*>> =
36+
listOf(LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME))
37+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.inappmessaging.ktx
16+
17+
import com.google.common.truth.Truth.assertThat
18+
import com.google.firebase.FirebaseApp
19+
import com.google.firebase.FirebaseOptions
20+
import com.google.firebase.inappmessaging.FirebaseInAppMessaging
21+
import com.google.firebase.ktx.Firebase
22+
import com.google.firebase.ktx.app
23+
import com.google.firebase.ktx.initialize
24+
import com.google.firebase.platforminfo.UserAgentPublisher
25+
import org.junit.After
26+
import org.junit.Before
27+
import org.junit.Test
28+
import org.junit.runner.RunWith
29+
import org.robolectric.RobolectricTestRunner
30+
import org.robolectric.RuntimeEnvironment
31+
32+
const val APP_ID = "APP_ID"
33+
const val API_KEY = "API_KEY"
34+
35+
const val EXISTING_APP = "existing"
36+
37+
abstract class BaseTestCase {
38+
@Before
39+
fun setUp() {
40+
Firebase.initialize(
41+
RuntimeEnvironment.application,
42+
FirebaseOptions.Builder()
43+
.setApplicationId(APP_ID)
44+
.setGcmSenderId("ic")
45+
.setApiKey(API_KEY)
46+
.setProjectId("123")
47+
.build()
48+
)
49+
50+
Firebase.initialize(
51+
RuntimeEnvironment.application,
52+
FirebaseOptions.Builder()
53+
.setApplicationId(APP_ID)
54+
.setApiKey(API_KEY)
55+
.setProjectId("123")
56+
.build(),
57+
EXISTING_APP
58+
)
59+
}
60+
61+
@After
62+
fun cleanUp() {
63+
FirebaseApp.clearInstancesForTest()
64+
}
65+
}
66+
67+
@RunWith(RobolectricTestRunner::class)
68+
class FirebaseInAppMessagingTests : BaseTestCase() {
69+
70+
@Test
71+
fun `inappmessaging should delegate to FirebaseInAppMessaging#getInstance()`() {
72+
assertThat(Firebase.inAppMessaging).isSameInstanceAs(FirebaseInAppMessaging.getInstance())
73+
}
74+
}
75+
76+
@RunWith(RobolectricTestRunner::class)
77+
class LibraryVersionTest : BaseTestCase() {
78+
@Test
79+
fun `library version should be registered with runtime`() {
80+
val publisher = Firebase.app.get(UserAgentPublisher::class.java)
81+
assertThat(publisher.userAgent).contains(LIBRARY_NAME)
82+
}
83+
}

0 commit comments

Comments
 (0)