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

fix(core): use returns instead of answers on coEvery #2653

Merged
merged 16 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ internal class AWSCloudWatchLoggingPluginImplementationTest {
region = "REGION",
logGroupName = "LOG_GROUP"
)
every { loggingConstraintsResolver::localLoggingConstraint.set(capture(loggingConstraintsSlot)) }.answers { }
coEvery { cloudWatchLogManager.startSync() }.answers { }
every { loggingConstraintsResolver::localLoggingConstraint.set(capture(loggingConstraintsSlot)) } returns Unit
coEvery { cloudWatchLogManager.startSync() } returns Unit
awsCloudWatchLoggingPluginImplementation.configure(
awsLoggingConfig
)
Expand All @@ -77,8 +77,8 @@ internal class AWSCloudWatchLoggingPluginImplementationTest {
region = "REGION",
logGroupName = "LOG_GROUP"
)
every { loggingConstraintsResolver::localLoggingConstraint.set(any()) }.answers { }
coEvery { cloudWatchLogManager.startSync() }.answers { }
every { loggingConstraintsResolver::localLoggingConstraint.set(any()) } returns Unit
coEvery { cloudWatchLogManager.startSync() } returns Unit
awsCloudWatchLoggingPluginImplementation.configure(
awsLoggingConfig
)
Expand All @@ -88,15 +88,15 @@ internal class AWSCloudWatchLoggingPluginImplementationTest {

@Test
fun `on enable`() = runTest {
coEvery { cloudWatchLogManager.startSync() }.answers { }
coEvery { cloudWatchLogManager.startSync() } returns Unit
awsCloudWatchLoggingPluginImplementation.enable()
assertTrue(awsCloudWatchLoggingPluginImplementation.isPluginEnabled)
coVerify(exactly = 1) { cloudWatchLogManager.startSync() }
}

@Test
fun `on disable`() {
every { cloudWatchLogManager.stopSync() }.answers { }
every { cloudWatchLogManager.stopSync() } returns Unit
awsCloudWatchLoggingPluginImplementation.disable()
assertFalse(awsCloudWatchLoggingPluginImplementation.isPluginEnabled)
verify(exactly = 1) { cloudWatchLogManager.stopSync() }
Expand All @@ -106,8 +106,8 @@ internal class AWSCloudWatchLoggingPluginImplementationTest {
fun `on flush logs success`() = runTest {
val onSuccess = mockk<Action>()
val onError = mockk<Consumer<AmplifyException>>()
coEvery { cloudWatchLogManager.syncLogEventsWithCloudwatch() }.answers { }
every { onSuccess.call() }.answers { }
coEvery { cloudWatchLogManager.syncLogEventsWithCloudwatch() } returns Unit
every { onSuccess.call() } returns Unit
awsCloudWatchLoggingPluginImplementation.flushLogs(onSuccess, onError)
coVerify(exactly = 1) { cloudWatchLogManager.syncLogEventsWithCloudwatch() }
verify(exactly = 1) { onSuccess.call() }
Expand All @@ -120,7 +120,7 @@ internal class AWSCloudWatchLoggingPluginImplementationTest {
val onError = mockk<Consumer<AmplifyException>>()
val exception = slot<AmplifyException>()
coEvery { cloudWatchLogManager.syncLogEventsWithCloudwatch() }.throws(IllegalStateException())
every { onError.accept(capture(exception)) }.answers { }
every { onError.accept(capture(exception)) } returns Unit
awsCloudWatchLoggingPluginImplementation.flushLogs(onSuccess, onError)
coVerify(exactly = 1) { cloudWatchLogManager.syncLogEventsWithCloudwatch() }
verify(exactly = 0) { onSuccess.call() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import java.util.UUID
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
Expand All @@ -60,8 +61,8 @@ class AnalyticsClientTest {
fun setup() = runTest {
mockkStatic("com.amplifyframework.pinpoint.core.util.SharedPreferencesUtilKt")
every { sharedPrefs.getUniqueId() } answers { "UNIQUE_ID" }
coEvery { sessionClient.setAnalyticsClient(any()) } answers { }
coEvery { sessionClient.startSession() } answers { }
coEvery { sessionClient.setAnalyticsClient(any()) } returns Unit
coEvery { sessionClient.startSession() } returns Unit

analyticsClient = AnalyticsClient(
ApplicationProvider.getApplicationContext(),
Expand Down Expand Up @@ -159,4 +160,9 @@ class AnalyticsClientTest {
analyticsClient.addGlobalMetric(metricName, metricValue)
assertEquals(metricValue, analyticsClient.getGlobalMetrics()[metricName])
}

@After
fun tearDown() {
analyticsClient.disableEventSubmitter()
}
}
Loading