Skip to content

Commit 348041f

Browse files
committed
Refactor SwitchBrowserActivityTest to use an inline IFlightsManager for deterministic flight behavior across environments, replacing the previous MockCommonFlightsManager implementation.
1 parent 0490511 commit 348041f

1 file changed

Lines changed: 36 additions & 22 deletions

File tree

common/src/test/java/com/microsoft/identity/common/internal/providers/oauth2/SwitchBrowserActivityTest.kt

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import android.content.Context
2626
import android.content.Intent
2727
import com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker
2828
import com.microsoft.identity.common.adal.internal.AuthenticationConstants.SWITCH_BROWSER
29-
import com.microsoft.identity.common.internal.mocks.MockCommonFlightsManager
3029
import com.microsoft.identity.common.java.flighting.CommonFlightsManager
3130
import com.microsoft.identity.common.java.flighting.IFlightConfig
31+
import com.microsoft.identity.common.java.flighting.IFlightsManager
3232
import com.microsoft.identity.common.java.flighting.IFlightsProvider
3333
import io.mockk.every
3434
import io.mockk.just
@@ -60,13 +60,14 @@ class SwitchBrowserActivityTest {
6060
// CommonFlight.ENABLE_AUTH_TAB_FOR_SWITCH_BROWSER. Its default value is environment-
6161
// dependent (true on a developer machine where it has been initialized, false in CI
6262
// where the DefaultValueFlightsProvider returns the flight's default — which is false
63-
// for any feature still rolling out). Force it ON here via the shared
64-
// MockCommonFlightsManager helper so the Auth Tab branch is exercised deterministically
65-
// across local and pipeline runs.
66-
val flightsManager = MockCommonFlightsManager().apply {
67-
setMockCommonFlightsProvider(AllOnFlightsProvider)
68-
}
69-
CommonFlightsManager.initializeCommonFlightsManager(flightsManager)
63+
// for any feature still rolling out). Force it ON here so the Auth Tab branch is
64+
// exercised deterministically across local and pipeline runs.
65+
//
66+
// Note: We can't reuse the existing MockCommonFlightsManager helper here because its
67+
// setter is generated by Lombok at Java-compile time, which runs after kotlinc — so
68+
// the setter is invisible from Kotlin. A small inline IFlightsManager test double is
69+
// simpler than introducing kapt/Lombok wiring just for this test.
70+
CommonFlightsManager.initializeCommonFlightsManager(AllOnFlightsManager)
7071
}
7172

7273
@After
@@ -180,20 +181,33 @@ class SwitchBrowserActivityTest {
180181
}
181182

182183
/**
183-
* Test [IFlightsProvider] that returns `true` for any boolean flight, ensuring tests are
184-
* not affected by environment-specific flight defaults (CI vs local dev machine).
185-
* Plugged into the shared [MockCommonFlightsManager] helper.
184+
* Inline test [IFlightsManager] that returns `true` for every boolean flight, ensuring tests
185+
* are not affected by environment-specific flight defaults (CI vs local dev machine).
186+
*
187+
* Implemented inline (rather than via [com.microsoft.identity.common.internal.mocks.MockCommonFlightsManager])
188+
* because that helper's setter is generated by Lombok and is therefore not visible from Kotlin
189+
* sources without enabling kapt for the test source set.
186190
*/
187-
private object AllOnFlightsProvider : IFlightsProvider {
188-
override fun isFlightEnabled(flightConfig: IFlightConfig): Boolean = true
189-
override fun getBooleanValue(flightConfig: IFlightConfig): Boolean = true
190-
override fun getIntValue(flightConfig: IFlightConfig): Int =
191-
flightConfig.defaultValue as Int
192-
override fun getDoubleValue(flightConfig: IFlightConfig): Double =
193-
flightConfig.defaultValue as Double
194-
override fun getStringValue(flightConfig: IFlightConfig): String =
195-
flightConfig.defaultValue as String
196-
override fun getJsonValue(flightConfig: IFlightConfig): JSONObject =
197-
flightConfig.defaultValue as JSONObject
191+
private object AllOnFlightsManager : IFlightsManager {
192+
private val provider = object : IFlightsProvider {
193+
override fun isFlightEnabled(flightConfig: IFlightConfig): Boolean = true
194+
override fun getBooleanValue(flightConfig: IFlightConfig): Boolean = true
195+
override fun getIntValue(flightConfig: IFlightConfig): Int =
196+
flightConfig.defaultValue as Int
197+
override fun getDoubleValue(flightConfig: IFlightConfig): Double =
198+
flightConfig.defaultValue as Double
199+
override fun getStringValue(flightConfig: IFlightConfig): String =
200+
flightConfig.defaultValue as String
201+
override fun getJsonValue(flightConfig: IFlightConfig): JSONObject =
202+
flightConfig.defaultValue as JSONObject
203+
}
204+
205+
override fun getFlightsProvider(waitForConfigsWithTimeoutInMs: Long): IFlightsProvider =
206+
provider
207+
208+
override fun getFlightsProviderForTenant(
209+
tenantId: String,
210+
waitForConfigsWithTimeoutInMs: Long
211+
): IFlightsProvider = provider
198212
}
199213
}

0 commit comments

Comments
 (0)