Skip to content

Commit 90de230

Browse files
authored
Set a fixed locale in RealSubscriptionsManagerTest (#7064)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1202552961248957/task/1211852239322423?focus=true ### Description ### Steps to test this PR - [x] Tests should pass - [ ] ### No UI changes
1 parent 09d88a4 commit 90de230

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2025 DuckDuckGo
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.duckduckgo.common.test
18+
19+
import org.junit.rules.TestRule
20+
import org.junit.runner.Description
21+
import org.junit.runners.model.Statement
22+
import java.util.Locale
23+
24+
class FixedLocaleRule(private val locale: Locale = Locale.US) : TestRule {
25+
26+
override fun apply(base: Statement, description: Description) = object : Statement() {
27+
override fun evaluate() {
28+
val originalLocale = Locale.getDefault()
29+
Locale.setDefault(locale)
30+
try {
31+
base.evaluate()
32+
} finally {
33+
Locale.setDefault(originalLocale)
34+
}
35+
}
36+
}
37+
}

subscriptions/subscriptions-impl/src/test/java/com/duckduckgo/subscriptions/impl/RealSubscriptionsManagerTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.android.billingclient.api.ProductDetails.SubscriptionOfferDetails
1010
import com.android.billingclient.api.PurchaseHistoryRecord
1111
import com.duckduckgo.autofill.api.email.EmailManager
1212
import com.duckduckgo.common.test.CoroutineTestRule
13+
import com.duckduckgo.common.test.FixedLocaleRule
1314
import com.duckduckgo.common.utils.CurrentTimeProvider
1415
import com.duckduckgo.feature.toggles.api.FakeFeatureToggleFactory
1516
import com.duckduckgo.feature.toggles.api.Toggle.State
@@ -108,6 +109,9 @@ class RealSubscriptionsManagerTest(private val authApiV2Enabled: Boolean) {
108109
@get:Rule
109110
val coroutineRule = CoroutineTestRule()
110111

112+
@get:Rule
113+
val fixedLocalRule = FixedLocaleRule()
114+
111115
private val authService: AuthService = mock()
112116
private val subscriptionsService: SubscriptionsService = mock()
113117
private val authDataStore: FakeSubscriptionsDataStore = FakeSubscriptionsDataStore()

0 commit comments

Comments
 (0)