From df0d790493141af21e6a8fb0df1638ce55416a7c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 26 Mar 2024 15:29:12 +0100 Subject: [PATCH] Avoid tryEmit(), use emit() --- .../troubleshoot/FakeNotificationTroubleshootTest.kt | 10 +++++----- .../core/notifications/NotificationTroubleshootTest.kt | 6 ++++-- .../NotificationTroubleshootTestDelegate.kt | 8 ++++---- .../NotificationTroubleshootCheckPermissionTest.kt | 2 +- .../push/impl/troubleshoot/CurrentPushProviderTest.kt | 2 +- .../push/impl/troubleshoot/NotificationTest.kt | 2 +- .../push/impl/troubleshoot/PushLoopbackTest.kt | 2 +- .../push/impl/troubleshoot/PushProvidersTest.kt | 2 +- .../firebase/troubleshoot/FirebaseAvailabilityTest.kt | 2 +- .../firebase/troubleshoot/FirebaseTokenTest.kt | 2 +- .../unifiedpush/troubleshoot/UnifiedPushTest.kt | 2 +- 11 files changed, 21 insertions(+), 19 deletions(-) diff --git a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/FakeNotificationTroubleshootTest.kt b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/FakeNotificationTroubleshootTest.kt index e619a62972..361c59cae7 100644 --- a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/FakeNotificationTroubleshootTest.kt +++ b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/troubleshoot/FakeNotificationTroubleshootTest.kt @@ -48,30 +48,30 @@ class FakeNotificationTroubleshootTest( } } - override fun reset() { + override suspend fun reset() { updateState( name = defaultName, description = defaultDescription, status = firstStatus, ) resetAction()?.let { - _state.tryEmit(it) + _state.emit(it) } } override suspend fun quickFix(coroutineScope: CoroutineScope) { updateState(NotificationTroubleshootTestState.Status.InProgress) quickFixAction()?.let { - _state.tryEmit(it) + _state.emit(it) } } - fun updateState( + suspend fun updateState( status: NotificationTroubleshootTestState.Status, name: String = defaultName, description: String = defaultDescription, ) { - _state.tryEmit( + _state.emit( NotificationTroubleshootTestState( name = name, description = description, diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/notifications/NotificationTroubleshootTest.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/notifications/NotificationTroubleshootTest.kt index 755e186e8b..7af0b85ffb 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/notifications/NotificationTroubleshootTest.kt +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/notifications/NotificationTroubleshootTest.kt @@ -24,6 +24,8 @@ interface NotificationTroubleshootTest { val state: StateFlow fun isRelevant(data: TestFilterData): Boolean = true suspend fun run(coroutineScope: CoroutineScope) - fun reset() - suspend fun quickFix(coroutineScope: CoroutineScope) {} + suspend fun reset() + suspend fun quickFix(coroutineScope: CoroutineScope) { + error("Quick fix not implemented, you need to override this method in your test") + } } diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/notifications/NotificationTroubleshootTestDelegate.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/notifications/NotificationTroubleshootTestDelegate.kt index 9711677253..88aaae7281 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/notifications/NotificationTroubleshootTestDelegate.kt +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/notifications/NotificationTroubleshootTestDelegate.kt @@ -41,12 +41,12 @@ class NotificationTroubleshootTestDelegate( val state: StateFlow = _state.asStateFlow() - fun updateState( + suspend fun updateState( status: NotificationTroubleshootTestState.Status, name: String = defaultName, description: String = defaultDescription, ) { - _state.tryEmit( + _state.emit( NotificationTroubleshootTestState( name = name, description = description, @@ -55,7 +55,7 @@ class NotificationTroubleshootTestDelegate( ) } - fun reset() { + suspend fun reset() { updateState(NotificationTroubleshootTestState.Status.Idle(visibleWhenIdle)) } @@ -64,7 +64,7 @@ class NotificationTroubleshootTestDelegate( delay(fakeDelay) } - fun done(isSuccess: Boolean = true) { + suspend fun done(isSuccess: Boolean = true) { updateState( if (isSuccess) { NotificationTroubleshootTestState.Status.Success diff --git a/libraries/permissions/impl/src/main/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTest.kt b/libraries/permissions/impl/src/main/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTest.kt index 501b00e14a..f158ccbabd 100644 --- a/libraries/permissions/impl/src/main/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTest.kt +++ b/libraries/permissions/impl/src/main/kotlin/io/element/android/libraries/permissions/impl/troubleshoot/NotificationTroubleshootCheckPermissionTest.kt @@ -57,7 +57,7 @@ class NotificationTroubleshootCheckPermissionTest @Inject constructor( delegate.done(result) } - override fun reset() = delegate.reset() + override suspend fun reset() = delegate.reset() override suspend fun quickFix(coroutineScope: CoroutineScope) { // Do not bother about asking the permission inline, just lead the user to the settings diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTest.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTest.kt index 6b8f69e8db..32f99edd13 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTest.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/CurrentPushProviderTest.kt @@ -54,5 +54,5 @@ class CurrentPushProviderTest @Inject constructor( } } - override fun reset() = delegate.reset() + override suspend fun reset() = delegate.reset() } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt index b2e7ef223c..d2bf0b160d 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/NotificationTest.kt @@ -90,5 +90,5 @@ class NotificationTest @Inject constructor( notificationDisplayer.dismissDiagnosticNotification() } - override fun reset() = delegate.reset() + override suspend fun reset() = delegate.reset() } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt index 86d7b437a7..b4323b612f 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushLoopbackTest.kt @@ -98,5 +98,5 @@ class PushLoopbackTest @Inject constructor( } } - override fun reset() = delegate.reset() + override suspend fun reset() = delegate.reset() } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTest.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTest.kt index 7beca906b9..bbcee50a54 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTest.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/troubleshoot/PushProvidersTest.kt @@ -55,5 +55,5 @@ class PushProvidersTest @Inject constructor( } } - override fun reset() = delegate.reset() + override suspend fun reset() = delegate.reset() } diff --git a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTest.kt b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTest.kt index e0891d6081..acd907fb0a 100644 --- a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTest.kt +++ b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseAvailabilityTest.kt @@ -61,5 +61,5 @@ class FirebaseAvailabilityTest @Inject constructor( } } - override fun reset() = delegate.reset() + override suspend fun reset() = delegate.reset() } diff --git a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt index 7c8ce5dfef..e501ce1e9d 100644 --- a/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt +++ b/libraries/pushproviders/firebase/src/main/kotlin/io/element/android/libraries/pushproviders/firebase/troubleshoot/FirebaseTokenTest.kt @@ -63,7 +63,7 @@ class FirebaseTokenTest @Inject constructor( } } - override fun reset() = delegate.reset() + override suspend fun reset() = delegate.reset() override suspend fun quickFix(coroutineScope: CoroutineScope) { delegate.start() diff --git a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt index 3d612b0613..df79030c44 100644 --- a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt +++ b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/troubleshoot/UnifiedPushTest.kt @@ -62,7 +62,7 @@ class UnifiedPushTest @Inject constructor( } } - override fun reset() = delegate.reset() + override suspend fun reset() = delegate.reset() override suspend fun quickFix(coroutineScope: CoroutineScope) { openDistributorWebPageAction.execute()