Skip to content
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

Set and reset Locale to pass test for non-english contributor. #2622

Merged
merged 7 commits into from
Apr 6, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.junit.jupiter.params.provider.EnumSource
import org.xml.sax.SAXParseException
import java.nio.file.Path
import java.nio.file.Paths
import java.util.Locale
import kotlin.io.path.Path
import kotlin.io.path.copyTo
import kotlin.io.path.pathString
Expand Down Expand Up @@ -106,25 +107,30 @@ class BaselineTest {

@Nested
inner class `Baseline has invalid xml structure` {
private val currentLocale = Locale.getDefault()

@Test
fun `Given that the baseline is loaded with classic loader then the log contains an error message`(
@TempDir
tempDir: Path,
) {
setLocaleToEnglish()
Jaehwa-Noh marked this conversation as resolved.
Show resolved Hide resolved
val path = "baseline-invalid.xml".copyResourceToFileIn(tempDir)

val logCaptor = LogCaptor.forClass(Baseline::class.java)

loadBaseline(path)

assertThat(logCaptor.errorLogs).contains("Unable to parse baseline file: $path")
resetLocale(default = currentLocale)
Jaehwa-Noh marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
fun `Given that the baseline is loaded with new loader then an exception is thrown on error`(
@TempDir
tempDir: Path,
) {
setLocaleToEnglish()
val path = "baseline-invalid.xml".copyResourceToFileIn(tempDir)

assertThatExceptionOfType(BaselineLoaderException::class.java)
Expand All @@ -133,6 +139,7 @@ class BaselineTest {
.withCauseInstanceOf(SAXParseException::class.java)
.havingCause()
.withMessage("The element type \"file\" must be terminated by the matching end-tag \"</file>\".")
resetLocale(default = currentLocale)
}

@Test
Expand All @@ -148,6 +155,10 @@ class BaselineTest {

assertThat(logCaptor.errorLogs).contains("Unable to parse baseline file: $path")
}

private fun setLocaleToEnglish() = Locale.setDefault(Locale.ENGLISH)

private fun resetLocale(default: Locale) = Locale.setDefault(default)
Jaehwa-Noh marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down