diff --git a/core/src/test/kotlin/dev/usbharu/multim/api/common/TestUtil.kt b/core/src/test/kotlin/dev/usbharu/multim/TestUtil.kt similarity index 81% rename from core/src/test/kotlin/dev/usbharu/multim/api/common/TestUtil.kt rename to core/src/test/kotlin/dev/usbharu/multim/TestUtil.kt index e08bba0..f117c38 100644 --- a/core/src/test/kotlin/dev/usbharu/multim/api/common/TestUtil.kt +++ b/core/src/test/kotlin/dev/usbharu/multim/TestUtil.kt @@ -1,5 +1,6 @@ -package dev.usbharu.multim.api.common +package dev.usbharu.multim +import com.github.michaelbull.result.* import io.ktor.client.* import io.ktor.client.engine.mock.* import io.ktor.client.plugins.contentnegotiation.* @@ -9,6 +10,7 @@ import io.ktor.serialization.kotlinx.json.* import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonObject import org.assertj.core.api.Fail.fail +import org.junit.jupiter.api.Assertions.assertInstanceOf object TestUtil { @@ -63,4 +65,14 @@ object TestUtil { } } } + + + fun assertIsOk(result: Result<*,*>){ + assertInstanceOf(Ok::class.java,result,"resultの型がOkではない") + } + + inline fun assertIsErr(result: Result<*,T>){ + assertInstanceOf(Err::class.java,result,"resultの型がErrではない") + assertInstanceOf(R::class.java,result.getError(),"Errorの型が違う") + } } diff --git a/core/src/test/kotlin/dev/usbharu/multim/api/AccountApiTest.kt b/core/src/test/kotlin/dev/usbharu/multim/api/AccountApiTest.kt new file mode 100644 index 0000000..9e6c340 --- /dev/null +++ b/core/src/test/kotlin/dev/usbharu/multim/api/AccountApiTest.kt @@ -0,0 +1,83 @@ +package dev.usbharu.multim.api + +import org.junit.jupiter.api.Test + +abstract class AccountApiTest { + + abstract val accountApi: AccountApi + + @Test + abstract fun userTimeline() + + @Test + open fun userTimeline_illegalAccount_returnErr() { + } + + @Test + open fun userTimeline_requestWithSinceId_returnRangeTimeline() { + } + + @Test + open fun userTimeline_requestWithUntilId_returnRangeTimeline() { + } + + @Test + open fun userTimeline_requestWithSinceIdAndUntilId_returnRangeTimeline() { + } + + + @Test + abstract fun follow() // フォローに関しては、どのように振る舞うべきかは実装によって違うので詳細なテストは書かない + + @Test + abstract fun follow_illegalAccount_returnErr() + + @Test + abstract fun unfollow() //アンフォローも同じ + + @Test + abstract fun unfollow_illegalAccount_returnErr() + + @Test + abstract fun profile() + + @Test + abstract fun profile_illegalAccount_returnErr() + + @Test + abstract fun statuses() + + @Test + abstract fun statusesWithIncludeRepost() + + @Test + abstract fun statuses_illegalAccount_returnErr() + + @Test + abstract fun relationships() + + @Test + open fun relationships_sameAccount_returnErr() { + } + + @Test + abstract fun relationships_illegalAccount_returnErr() + + @Test + abstract fun requestCancel() + + @Test + abstract fun requestCancel_illegalAccount_returnErr() + + @Test + abstract fun requestAccept() + + @Test + abstract fun requestAccept_illegalAccount_returnErr() + + @Test + abstract fun requestReject() + + @Test + abstract fun requestReject_illegalAccount_returnErr() +} diff --git a/core/src/test/kotlin/dev/usbharu/multim/api/ApiClientTest.kt b/core/src/test/kotlin/dev/usbharu/multim/api/ApiClientTest.kt new file mode 100644 index 0000000..b2b8b4a --- /dev/null +++ b/core/src/test/kotlin/dev/usbharu/multim/api/ApiClientTest.kt @@ -0,0 +1,138 @@ +package dev.usbharu.multim.api + +import com.github.michaelbull.result.Err +import com.github.michaelbull.result.get +import dev.usbharu.multim.TestUtil.assertIsErr +import dev.usbharu.multim.TestUtil.assertIsOk +import dev.usbharu.multim.error.HttpClientClientError +import dev.usbharu.multim.error.HttpClientServerError +import dev.usbharu.multim.error.ThrowableError +import io.ktor.client.call.* +import io.ktor.client.plugins.* +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.runTest +import kotlinx.serialization.Serializable +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test + +@OptIn(ExperimentalCoroutinesApi::class) +abstract class ApiClientTest { + + abstract var apiClient: ApiClient + + @Test + open fun postEmpty_emptyRequest_returnOk() = runTest { + val postEmpty = apiClient.postEmpty("postEmpty/emptyRequest/returnOk") + assertIsOk(postEmpty) + } + + @Test + open fun postEmpty_illegalRequest_returnErr() = runTest { + val postEmpty = apiClient.postEmpty("postEmpty/illegalRequest/returnErr") + assertInstanceOf(Err::class.java, postEmpty, "返り値がErr型ではない") + assertInstanceOf( + HttpClientClientError::class.java, + (postEmpty as Err).error, + "ErrorがHttpClientClientError型ではない" + ) + assertInstanceOf( + ClientRequestException::class.java, + postEmpty.error.throwable, + "throwableがClientRequestException型ではない" + ) + } + + @Test + fun postEmpty_serverError_returnErr() = runTest { + val postEmpty = apiClient.postEmpty("postEmpty/serverError/returnErr") + assertInstanceOf(Err::class.java, postEmpty, "返り値がErr型ではない") + assertInstanceOf( + HttpClientServerError::class.java, + (postEmpty as Err).error, + "ErrorがHttpClientServerError型ではない" + ) + assertInstanceOf( + ServerResponseException::class.java, + postEmpty.error.throwable, + "throwableがServerResponseException型ではない" + ) + } + + @Test + fun post_request_returnOkWithEchoBody() = runTest { + val expectBody = PostEmptyData("957a29f2-03bc-4856-b880-3ef42fbc4c77") + val actual = apiClient.post( + expectBody, + "post/request/returnOkWithEchoBody" + ) + assertIsOk(actual) + assertEquals(expectBody, actual.get()) + } + + @Test + fun post_illegalRequest_returnErr() = runTest { + val body = PostEmptyData("1974d2a0-552e-442d-a60c-07ab410d4e44") + val actual = apiClient.post( + body, + "post/illegalRequest/returnErr" + ) + assertIsErr(actual) + } + + @Test + fun post_serverError_returnErr() = runTest { + val body = PostEmptyData("3a84e1a1-5323-4158-824d-ccf9efee0bf7") + val actual = apiClient.post( + body, + "post/serverError/returnErr" + ) + assertIsErr(actual) + } + + @Test + fun postWithoutResponse_request_returnOk() = runTest { + val body = PostEmptyData("497676e7-731b-42cb-bc44-dee573858e66") + val actual = + apiClient.postWithoutResponse(body, "postWithoutResponse/request/returnOk") + assertIsOk(actual) + } + + @Test + fun postWithoutResponse_illegalRequest_returnErr() = runTest { + val body = PostEmptyData("20b04325-1386-4076-8068-fb6370ba6150") + val actual = + apiClient.postWithoutResponse(body, "postWithoutResponse/illegalRequest/returnErr") + assertIsErr(actual) + } + + @Test + fun postWithoutResponse_serverError_returnErr() = runTest { + val body = PostEmptyData("5ef770aa-b228-4b02-90dd-1c1866933f16") + val actual = + apiClient.postWithoutResponse(body, "postWithoutResponse/serverError/returnErr") + assertIsErr(actual) + } + + @Test + fun get_request_returnOk() = runTest { + val expectBody = PostEmptyData("43c56ee1-ad7a-418e-9411-2fcb61b34cf9") + val actual = apiClient.get("get/request/returnOk") {} + assertIsOk(actual) + assertEquals(expectBody, actual.get()?.body()) + } + + @Test + fun get_illegalRequest_returnErr() = runTest { + val actual = apiClient.get("get/illegalRequest/returnErr") {} + assertIsErr(actual) + } + + @Test + fun get_serverError_returnErr() = runTest { + val actual = apiClient.get("get/serverError/returnErr") {} + assertIsErr(actual) + } + + @Serializable + data class PostEmptyData(val testData: String) +} diff --git a/core/src/test/kotlin/dev/usbharu/multim/api/StatusApiTest.kt b/core/src/test/kotlin/dev/usbharu/multim/api/StatusApiTest.kt new file mode 100644 index 0000000..68f61c3 --- /dev/null +++ b/core/src/test/kotlin/dev/usbharu/multim/api/StatusApiTest.kt @@ -0,0 +1,93 @@ +package dev.usbharu.multim.api + +import org.junit.jupiter.api.Test + +abstract class StatusApiTest { + @Test + abstract fun post() + + @Test + abstract fun post_illegalStatus() + + @Test + abstract fun delete() + + @Test + abstract fun delete_illegalStatusId() + + @Test + abstract fun findById() + + @Test + abstract fun findById_illegalStatusId() + + @Test + abstract fun addReaction() + + @Test + abstract fun addReaction_illegalStatusId() + + @Test + abstract fun addReaction_illegalReaction() + + @Test + abstract fun removeReaction() + + @Test + abstract fun removeReaction_illegalStatusId() + + @Test + abstract fun removeReaction_illegalReaction() + + @Test + abstract fun reactions() + + @Test + abstract fun reaction_illegalStatusId() + + @Test + abstract fun replies() + + @Test + abstract fun replies_illegalStatusId() + + @Test + abstract fun repost() + + @Test + abstract fun repost_illegalStatusId() + + @Test + abstract fun unRepost() + + @Test + abstract fun unRepost_illegalStatusId() + + @Test + abstract fun replyTo() + + @Test + abstract fun replyTo_illegalStatusId() + + @Test + abstract fun replyTo_illegalStatus() + + @Test + abstract fun addToBookmarks() + + @Test + abstract fun addToBookmarks_illegalStatusId() + + @Test + abstract fun removeFromBookmarks() + + @Test + abstract fun removeFromBookmarks_illegalStatusId() + + @Test + abstract fun getPreviousAndNext() + + @Test + abstract fun getPreviousAndNext_illegalStatusIs() + +} diff --git a/core/src/test/kotlin/dev/usbharu/multim/api/TimelineApiTest.kt b/core/src/test/kotlin/dev/usbharu/multim/api/TimelineApiTest.kt new file mode 100644 index 0000000..33afe4c --- /dev/null +++ b/core/src/test/kotlin/dev/usbharu/multim/api/TimelineApiTest.kt @@ -0,0 +1,27 @@ +package dev.usbharu.multim.api + +import org.junit.jupiter.api.Test + +abstract class TimelineApiTest { + + @Test + abstract fun availableTimelines() + + @Test + abstract fun listen() + + @Test + abstract fun listen_illegalTimeline() + + @Test + abstract fun connect() + + @Test + abstract fun connect_illegalTimeline() + + @Test + abstract fun disconnect() + + @Test + abstract fun disconnect_illegalTimeline() +} diff --git a/core/src/test/kotlin/dev/usbharu/multim/api/factory/impl/DefaultPlatformApiFactoryTest.kt b/core/src/test/kotlin/dev/usbharu/multim/api/factory/impl/DefaultPlatformApiFactoryTest.kt deleted file mode 100644 index 1ba0860..0000000 --- a/core/src/test/kotlin/dev/usbharu/multim/api/factory/impl/DefaultPlatformApiFactoryTest.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.usbharu.multim.api.factory.impl - -import org.junit.jupiter.api.Test - -class DefaultPlatformApiFactoryTest { - @Test - fun testName() { - - } -}