mirror of
https://github.com/accelforce/Yuito
synced 2025-01-03 11:30:29 +01:00
Ensures AbsoluteTimeFormatterTest class is not locale-dependant (#3863)
As tests are run against locale JVM and test does not force a locale to run, so some tests may fail due to a different result only due to the locale of the JVM used. Example here with test `same year formatting` in class `AbsoluteTimeFormatterTest` line 30 on a French JVM. There may be other lines to fail with other languages. Fixes #3859
This commit is contained in:
parent
a75131246f
commit
9a7e456edf
@ -1,12 +1,35 @@
|
|||||||
package com.keylesspalace.tusky.util
|
package com.keylesspalace.tusky.util
|
||||||
|
|
||||||
|
import org.junit.AfterClass
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.BeforeClass
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.Date
|
import java.util.*
|
||||||
import java.util.TimeZone
|
|
||||||
|
|
||||||
class AbsoluteTimeFormatterTest {
|
class AbsoluteTimeFormatterTest {
|
||||||
|
companion object {
|
||||||
|
/** Default locale before this test started */
|
||||||
|
private lateinit var locale: Locale
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure the Locale is ENGLISH so that tests against literal strings like
|
||||||
|
* "Apr" later, even if the test host's locale is e.g. FRENCH which would
|
||||||
|
* normally report "avr.".
|
||||||
|
*/
|
||||||
|
@BeforeClass
|
||||||
|
@JvmStatic
|
||||||
|
fun beforeClass() {
|
||||||
|
locale = Locale.getDefault()
|
||||||
|
Locale.setDefault(Locale.ENGLISH)
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
@JvmStatic
|
||||||
|
fun afterClass() {
|
||||||
|
Locale.setDefault(locale)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val formatter = AbsoluteTimeFormatter(TimeZone.getTimeZone("UTC"))
|
private val formatter = AbsoluteTimeFormatter(TimeZone.getTimeZone("UTC"))
|
||||||
private val now = Date.from(Instant.parse("2022-04-11T00:00:00.00Z"))
|
private val now = Date.from(Instant.parse("2022-04-11T00:00:00.00Z"))
|
||||||
|
Loading…
Reference in New Issue
Block a user