Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions core/src/main/kotlin/dev/usbharu/multim/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import dev.usbharu.multim.error.ThrowableError
object Logger {

const val nullString = "null"
fun info(tag: String? = null, message: String? = null) =
fun info(tag: String? = null, message: String? = null) {
Napier.i(message ?: nullString, null, tag)
}

fun info(message: String? = null) = Napier.i(message ?: nullString)
fun info(message: String? = null) {
Napier.i(message ?: nullString)
}

fun info(tag: String? = null, message: String? = null, throwable: Throwable? = null) =
fun info(tag: String? = null, message: String? = null, throwable: Throwable? = null) {
Napier.i(message ?: nullString, throwable, tag)
}

fun info(tag: String? = null, message: String? = null, error: Error) {
message?.let { Napier.i(it, null, tag) }
Expand All @@ -24,13 +28,17 @@ object Logger {
}
}

fun debug(tag: String? = null, message: String? = null) =
fun debug(tag: String? = null, message: String? = null) {
Napier.d(message ?: nullString, null, tag)
}

fun debug(message: String? = null) = Napier.d(message ?: nullString)
fun debug(message: String? = null) {
Napier.d(message ?: nullString)
}

fun debug(tag: String? = null, message: String? = null, throwable: Throwable? = null) =
fun debug(tag: String? = null, message: String? = null, throwable: Throwable? = null) {
Napier.d(message ?: nullString, throwable, tag)
}

fun debug(tag: String? = null, message: String? = null, error: Error) {
message?.let { Napier.d(it, null, tag) }
Expand All @@ -41,13 +49,17 @@ object Logger {
}
}

fun error(tag: String? = null, message: String? = null) =
fun error(tag: String? = null, message: String? = null) {
Napier.e(message ?: nullString, null, tag)
}

fun error(message: String? = null) = Napier.e(message ?: nullString)
fun error(message: String? = null) {
Napier.e(message ?: nullString)
}

fun error(tag: String? = null, message: String? = null, throwable: Throwable? = null) =
fun error(tag: String? = null, message: String? = null, throwable: Throwable? = null) {
Napier.e(message ?: nullString, throwable, tag)
}

fun error(tag: String? = null, message: String? = null, error: Error) {
message?.let { Napier.e(it, null, tag) }
Expand All @@ -58,13 +70,17 @@ object Logger {
}
}

fun warn(tag: String? = null, message: String? = null) =
fun warn(tag: String? = null, message: String? = null) {
Napier.w(message ?: nullString, null, tag)
}

fun warn(message: String? = null) = Napier.w(message ?: nullString)
fun warn(message: String? = null) {
Napier.w(message ?: nullString)
}

fun warn(tag: String? = null, message: String? = null, throwable: Throwable? = null) =
fun warn(tag: String? = null, message: String? = null, throwable: Throwable? = null) {
Napier.w(message ?: nullString, throwable, tag)
}

fun warn(tag: String? = null, message: String? = null, error: Error) {
message?.let { Napier.w(it, null, tag) }
Expand All @@ -75,13 +91,17 @@ object Logger {
}
}

fun trace(tag: String? = null, message: String? = null) =
fun trace(tag: String? = null, message: String? = null) {
Napier.v(message ?: nullString, null, tag)
}

fun trace(message: String? = null) = Napier.v(message ?: nullString)
fun trace(message: String? = null) {
Napier.v(message ?: nullString)
}

fun trace(tag: String? = null, message: String? = null, throwable: Throwable? = null) =
fun trace(tag: String? = null, message: String? = null, throwable: Throwable? = null) {
Napier.v(message ?: nullString, throwable, tag)
}

fun trace(tag: String? = null, message: String? = null, error: Error) {
message?.let { Napier.v(it, null, tag) }
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/kotlin/dev/usbharu/multim/api/AccountApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ interface AccountApi {
suspend fun statuses(
account: Account,
includeRepost: Boolean = false,
since:StatusId? = null,
until:StatusId? = null,
since: StatusId? = null,
until: StatusId? = null,
): Result<List<Status>, MultiMError> {
Logger.debug("Account Api", "Not impl account api. statuses.")
return Err(MultiMError("statuses not implements", null, ErrorType.NOT_IMPL))
}

val RELEATIONSHIPS: String
val RELATIONSHIPS: String
get() = "account/relationships"

suspend fun relationships(myself: Account, other: Account): Result<Relation, MultiMError> {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/dev/usbharu/multim/api/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ abstract class ApiClient(var baseUrl: String, val client: HttpClient) {
} catch (e: ServerResponseException) {
return Err(HttpClientServerError(e))
}
Logger.warn(post.bodyAsText())
// Logger.warn(post.bodyAsText())
return runCatching<R> { post.body() }.fold(
onSuccess = { Ok(it) },
onFailure = {
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/kotlin/dev/usbharu/multim/api/StatusApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ interface StatusApi {
(status.content.text + status.account.accountName + date).encodeToByteArray()
).toInt()
}
val AVAILABLE_REACTIONS:String

val AVAILABLE_REACTIONS: String
get() = "status/availableReactions"

suspend fun availableReactions(): MultiMResult<List<Reaction>> {
Logger.debug("Status Api", "Not impl status api availableReactions")
return Err(MultiMError("availableReactions not implements", null, ErrorType.NOT_IMPL))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ interface StringIdAccountApi : AccountApi {
suspend fun statuses(
accountId: String,
includeRepost: Boolean = false,
since:String? = null,
until:String? = null
since: String? = null,
until: String? = null
): MultiMResult<List<Status>> {
Logger.debug("Account Api", "Not impl account api. statuses by id.")
return Err(MultiMError("statuses by id not implements", null, ErrorType.NOT_IMPL))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CacheableAccountApi(
myself: Account,
other: Account
): Result<Relation, MultiMError> {
return cacheableApi.cacheOrGet(RELEATIONSHIPS, myself, other) {
return cacheableApi.cacheOrGet(RELATIONSHIPS, myself, other) {
accountApi.relationships(
myself,
other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MultiAccountApiBase(val serviceList: List<ServiceInfo>) {

val factory = ServiceInfoFactory(serviceList)

val httpClient = MultiM.httpClientWithJson.config({})
val httpClient = MultiM.httpClientWithJson.config {}

val apiClientMap = mutableMapOf<Int, MultiMApis>()

Expand Down
29 changes: 23 additions & 6 deletions core/src/test/kotlin/dev/usbharu/multim/TestUtil.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package dev.usbharu.multim

import com.github.michaelbull.result.Err
import com.github.michaelbull.result.Ok
import com.github.michaelbull.result.Result
import com.github.michaelbull.result.getError
import com.github.michaelbull.result.*
import dev.usbharu.multim.error.ErrorType
import dev.usbharu.multim.error.MultiMResult
import io.ktor.client.*
import io.ktor.client.engine.mock.*
import io.ktor.client.plugins.contentnegotiation.*
Expand All @@ -12,8 +11,8 @@ import io.ktor.http.*
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
import org.junit.jupiter.api.fail


object TestUtil {
Expand Down Expand Up @@ -67,7 +66,7 @@ object TestUtil {
respond(respond, status, headers)
} else {
fail("Not authed")
respondBadRequest()
// respondBadRequest()
}
}
}
Expand All @@ -81,4 +80,22 @@ object TestUtil {
assertInstanceOf(Err::class.java, result, "resultの型がErrではない")
assertInstanceOf(R::class.java, result.getError(), "Errorの型が違う")
}

fun <T> MultiMResult<T>.failOnError(): T {
val get = this.get()
if (get != null) {
return get
}
val error = this.getError()!!
fail("Return Error ${error.message}", error.throwable)
}

fun MultiMResult<*>.failOnSuccess() {
this.onSuccess { fail("成功してはいけない") }
this.onFailure {
if (it.errorType != ErrorType.NOT_IMPL) {
fail("エラータイプが未実装ではない")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dev.usbharu.multim.api

import dev.usbharu.multim.TestUtil.failOnSuccess
import dev.usbharu.multim.model.Account
import dev.usbharu.multim.model.Avatar
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test

@OptIn(ExperimentalCoroutinesApi::class)
class NotImplAccountApiTest {
val avatar = object : Avatar("") {}

val account = object : Account("", "", false, avatar) {
override val cacheKey: String
get() = TODO("Not yet implemented")

}

@Test
fun userTimeline() = runTest {
@Suppress("DEPRECATION")
NotImplAccountApi.userTimeline(account).failOnSuccess()
}

@Test
fun follow() = runTest {
NotImplAccountApi.follow(account).failOnSuccess()
}

@Test
fun unfollow() = runTest {
NotImplAccountApi.unfollow(account).failOnSuccess()
}

@Test
fun profile() = runTest {
NotImplAccountApi.profile(account).failOnSuccess()
}


@Test
fun statuses() = runTest {
NotImplAccountApi.statuses(account).failOnSuccess()
}


@Test
fun relationships() = runTest {
NotImplAccountApi.relationships(account, account).failOnSuccess()
}


@Test
fun requestCancel() = runTest {
NotImplAccountApi.requestCancel(account).failOnSuccess()
}


@Test
fun requestAccept() = runTest {
NotImplAccountApi.requestAccept(account).failOnSuccess()
}

@Test
fun requestReject() = runTest {
NotImplAccountApi.requestReject(account).failOnSuccess()
}
}
21 changes: 21 additions & 0 deletions core/src/test/kotlin/dev/usbharu/multim/api/NotImplEmojiApiTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.usbharu.multim.api

import dev.usbharu.multim.TestUtil.failOnSuccess
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test

@OptIn(ExperimentalCoroutinesApi::class)
class NotImplEmojiApiTest {

@Test
fun get() = runTest {
NotImplEmojiApi.get("dgeB0b").failOnSuccess()
}

@Test
fun findByName() = runTest {
NotImplEmojiApi.findByName("KR4y61").failOnSuccess()
}
}
22 changes: 22 additions & 0 deletions core/src/test/kotlin/dev/usbharu/multim/api/NotImplIApiTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.usbharu.multim.api

import dev.usbharu.multim.TestUtil.failOnSuccess
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.*

import org.junit.jupiter.api.Test

@OptIn(ExperimentalCoroutinesApi::class)
class NotImplIApiTest {

@Test
fun profile() = runTest {
NotImplIApi.profile().failOnSuccess()
}

@Test
fun statuses() = runTest {
NotImplIApi.statuses().failOnSuccess()
}
}
Loading