Replace unit test for “get times” AJAX page
[Sone.git] / src / test / java / net / pterodactylus / sone / web / ajax / GetTimesAjaxPageTest.kt
1 package net.pterodactylus.sone.web.ajax
2
3 import net.pterodactylus.sone.test.deepMock
4 import net.pterodactylus.sone.test.whenever
5 import net.pterodactylus.sone.web.WebInterface
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
8 import org.junit.Test
9 import java.lang.System.currentTimeMillis
10
11 /**
12  * Unit test for [GetTimesAjaxPage].
13  */
14 class GetTimesAjaxPageTest {
15
16         private val webInterface = deepMock<WebInterface>()
17
18         @Test
19         fun timestampInTheFutureIsTranslatedCorrectly() {
20                 whenever(webInterface.l10n.getString("View.Time.InTheFuture")).thenReturn("in the future")
21                 val time = GetTimesAjaxPage.getTime(webInterface, currentTimeMillis() + 1000)
22                 assertThat(time.text, equalTo("in the future"))
23         }
24
25         @Test
26         fun timestampAFewSecondsAgoIsTranslatedCorrectly() {
27                 whenever(webInterface.l10n.getString("View.Time.AFewSecondsAgo")).thenReturn("a few seconds ago")
28                 val time = GetTimesAjaxPage.getTime(webInterface, currentTimeMillis() - 1000)
29                 assertThat(time.text, equalTo("a few seconds ago"))
30         }
31
32 }