From 4cc2c76f924e2faa17b2b69eb30add5b88abf28a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 19 Nov 2016 00:24:12 +0100 Subject: [PATCH] =?utf8?q?Replace=20unit=20test=20for=20=E2=80=9Cget=20tim?= =?utf8?q?es=E2=80=9D=20AJAX=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../sone/web/ajax/GetTimesAjaxPageTest.java | 39 ---------------------- .../sone/web/ajax/GetTimesAjaxPageTest.kt | 32 ++++++++++++++++++ .../net/pterodactylus/sone/test/Mockotlin.kt | 1 + 3 files changed, 33 insertions(+), 39 deletions(-) delete mode 100644 src/test/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.java create mode 100644 src/test/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt diff --git a/src/test/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.java b/src/test/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.java deleted file mode 100644 index e1ab857..0000000 --- a/src/test/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.pterodactylus.sone.web.ajax; - -import static java.lang.System.currentTimeMillis; -import static net.pterodactylus.sone.web.ajax.GetTimesAjaxPage.getTime; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.when; - -import net.pterodactylus.sone.web.WebInterface; -import net.pterodactylus.sone.web.ajax.GetTimesAjaxPage.Time; - -import org.junit.Test; -import org.mockito.Mockito; - -/** - * Unit test for {@link GetTimesAjaxPage}. - * - * @author David ‘Bombe’ Roden - */ -public class GetTimesAjaxPageTest { - - private final WebInterface webInterface = Mockito.mock(WebInterface.class, RETURNS_DEEP_STUBS); - - @Test - public void timestampInTheFutureIsTranslatedCorrectly() { - when(webInterface.getL10n().getString("View.Time.InTheFuture")).thenReturn("in the future"); - Time time = getTime(webInterface, currentTimeMillis() + 100); - assertThat(time.getText(), is("in the future")); - } - - @Test - public void timestampAFewSecondsAgoIsTranslatedCorrectly() { - when(webInterface.getL10n().getString("View.Time.AFewSecondsAgo")).thenReturn("a few seconds ago"); - Time time = getTime(webInterface, currentTimeMillis() - 1000); - assertThat(time.getText(), is("a few seconds ago")); - } - -} diff --git a/src/test/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt b/src/test/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt new file mode 100644 index 0000000..4c35a9d --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPageTest.kt @@ -0,0 +1,32 @@ +package net.pterodactylus.sone.web.ajax + +import net.pterodactylus.sone.test.deepMock +import net.pterodactylus.sone.test.whenever +import net.pterodactylus.sone.web.WebInterface +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Test +import java.lang.System.currentTimeMillis + +/** + * Unit test for [GetTimesAjaxPage]. + */ +class GetTimesAjaxPageTest { + + private val webInterface = deepMock() + + @Test + fun timestampInTheFutureIsTranslatedCorrectly() { + whenever(webInterface.l10n.getString("View.Time.InTheFuture")).thenReturn("in the future") + val time = GetTimesAjaxPage.getTime(webInterface, currentTimeMillis() + 1000) + assertThat(time.text, equalTo("in the future")) + } + + @Test + fun timestampAFewSecondsAgoIsTranslatedCorrectly() { + whenever(webInterface.l10n.getString("View.Time.AFewSecondsAgo")).thenReturn("a few seconds ago") + val time = GetTimesAjaxPage.getTime(webInterface, currentTimeMillis() - 1000) + assertThat(time.text, equalTo("a few seconds ago")) + } + +} diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt b/src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt index c8d93cc..eba2012 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/Mockotlin.kt @@ -5,6 +5,7 @@ import org.mockito.ArgumentCaptor import org.mockito.Mockito inline fun mock(): T = Mockito.mock(T::class.java)!! +inline fun deepMock(): T = Mockito.mock(T::class.java, Mockito.RETURNS_DEEP_STUBS)!! inline fun capture(): ArgumentCaptor = ArgumentCaptor.forClass(T::class.java) inline fun bind(implementation: T): Module = -- 2.7.4