Skip to content

Commit 7f73bcf

Browse files
committed
chore: upgrade mockito, fix: spying mocked objects in new library
1 parent 76923bc commit 7f73bcf

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

auth/build.gradle.kts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ dependencies {
9191
implementation(Config.Libs.Androidx.fragment)
9292
implementation(Config.Libs.Androidx.customTabs)
9393
implementation(Config.Libs.Androidx.constraint)
94-
implementation("androidx.credentials:credentials:1.3.0")
94+
implementation(libs.androidx.credentials)
9595
implementation("androidx.credentials:credentials-play-services-auth:1.3.0")
9696

9797
implementation(Config.Libs.Androidx.lifecycleExtensions)
@@ -112,12 +112,27 @@ dependencies {
112112

113113
testImplementation(Config.Libs.Test.junit)
114114
testImplementation(Config.Libs.Test.truth)
115-
testImplementation(Config.Libs.Test.mockito)
116115
testImplementation(Config.Libs.Test.core)
117116
testImplementation(Config.Libs.Test.robolectric)
118117
testImplementation(Config.Libs.Test.kotlinReflect)
119118
testImplementation(Config.Libs.Provider.facebook)
120119
testImplementation(libs.androidx.ui.test.junit4)
120+
testImplementation(libs.mockito)
121+
testImplementation(libs.mockito.inline)
122+
testImplementation(libs.mockito.kotlin)
123+
testImplementation(libs.androidx.credentials)
121124

122125
debugImplementation(project(":internal:lintchecks"))
123126
}
127+
128+
val mockitoAgent by configurations.creating
129+
130+
dependencies {
131+
mockitoAgent(libs.mockito) {
132+
isTransitive = false
133+
}
134+
}
135+
136+
tasks.withType<Test>().configureEach {
137+
jvmArgs("-javaagent:${mockitoAgent.asPath}")
138+
}

auth/src/test/java/com/firebase/ui/auth/testhelpers/TestHelper.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,17 @@ public static void initialize() {
7575
}
7676

7777
private static void spyContextAndResources() {
78-
CONTEXT = spy(CONTEXT);
78+
// In Mockito 5.x, we need to avoid spying on objects that are already mocks/spies
79+
if (!org.mockito.Mockito.mockingDetails(CONTEXT).isSpy()) {
80+
CONTEXT = spy(CONTEXT);
81+
}
7982
when(CONTEXT.getApplicationContext())
8083
.thenReturn(CONTEXT);
81-
Resources spiedResources = spy(CONTEXT.getResources());
82-
when(CONTEXT.getResources()).thenReturn(spiedResources);
84+
Resources resources = CONTEXT.getResources();
85+
if (!org.mockito.Mockito.mockingDetails(resources).isSpy()) {
86+
Resources spiedResources = spy(resources);
87+
when(CONTEXT.getResources()).thenReturn(spiedResources);
88+
}
8389
}
8490

8591
private static void initializeApp(Context context) {

gradle/libs.versions.toml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
[versions]
2-
datastorePreferences = "1.1.1"
32
kotlin = "2.2.0"
3+
4+
# Compose
45
androidxComposeBom = "2025.08.00"
56
androidxActivityCompose = "1.9.0"
67

8+
# Authentication
9+
credentials = "1.3.0"
10+
11+
# Storage
12+
datastorePreferences = "1.1.1"
13+
14+
# Testing
15+
mockito = "5.19.0"
16+
mockitoInline = "5.2.0"
17+
mockitoKotlin = "6.0.0"
18+
719
[libraries]
820
# Compose
921
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidxComposeBom" }
@@ -16,11 +28,17 @@ androidx-compose-material3 = { group = "androidx.compose.material3", name = "mat
1628
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidxActivityCompose" }
1729
androidx-compose-material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended" }
1830

31+
# Authentication
32+
androidx-credentials = { module = "androidx.credentials:credentials", version.ref = "credentials" }
33+
1934
# Storage
2035
androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastorePreferences" }
2136

2237
# Testing
2338
androidx-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" }
39+
mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" }
40+
mockito-inline = { module = "org.mockito:mockito-inline", version.ref = "mockitoInline" }
41+
mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version.ref = "mockitoKotlin" }
2442

2543
[plugins]
2644
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

0 commit comments

Comments
 (0)