-
Notifications
You must be signed in to change notification settings - Fork 18
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
Coroutines and necessary Ktlint configuration #39
Conversation
import org.junit.runner.Description | ||
import org.junit.runners.model.Statement | ||
|
||
class GravatarSdkTest : TestRule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TestRule sets the basic container to be able to test the GravatarApi.
ktlint_function_signature_body_expression_wrapping = default | ||
ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed!
ktlint_standard_multiline-expression-wrapping = disabled | ||
ktlint_standard_string-template-indent = disabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow to keep the expression in the same line when it fits. Example:
@Test
fun `given a file, email and accessToken when uploading avatar then Gravatar service is invoked`() = runTest {
Without disabling those rules:
@Test
fun `given a file, email and accessToken when uploading avatar then Gravatar service is invoked`() =
runTest {
@@ -27,6 +26,8 @@ class GravatarApi(private val okHttpClient: OkHttpClient? = null) { | |||
UNKNOWN, | |||
} | |||
|
|||
val coroutineScope = CoroutineScope(GravatarSdkContainer.instance.dispatcherDefault) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Injecting the dispatchers is a good practice to be able to replace them when unit testing.
if (response.isSuccessful) { | ||
gravatarUploadListener.onSuccess() | ||
} else { | ||
// Log the response body for debugging purposes if the response is not successful | ||
Log.w( | ||
GravatarSdkContainer.instance.logger.w( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to alias GravatarSdkContainer.instance.logger
to something shorter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've refactored this part. Rethinking about this, we probably don't need to inject the logger; the main reason to have a wrapper around it would be to have better control over our library logs and send some error analytics when/if needed. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably don't need to inject the logger; the main reason to have a wrapper around it would be to have better control over our library logs and send some error analytics when/if needed
It sounds like this falls into the premature optimization category. Let's keep it simple for now, we can inject a logger abstraction later if we need to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
we can revisit logging stuff later
ktlint_function_signature_body_expression_wrapping = default | ||
ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed!
#30
Using Kotlin Coroutines will allow us to improve our testing possibilities. This PR adds several tests to the current GravatarApi.
I've created a wrapper for the Android logger and injected it in the GravatarApi using the container. That way, we don't need an Android class in the unit test, and why not? We can verify that the Logger is invoked (if needed).
This PR also modified our Ktlint rules to remove some unnecessary "new line" requirements.