For most of the tests it was sufficient to use the OverrideLocale TestRule added in the previous commit but in one case the creation of a date formatter needed to be delayed so that it uses the update locale during the test.
@Inject constructor(webInterface: WebInterface, elementLoader: ElementLoader, newElements: NewElements, timeTextConverter: TimeTextConverter, l10nFilter: L10nFilter):
this(webInterface, elementLoader, newElements, timeTextConverter, l10nFilter, TimeZone.getDefault())
- private val dateFormatter = SimpleDateFormat("MMM d, yyyy, HH:mm:ss").apply {
- this.timeZone = timeZone
+ private val dateFormatter by lazy {
+ SimpleDateFormat("MMM d, yyyy, HH:mm:ss").apply {
+ this.timeZone = timeZone
+ }
}
override fun createJsonObject(request: FreenetRequest) =
package net.pterodactylus.sone.template
+import net.pterodactylus.sone.test.OverrideLocale
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
+import org.junit.Rule
+import java.util.Locale.ENGLISH
import kotlin.test.*
class DurationFormatFilterTest {
private val filter = DurationFormatFilter()
+ @get:Rule
+ val overrideLocale = OverrideLocale(ENGLISH)
+
@Test
fun `random object is returned as it is`() {
val randomObject = Any()
import com.codahale.metrics.*
import net.pterodactylus.sone.freenet.*
+import net.pterodactylus.sone.test.OverrideLocale
import net.pterodactylus.util.template.*
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
import org.jsoup.nodes.*
import org.junit.*
import java.util.*
+import java.util.Locale.ENGLISH
/**
* Unit test for [HistogramRenderer].
*/
class HistogramRendererTest {
+ @get:Rule
+ val overrideLocale = OverrideLocale(ENGLISH)
+
private val translation = object : Translation {
override val currentLocale = Locale.ENGLISH
override fun translate(key: String) = "Metric Name".takeIf { key == "Page.Metrics.TestHistogram.Title" } ?: ""
import net.pterodactylus.sone.data.Sone.SoneStatus.inserting
import net.pterodactylus.sone.freenet.L10nFilter
import net.pterodactylus.sone.freenet.L10nText
+import net.pterodactylus.sone.test.OverrideLocale
import net.pterodactylus.sone.test.deepMock
import net.pterodactylus.sone.test.getInstance
import net.pterodactylus.sone.test.isProvidedByMock
import org.hamcrest.Matchers.hasEntry
import org.hamcrest.Matchers.notNullValue
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyLong
+import java.util.Locale.ENGLISH
import java.util.TimeZone
/**
*/
class GetStatusAjaxPageTest: JsonPageTest("getStatus.ajax", requiresLogin = false, needsFormPassword = false) {
+ @get:Rule
+ val overrideLocale = OverrideLocale(ENGLISH)
+
private val timeTextConverter = mock<TimeTextConverter>()
private val l10nFilter = mock<L10nFilter>()
override var page: JsonPage = GetStatusAjaxPage(webInterface, elementLoader, newElements, timeTextConverter, l10nFilter, TimeZone.getTimeZone("UTC"))
import net.pterodactylus.sone.data.PostReply
import net.pterodactylus.sone.freenet.L10nFilter
import net.pterodactylus.sone.freenet.L10nText
+import net.pterodactylus.sone.test.OverrideLocale
import net.pterodactylus.sone.test.get
import net.pterodactylus.sone.test.getInstance
import net.pterodactylus.sone.test.isProvidedByMock
import org.hamcrest.Matchers.emptyIterable
import org.hamcrest.Matchers.notNullValue
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyLong
+import java.util.Locale.ENGLISH
import java.util.TimeZone
import java.util.TimeZone.getTimeZone
*/
class GetTimesAjaxPageTest : JsonPageTest("getTimes.ajax", needsFormPassword = false, requiresLogin = false) {
+ @get:Rule
+ val overrideLocale = OverrideLocale(ENGLISH)
+
private val timeTextConverter = mock<TimeTextConverter>()
private val l10nFilter = mock<L10nFilter>()
override val page: JsonPage by lazy { GetTimesAjaxPage(webInterface, timeTextConverter, l10nFilter, getTimeZone("UTC")) }