1
0
mirror of https://github.com/square/okhttp.git synced 2025-11-24 18:41:06 +03:00

Test Android with Play provider (#5679)

This commit is contained in:
Yuri Schimke
2020-01-02 07:04:58 +00:00
committed by GitHub
parent bb819709ec
commit 3e61ce3cf0
4 changed files with 68 additions and 23 deletions

View File

@@ -23,6 +23,7 @@ import org.junit.runner.Description
import org.junit.runners.model.Statement
import java.net.InetAddress
import java.util.concurrent.TimeUnit
import java.util.logging.Logger
/**
* Apply this rule to all tests. It adds additional checks for leaked resources and uncaught
@@ -35,11 +36,16 @@ class OkHttpClientTestRule : TestRule {
private val clientEventsList = mutableListOf<String>()
private var testClient: OkHttpClient? = null
private var uncaughtException: Throwable? = null
var logger: Logger? = null
fun wrap(eventListener: EventListener) = object : EventListener.Factory {
override fun create(call: Call) = ClientRuleEventListener(eventListener) { addEvent(it) }
}
fun wrap(eventListenerFactory: EventListener.Factory) = object : EventListener.Factory {
override fun create(call: Call) = ClientRuleEventListener(eventListenerFactory.create(call)) { addEvent(it) }
}
/**
* Returns an OkHttpClient for tests to use as a starting point.
*
@@ -68,6 +74,7 @@ class OkHttpClientTestRule : TestRule {
}
@Synchronized private fun addEvent(event: String) {
logger?.info(event)
clientEventsList.add(event)
}