Skip to content

Commit 0552fe9

Browse files
committed
add tests for component registrar
1 parent 97b0873 commit 0552fe9

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright 2025 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. 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 distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.firebase.ui.auth
16+
17+
import android.content.Context
18+
import android.content.pm.PackageManager
19+
import androidx.test.core.app.ApplicationProvider
20+
import com.google.common.truth.Truth.assertThat
21+
import org.junit.Before
22+
import org.junit.Test
23+
import org.junit.runner.RunWith
24+
import org.robolectric.RobolectricTestRunner
25+
import org.robolectric.annotation.Config
26+
27+
/**
28+
* Unit tests for [FirebaseUIComposeRegistrar] covering component registration
29+
* and AndroidManifest.xml configuration validation.
30+
*/
31+
@RunWith(RobolectricTestRunner::class)
32+
@Config(sdk = [28])
33+
class FirebaseUIComposeRegistrarTest {
34+
35+
private lateinit var context: Context
36+
private lateinit var registrar: FirebaseUIComposeRegistrar
37+
38+
@Before
39+
fun setUp() {
40+
context = ApplicationProvider.getApplicationContext()
41+
registrar = FirebaseUIComposeRegistrar()
42+
}
43+
44+
// =============================================================================================
45+
// Component Registration Tests
46+
// =============================================================================================
47+
48+
@Test
49+
fun `getComponents() returns exactly one component`() {
50+
val components = registrar.getComponents()
51+
52+
assertThat(components).hasSize(1)
53+
}
54+
55+
// =============================================================================================
56+
// AndroidManifest.xml Configuration Tests
57+
// =============================================================================================
58+
59+
@Test
60+
fun `ComponentDiscoveryService has correct meta-data for FirebaseUIComposeRegistrar`() {
61+
val packageInfo = context.packageManager.getPackageInfo(
62+
context.packageName,
63+
PackageManager.GET_SERVICES or PackageManager.GET_META_DATA
64+
)
65+
66+
val service = packageInfo.services?.find { serviceInfo ->
67+
serviceInfo.name == "com.google.firebase.components.ComponentDiscoveryService"
68+
}
69+
70+
assertThat(service).isNotNull()
71+
72+
val metaData = service?.metaData
73+
assertThat(metaData).isNotNull()
74+
75+
// Check the meta-data key contains the fully qualified class name
76+
val expectedMetaDataKey = "com.google.firebase.components:com.firebase.ui.auth.FirebaseUIComposeRegistrar"
77+
val metaDataValue = metaData?.getString(expectedMetaDataKey)
78+
79+
assertThat(metaDataValue).isEqualTo("com.google.firebase.components.ComponentRegistrar")
80+
}
81+
82+
// =============================================================================================
83+
// Class Metadata Tests
84+
// =============================================================================================
85+
86+
@Test
87+
fun `meta-data key matches actual class fully qualified name`() {
88+
// The expected meta-data key format used in AndroidManifest.xml
89+
val expectedMetaDataKey = "com.google.firebase.components:com.firebase.ui.auth.FirebaseUIComposeRegistrar"
90+
val actualClassName = FirebaseUIComposeRegistrar::class.java.name
91+
92+
// Extract the class name from the meta-data key (after the colon)
93+
val classNameInMetaData = expectedMetaDataKey.substringAfter(":")
94+
95+
assertThat(classNameInMetaData).isEqualTo(actualClassName)
96+
}
97+
98+
@Test
99+
fun `registrar implements ComponentRegistrar interface`() {
100+
val interfaces = FirebaseUIComposeRegistrar::class.java.interfaces
101+
102+
assertThat(interfaces.map { it.name }).contains("com.google.firebase.components.ComponentRegistrar")
103+
}
104+
}

0 commit comments

Comments
 (0)