Skip to content

v6 - Core - Unit tests for model, localization and session params helpers - #2950

Draft
araratthehero wants to merge 1 commit into
mainfrom
chore/v6-core-test-coverage
Draft

v6 - Core - Unit tests for model, localization and session params helpers#2950
araratthehero wants to merge 1 commit into
mainfrom
chore/v6-core-test-coverage

Conversation

@araratthehero

Copy link
Copy Markdown
Contributor

Description

Adds unit tests for four core helpers that had no coverage.

Checklist

  • Code is unit tested

Ticket Number

COSDK-546

@AdyenAutomationBot AdyenAutomationBot added the Chore [PRs only] Indicates any task that does not need to be mentioned in the public release notes label Aug 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive unit tests for several core utility classes, including JsonUtils, ModelUtils, LocalizationResolver, and SessionParamsFactory, along with a MockModelObject helper. A review comment points out that the test for formatting localized strings with arguments does not verify if the shopper's locale is respected, as Kotlin's String.format extension defaults to the system locale. It suggests updating the test to use a locale-sensitive argument and a specific locale to ensure correct formatting.

Comment on lines +69 to +78
fun `when format args are passed, then the string is formatted with them`() {
val result = getLocalizedString(
localizationProvider = FakeLocalizationProvider("Pay %s"),
key = CheckoutLocalizationKey.PAY_BUTTON_WITH_AMOUNT,
formatArgs = arrayOf("EUR 10.00"),
)

assertEquals("Pay EUR 10.00", result)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current test formats the string using a String argument ("EUR 10.00"), which does not verify whether the formatting respects the shopper's locale.

In LocalizationResolver.getLocalizedStringFor, the formatting is performed using string.format(*formatArgs). In Kotlin, this extension function defaults to Locale.getDefault(), ignoring the shopper's locale parameter passed to the method. This can lead to incorrect formatting of locale-sensitive values (such as decimals, currencies, or dates) on devices with different system locales.

To expose and prevent this issue, we should update the test to use a locale-sensitive format argument (like a Double) and a specific locale (like Locale.FRANCE), asserting that the output is formatted correctly according to that locale. Note that fixing this test will require updating LocalizationResolver.kt to use string.format(locale, *formatArgs).

Suggested change
fun `when format args are passed, then the string is formatted with them`() {
val result = getLocalizedString(
localizationProvider = FakeLocalizationProvider("Pay %s"),
key = CheckoutLocalizationKey.PAY_BUTTON_WITH_AMOUNT,
formatArgs = arrayOf("EUR 10.00"),
)
assertEquals("Pay EUR 10.00", result)
}
@Test
fun whenFormatArgsArePassedThenTheStringIsFormattedUsingTheShopperLocale() {
val result = getLocalizedString(
localizationProvider = FakeLocalizationProvider("Pay %.2f"),
key = CheckoutLocalizationKey.PAY_BUTTON_WITH_AMOUNT,
locale = Locale.FRANCE,
formatArgs = arrayOf(10.00),
)
assertEquals("Pay 10,00", result)
}

@github-actions

Copy link
Copy Markdown
Contributor

✅ No public API changes

@sonarqubecloud

Copy link
Copy Markdown

@araratthehero
araratthehero marked this pull request as ready for review August 18, 2026 12:00
@araratthehero
araratthehero requested a review from a team as a code owner August 18, 2026 12:00
@araratthehero
araratthehero marked this pull request as draft August 18, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Chore [PRs only] Indicates any task that does not need to be mentioned in the public release notes size:large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants