X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FBookmarkAjaxPageTest.kt;h=00de5568207237028b9d6c8a8cf4d46f3a8cd10f;hp=1d26c71dff5033982b45bb55d056fbd77c8f6d1b;hb=ea7ad5e87074576d17b7df74365a726bd95d7665;hpb=acab609befb73e27ee91cfeae4966aaf76236b5f diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPageTest.kt index 1d26c71..00de556 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPageTest.kt @@ -1,8 +1,11 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.test.getInstance +import net.pterodactylus.sone.web.baseInjector import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo +import org.hamcrest.Matchers.notNullValue import org.junit.Test import org.mockito.ArgumentMatchers.any import org.mockito.Mockito.never @@ -11,35 +14,23 @@ import org.mockito.Mockito.verify /** * Unit test for [BookmarkAjaxPage]. */ -class BookmarkAjaxPageTest : JsonPageTest(::BookmarkAjaxPage) { - - @Test - fun `page returns correct path`() { - assertThat(page.path, equalTo("bookmark.ajax")) - } - - @Test - fun `page does not require login`() { - assertThat(page.requiresLogin(), equalTo(false)) - } +class BookmarkAjaxPageTest : JsonPageTest("bookmark.ajax", requiresLogin = false, pageSupplier = ::BookmarkAjaxPage) { @Test fun `missing post ID results in invalid id response`() { - assertThat(json.isSuccess, equalTo(false)) - assertThat((json as JsonErrorReturnObject).error, equalTo("invalid-post-id")) + assertThatJsonFailed("invalid-post-id") } @Test fun `empty post ID results in invalid id response`() { addRequestParameter("post", "") - assertThat(json.isSuccess, equalTo(false)) - assertThat((json as JsonErrorReturnObject).error, equalTo("invalid-post-id")) + assertThatJsonFailed("invalid-post-id") } @Test fun `invalid post ID results in success but does not bookmark anything`() { addRequestParameter("post", "missing") - assertThat(json.isSuccess, equalTo(true)) + assertThatJsonIsSuccessful() verify(core, never()).bookmarkPost(any()) } @@ -47,8 +38,13 @@ class BookmarkAjaxPageTest : JsonPageTest(::BookmarkAjaxPage) { fun `valid post ID results in success and bookmarks the post`() { addRequestParameter("post", "valid-post-id") val post = addNewPost("valid-post-id", "1", 2) - assertThat(json.isSuccess, equalTo(true)) + assertThatJsonIsSuccessful() verify(core).bookmarkPost(post) } + @Test + fun `page can be created by dependency injection`() { + assertThat(baseInjector.getInstance(), notNullValue()) + } + }