dev.arildo.iris.mock.IrisMockCondition.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of iris-mock Show documentation
Show all versions of iris-mock Show documentation
A kotlin-first tool to intercept android network calls, modify requests/responses and mock entire APIs
package dev.arildo.iris.mock
import okhttp3.Request
class IrisMockCondition internal constructor(
internal val method: String,
internal val shouldIntercept: Boolean,
internal val irisMockScope: IrisMockScope
)
internal fun IrisMockScope.createCondition(
request: Request,
contains: String,
endsWith: String,
method: String
): IrisMockCondition {
val url = request.url().toString()
val chainMethod = request.method()
return IrisMockCondition(
method = method,
irisMockScope = this,
shouldIntercept = when {
endsWith.isNotBlank() && contains.isNotBlank() -> {
throw IllegalArgumentException("Must provide only one string matcher")
}
endsWith.isNotBlank() -> {
url.endsWith(endsWith, true) && chainMethod == method
}
contains.isNotBlank() -> {
url.contains(contains, true) && chainMethod == method
}
else -> throw IllegalArgumentException("Must provide a string to match on url")
}
)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy