/**
* 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`() {
/**
* Unit test for [CreatePostAjaxPage].
*/
-class CreatePostAjaxPageTest : JsonPageTest(::CreatePostAjaxPage) {
-
- @Test
- fun `page returns correct path`() {
- assertThat(page.path, equalTo("createPost.ajax"))
- }
-
- @Test
- fun `page needs form password`() {
- assertThat(page.needsFormPassword(), equalTo(true))
- }
-
- @Test
- fun `page requires login`() {
- assertThat(page.requiresLogin(), equalTo(true))
- }
+class CreatePostAjaxPageTest : JsonPageTest("createPost.ajax", pageSupplier = ::CreatePostAjaxPage) {
@Test
fun `page requires a current sone`() {
/**
* Unit test for [CreateReplyAjaxPage].
*/
-class CreateReplyAjaxPageTest : JsonPageTest(::CreateReplyAjaxPage) {
-
- @Test
- fun `page returns correct path`() {
- assertThat(page.path, equalTo("createReply.ajax"))
- }
-
- @Test
- fun `page needs form password`() {
- assertThat(page.needsFormPassword(), equalTo(true))
- }
-
- @Test
- fun `page requires login`() {
- assertThat(page.requiresLogin(), equalTo(true))
- }
+class CreateReplyAjaxPageTest : JsonPageTest("createReply.ajax", pageSupplier = ::CreateReplyAjaxPage) {
@Test
fun `invalid post ID results in error message`() {
/**
* Unit test for [GetLinkedElementAjaxPage].
*/
-class GetLinkedElementAjaxPageTest: JsonPageTest() {
+class GetLinkedElementAjaxPageTest: JsonPageTest("getLinkedElement.ajax", requiresLogin = false, needsFormPassword = false) {
private val linkedElementRenderFilter = mock<LinkedElementRenderFilter>()
override var page: JsonPage = GetLinkedElementAjaxPage(webInterface, elementLoader, linkedElementRenderFilter)
@Test
- fun `page returns correct path`() {
- assertThat(page.path, equalTo("getLinkedElement.ajax"))
- }
-
- @Test
- fun `page does not require login`() {
- assertThat(page.requiresLogin(), equalTo(false))
- }
-
- @Test
- fun `page does not require form password`() {
- assertThat(page.needsFormPassword(), equalTo(false))
- }
-
- @Test
fun `only loaded linked elements are returned`() {
addRequestParameter("elements", jsonArray("KSK@foo.png", "KSK@foo.jpg", "KSK@foo.html").toString())
addLinkedElement("KSK@foo.png", true, false)
/**
* Unit test for [GetStatusAjaxPage].
*/
-class GetStatusAjaxPageTest: JsonPageTest() {
+class GetStatusAjaxPageTest: JsonPageTest("getStatus.ajax", requiresLogin = false, needsFormPassword = false) {
private val timeTextConverter = mock<TimeTextConverter>()
private val l10nFilter = mock<L10nFilter>()
}
@Test
- fun `page returns correct path`() {
- assertThat(page.path, equalTo("getStatus.ajax"))
- }
-
- @Test
- fun `page does not require form password`() {
- assertThat(page.needsFormPassword(), equalTo(false))
- }
-
- @Test
- fun `page does not require login`() {
- assertThat(page.requiresLogin(), equalTo(false))
- }
-
- @Test
fun `page returns correct attribute “loggedIn” if sone is logged in`() {
assertThat(json.get("loggedIn").asText(), equalTo("true"))
}
import net.pterodactylus.sone.web.page.FreenetRequest
import net.pterodactylus.util.notify.Notification
import net.pterodactylus.util.web.Method.GET
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
import org.junit.Before
+import org.junit.Test
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyString
/**
* Base class for tests for any [JsonPage] implementations.
*/
-open class JsonPageTest(pageSupplier: (WebInterface) -> JsonPage = { _ -> mock<JsonPage>() }) {
+abstract class JsonPageTest(
+ private val expectedPath: String,
+ private val requiresLogin: Boolean = true,
+ private val needsFormPassword: Boolean = true,
+ pageSupplier: (WebInterface) -> JsonPage = { _ -> mock<JsonPage>() }) {
protected val webInterface = mock<WebInterface>()
protected val core = mock<Core>()
linkedElements[link] = LinkedElement(link, failed, loading)
}
+ @Test
+ fun `page returns correct path`() {
+ assertThat(page.path, equalTo(expectedPath))
+ }
+
+ @Test
+ fun `page needs form password`() {
+ assertThat(page.needsFormPassword(), equalTo(needsFormPassword))
+ }
+
+ @Test
+ fun `page requires login`() {
+ assertThat(page.requiresLogin(), equalTo(requiresLogin))
+ }
+
}