Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mockito to 5.12.0 and fix failing tests #4711

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@

package com.duckduckgo.subscriptions.impl

import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import androidx.core.net.toUri
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import app.cash.turbine.test
import com.duckduckgo.browser.api.ui.BrowserScreens.SettingsScreenNoParams
import com.duckduckgo.common.test.CoroutineTestRule
import com.duckduckgo.navigation.api.GlobalActivityStarter
import com.duckduckgo.navigation.api.GlobalActivityStarter.ActivityParams
import com.duckduckgo.subscriptions.api.Product.NetP
import com.duckduckgo.subscriptions.api.SubscriptionStatus.AUTO_RENEWABLE
import com.duckduckgo.subscriptions.api.SubscriptionStatus.INACTIVE
Expand Down Expand Up @@ -197,23 +200,29 @@ class RealSubscriptionsTest {

@Test
fun whenLaunchPrivacyProWithOriginThenPassTheOriginToActivity() = runTest {
whenever(globalActivityStarter.startIntent(any(), any<SettingsScreenNoParams>())).thenReturn(mock())
whenever(globalActivityStarter.startIntent(any(), any<SettingsScreenNoParams>())).thenReturn(fakeIntent())
whenever(globalActivityStarter.startIntent(any(), any<SubscriptionsWebViewActivityWithParams>())).thenReturn(fakeIntent())

val captor = argumentCaptor<SubscriptionsWebViewActivityWithParams>()
val captor = argumentCaptor<ActivityParams>()
subscriptions.launchPrivacyPro(context, "https://duckduckgo.com/pro?origin=test".toUri())

verify(globalActivityStarter, times(2)).startIntent(eq(context), captor.capture())
assertEquals("test", captor.lastValue.origin)
assertEquals("test", (captor.lastValue as SubscriptionsWebViewActivityWithParams).origin)
}

@Test
fun whenLaunchPrivacyProWithNoOriginThenDoNotPassTheOriginToActivity() = runTest {
whenever(globalActivityStarter.startIntent(any(), any<SettingsScreenNoParams>())).thenReturn(mock())
whenever(globalActivityStarter.startIntent(any(), any<SettingsScreenNoParams>())).thenReturn(fakeIntent())
whenever(globalActivityStarter.startIntent(any(), any<SubscriptionsWebViewActivityWithParams>())).thenReturn(fakeIntent())

val captor = argumentCaptor<SubscriptionsWebViewActivityWithParams>()
val captor = argumentCaptor<ActivityParams>()
subscriptions.launchPrivacyPro(context, "https://duckduckgo.com/pro".toUri())

verify(globalActivityStarter, times(2)).startIntent(eq(context), captor.capture())
assertNull(captor.lastValue.origin)
assertNull((captor.lastValue as SubscriptionsWebViewActivityWithParams).origin)
}

private fun fakeIntent(): Intent {
return Intent().also { it.addFlags(FLAG_ACTIVITY_NEW_TASK) }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed otherwise ContextCompat.startActivities complains about the activity being started outside of an activity context. (in production, it's already using an activity context so no changes needed to prod code)

}
}

This file was deleted.

4 changes: 2 additions & 2 deletions versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ version.leakcanary=2.10

version.logcat=0.1

version.mockito=4.4.0
version.mockito=5.12.0

version.moshi=1.8.0

Expand All @@ -109,7 +109,7 @@ version.org.apache.commons..commons-math3=3.6.1

version.org.json..json=20230227

version.org.mockito.kotlin..mockito-kotlin=4.0.0
version.org.mockito.kotlin..mockito-kotlin=5.3.1

version.retrofit2=2.9.0

Expand Down
Loading