-
Notifications
You must be signed in to change notification settings - Fork 1
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
Ipc 186 unit tests payment component #395
Merged
danicretu
merged 4 commits into
ipc-health-sdk-update
from
IPC-186-Unit-tests-payment-component
Mar 21, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e13524b
feat(health-sdk): Added unit tests for `PaymentComponent`
danicretu 62a153e
feat(health-sdk): Added unit tests for `PaymentComponentPreferences`
danicretu 03fab61
feat(health-sdk): Added unit tests for `PaymentComponentView`
danicretu fafa0a4
feat(health-sdk): Addressed code review comments
danicretu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 30 additions & 0 deletions
30
health-sdk/sdk/src/main/java/net/gini/android/health/sdk/util/extensions/Context.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,30 @@ | ||
package net.gini.android.health.sdk.util.extensions | ||
|
||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.BitmapFactory | ||
import android.graphics.drawable.BitmapDrawable | ||
import android.util.TypedValue | ||
import androidx.annotation.VisibleForTesting | ||
import net.gini.android.health.sdk.paymentprovider.PaymentProviderApp | ||
|
||
// In a future refactoring we can split extensions into files according to what component they extend | ||
@VisibleForTesting | ||
internal fun Context.generateBitmapDrawableIcon(icon: ByteArray, iconSize: Int): BitmapDrawable? { | ||
return BitmapFactory.decodeByteArray(icon, 0, iconSize) | ||
?.let { bitmap -> | ||
val iconSizePx = TypedValue.applyDimension( | ||
TypedValue.COMPLEX_UNIT_DIP, | ||
PaymentProviderApp.ICON_SIZE, | ||
this.resources.displayMetrics | ||
).toInt() | ||
val scaledBitmap = Bitmap.createScaledBitmap( | ||
bitmap, | ||
iconSizePx, | ||
iconSizePx, | ||
true | ||
) | ||
bitmap.recycle() | ||
BitmapDrawable(this.resources, scaledBitmap) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...test/java/net/gini/android/health/sdk/paymentComponent/PaymentComponentPreferencesTest.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,58 @@ | ||
package net.gini.android.health.sdk.paymentComponent | ||
|
||
import android.content.Context | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.google.common.truth.Truth.assertThat | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.test.runTest | ||
import net.gini.android.health.sdk.paymentcomponent.PaymentComponentPreferences | ||
import net.gini.android.health.sdk.test.ViewModelTestCoroutineRule | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@ExperimentalCoroutinesApi | ||
@RunWith(AndroidJUnit4::class) | ||
class PaymentComponentPreferencesTest { | ||
|
||
@get:Rule | ||
val testCoroutineRule = ViewModelTestCoroutineRule() | ||
private lateinit var context: Context | ||
|
||
@Before | ||
fun setup() { | ||
context = ApplicationProvider.getApplicationContext() | ||
} | ||
|
||
@Test | ||
fun `sets selected payment provider app`() = runTest { | ||
// Given | ||
val paymentComponentPreferences = PaymentComponentPreferences(context) | ||
|
||
assertThat(paymentComponentPreferences.getSelectedPaymentProviderId()).isNull() | ||
|
||
// When | ||
paymentComponentPreferences.saveSelectedPaymentProviderId("123") | ||
|
||
// Then | ||
assertThat(paymentComponentPreferences.getSelectedPaymentProviderId()).isEqualTo("123") | ||
} | ||
|
||
@Test | ||
fun `deletes selected payment provider app`() = runTest { | ||
// Given | ||
val paymentComponentPreferences = PaymentComponentPreferences(context) | ||
|
||
assertThat(paymentComponentPreferences.getSelectedPaymentProviderId()).isNull() | ||
paymentComponentPreferences.saveSelectedPaymentProviderId("123") | ||
assertThat(paymentComponentPreferences.getSelectedPaymentProviderId()).isEqualTo("123") | ||
|
||
// When | ||
paymentComponentPreferences.deleteSelectedPaymentProviderId() | ||
|
||
// Then | ||
assertThat(paymentComponentPreferences.getSelectedPaymentProviderId()).isNull() | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
[Comment] Yes, thank you for adding this comment! I wholeheartedly agree! 👍 👍 👍