Skip to content

Commit

Permalink
fix(core): use returns instead of answers on coEvery (#2653)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Leing <[email protected]>
Co-authored-by: gpanshu <[email protected]>
Co-authored-by: Matt Creaser <[email protected]>
  • Loading branch information
4 people authored Jan 29, 2024
1 parent 7eecf2e commit e6563dd
Show file tree
Hide file tree
Showing 25 changed files with 88 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ block inside your app's `build.gradle`, as below:
android {
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
```
Expand Down
4 changes: 4 additions & 0 deletions aws-analytics-pinpoint/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ dependencies {
androidTestImplementation(libs.test.androidx.junit)
androidTestImplementation(project(":aws-analytics-pinpoint"))
}

android.kotlinOptions {
jvmTarget = "11"
}
4 changes: 4 additions & 0 deletions aws-api-appsync/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ dependencies {
testImplementation(project(":testmodels"))
testImplementation(project(":testutils"))
}

android.kotlinOptions {
jvmTarget = "11"
}
4 changes: 4 additions & 0 deletions aws-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ dependencies {

androidTestUtil(libs.test.androidx.orchestrator)
}

android.kotlinOptions {
jvmTarget = "11"
}
4 changes: 4 additions & 0 deletions aws-auth-cognito/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ dependencies {
androidTestImplementation(project(":aws-api"))
androidTestImplementation(project(":testutils"))
}

android.kotlinOptions {
jvmTarget = "11"
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class APICaptorFactory(
val errorCaptor = slot<AuthException>()
val actionCaptor = slot<Map<String, Any>>().apply {
captured = emptyMap()
isCaptured = true
}
}

Expand Down
6 changes: 6 additions & 0 deletions aws-auth-plugins-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ apply(from = rootProject.file("configuration/publishing.gradle"))

group = properties["POM_GROUP"].toString()

android {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}

dependencies {
implementation(project(":core"))
implementation(project(":aws-core"))
Expand Down
2 changes: 1 addition & 1 deletion aws-datastore/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ dependencies {
}

afterEvaluate {
android.kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
android.kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ public void rawQueryReturnsResults() throws AmplifyException {

// Query for all BlogOwners, and verify that there is one result.
SqlCommand queryCommand = sqlCommandFactory.queryFor(blogOwnerSchema, Where.matchesAll());
Cursor cursor = sqlCommandProcessor.rawQuery(queryCommand);
Cursor cursor = null;
try {
cursor = sqlCommandProcessor.rawQuery(queryCommand);
} catch (Exception exc) {
throw new AmplifyException("DB already closed", exc, "Wait until DB is reopened");
}
List<BlogOwner> results = new ArrayList<>();

SQLiteModelFieldTypeConverter converter = new SQLiteModelFieldTypeConverter(blogOwnerSchema,
Expand Down
2 changes: 1 addition & 1 deletion aws-geo-location/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ dependencies {
}

afterEvaluate {
android.kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
android.kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
}
4 changes: 4 additions & 0 deletions aws-logging-cloudwatch/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ dependencies {
testImplementation(libs.test.androidx.workmanager)
testImplementation(project(":aws-logging-cloudwatch"))
}

android.kotlinOptions {
jvmTarget = "11"
}
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
4 changes: 4 additions & 0 deletions aws-pinpoint-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ dependencies {
androidTestImplementation(libs.test.androidx.runner)
androidTestImplementation(libs.test.androidx.junit)
}

android.kotlinOptions {
jvmTarget = "11"
}
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()
}
}
4 changes: 4 additions & 0 deletions aws-predictions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ dependencies {
androidTestImplementation(libs.test.mockk.android)
androidTestImplementation(libs.rxjava)
}

android.kotlinOptions {
jvmTarget = "11"
}
6 changes: 6 additions & 0 deletions aws-push-notifications-pinpoint-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ apply(from = rootProject.file("configuration/publishing.gradle"))

group = properties["POM_GROUP"].toString()

android {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}

dependencies {
implementation(project(":annotations"))
api(project(":common-core"))
Expand Down
4 changes: 4 additions & 0 deletions aws-storage-s3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ dependencies {
androidTestImplementation(libs.test.androidx.workmanager)
androidTestImplementation(project(":aws-storage-s3"))
}

android.kotlinOptions {
jvmTarget = "11"
}
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ fun Project.configureAndroid() {

compileOptions {
isCoreLibraryDesugaringEnabled = true
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

// Needed when running integration tests. The oauth2 library uses relies on two
// dependencies (Apache's httpcore and httpclient), both of which include
// META-INF/DEPENDENCIES. Tried a couple other options to no avail.
packagingOptions {
resources.excludes.add("META-INF/DEPENDENCIES")
resources.excludes.add("META-INF/*")
}
}

Expand Down
4 changes: 2 additions & 2 deletions canaries/example/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
Expand Down
2 changes: 1 addition & 1 deletion core-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ dependencies {
}

android.kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "11"
freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn"
}
4 changes: 4 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ dependencies {
androidTestImplementation(libs.test.androidx.fragment)
}

android.kotlinOptions {
jvmTarget = "11"
}

afterEvaluate {
// Disables this warning:
// warning: listOf(classfile) MethodParameters attribute
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ maplibre-annotations = "1.0.0"
material = "1.8.0"
mockito = "3.9.0"
mockito-inline = "3.11.2"
mockk = "1.12.3"
mockk = "1.13.8"
mockwebserver = "5.0.0-alpha.11"
navigation = "2.3.4"
oauth2 = "0.26.0"
Expand Down
2 changes: 1 addition & 1 deletion maplibre-adapter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ group = properties["POM_GROUP"].toString()

android {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
jvmTarget = JavaVersion.VERSION_11.toString()
}
lint {
disable += "GradleDependency"
Expand Down
4 changes: 4 additions & 0 deletions rxbindings/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ dependencies {
testImplementation(libs.test.robolectric)
testImplementation(project(":rxbindings"))
}

android.kotlinOptions {
jvmTarget = "11"
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
*/
@RunWith(RobolectricTestRunner.class)
public final class RxStorageBindingTest {
private static final long TIMEOUT_MS = TimeUnit.SECONDS.toMillis(5);
private static final long TIMEOUT_MS = TimeUnit.SECONDS.toMillis(10);
private RxStorageCategoryBehavior rxStorage;
private StoragePlugin<?> delegate;
private File localFile;
Expand Down

0 comments on commit e6563dd

Please sign in to comment.