All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.arildo.iris.mock.IrisMockCondition.kt Maven / Gradle / Ivy

Go to download

A kotlin-first tool to intercept android network calls, modify requests/responses and mock entire APIs

There is a newer version: 1.1.0
Show newest version
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