X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FJsonPageTest.kt;h=84fca496d53d0d6ff0d88233dac54245876b7f12;hp=e5621f0aaaa8d0884d5324b8b9d4e89d89a82a5e;hb=43278c5468221baa16946a5206c3a4e97d543010;hpb=d58ef344b43543fdcfca13c07df87e194f004376 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 e5621f0..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`() {