-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error handling when generating Health summary (#146)
# *Health summary PDF generation* ## ♻️ Current situation & Problem - Even though the summary pdf was generated successfully, the service was throwing because there was no PDF viewer app installed in the device - We were able to catch the error and were attempting to show a toast. However, since the code is being executed in a background thread, the app was crashing because toast must be executed in the main thread. Addressed the issue by: - Ensuring that toast messages are executed always in the main thread - Explicitly check whether after PDF generation whether there is an appropriate pdf reader app installed in the device. If not we display a toast message that summary is generated successfully but no pdf reader installed in the device. In case of success, the user will have the option to select the the pdf reader app via a default android bottom sheet ## ⚙️ Release Notes *Add a bullet point list summary of the feature and possible migration guides if this is a breaking change so this section can be added to the release notes.* *Include code snippets that provide examples of the feature implemented or links to the documentation if it appends or changes the public interface.* ## 📚 Documentation *Please ensure that you properly document any additions in conformance to [Spezi Documentation Guide](https://github.com/StanfordSpezi/.github/blob/main/DOCUMENTATIONGUIDE.md).* *You can use this section to describe your solution, but we encourage contributors to document your reasoning and changes using in-line documentation.* ## ✅ Testing *Please ensure that the PR meets the testing requirements set by CodeCov and that new functionality is appropriately tested.* *This section describes important information about the tests and why some elements might not be testable.* ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [ ] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md). --------- Co-authored-by: Paul Schmiedmayer <[email protected]>
- Loading branch information
1 parent
c6d63bf
commit d101a43
Showing
7 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
core/utils/src/androidTest/kotlin/edu/stanford/spezi/core/utils/HiltApplicationTestRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package edu.stanford.spezi.core.utils | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import androidx.test.runner.AndroidJUnitRunner | ||
import dagger.hilt.android.testing.HiltTestApplication | ||
|
||
@Suppress("Unused") | ||
class HiltApplicationTestRunner : AndroidJUnitRunner() { | ||
override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application { | ||
return super.newApplication(cl, HiltTestApplication::class.java.name, context) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
core/utils/src/androidTest/kotlin/edu/stanford/spezi/core/utils/MessageNotifierTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package edu.stanford.spezi.core.utils | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import dagger.hilt.android.testing.HiltAndroidRule | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import kotlinx.coroutines.test.StandardTestDispatcher | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidTest | ||
class MessageNotifierTest { | ||
|
||
@get:Rule(order = 1) | ||
val hiltRule = HiltAndroidRule(this) | ||
|
||
@Inject | ||
lateinit var messageNotifier: MessageNotifier | ||
|
||
@Before | ||
fun init() { | ||
hiltRule.inject() | ||
} | ||
|
||
@Test | ||
fun `it should not fail when toasting in main thread`() { | ||
InstrumentationRegistry.getInstrumentation().runOnMainSync { | ||
messageNotifier.notify("Some message") | ||
} | ||
} | ||
|
||
@Test | ||
fun `it should not fail when notifying on a background thread`() = runTest(StandardTestDispatcher()) { | ||
messageNotifier.notify("Some message") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters