X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FJsonPageTest.kt;h=84fca496d53d0d6ff0d88233dac54245876b7f12;hb=43278c5468221baa16946a5206c3a4e97d543010;hp=558b41466329842fdeb26701cb64771d7f1c6f61;hpb=f339996e95e45359e14becbe62d49863cf26acfd;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt index 558b414..84fca49 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt @@ -13,14 +13,23 @@ abstract class JsonPageTest( private val expectedPath: String, private val requiresLogin: Boolean = true, private val needsFormPassword: Boolean = true, - pageSupplier: (WebInterface) -> JsonPage = { mock() }): TestObjects() { + pageSupplier: (WebInterface) -> JsonPage = { mock() }) : TestObjects() { protected open val page: JsonPage by lazy { pageSupplier(webInterface) } protected val json by lazy { page.createJsonObject(freenetRequest) } - protected val JsonReturnObject.error get() = if (this is JsonErrorReturnObject) this.error else null + private val JsonReturnObject.error get() = if (this is JsonErrorReturnObject) this.error else null + + protected fun assertThatJsonIsSuccessful() { + assertThat(json.isSuccess, equalTo(true)) + } + + protected fun assertThatJsonFailed(error: String? = null) { + assertThat(json.isSuccess, equalTo(false)) + error?.run { assertThat(json.error, equalTo(this)) } + } @Test fun `page returns correct path`() { @@ -29,12 +38,12 @@ abstract class JsonPageTest( @Test fun `page needs form password`() { - assertThat(page.needsFormPassword(), equalTo(needsFormPassword)) + assertThat(page.needsFormPassword, equalTo(needsFormPassword)) } @Test fun `page requires login`() { - assertThat(page.requiresLogin(), equalTo(requiresLogin)) + assertThat(page.requiresLogin, equalTo(requiresLogin)) } }