aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2020-02-04 23:53:35 -0800
committerAllan Wang <me@allanwang.ca>2020-02-04 23:53:35 -0800
commit665490012f48401346384e5f13ace14781379d70 (patch)
treee4d4afbe494a61b2d4eb5746e25b5cd9c517e54c /app/src
parentaf634a90b677695905c7f26c2017cf13805d5b2e (diff)
downloadfrost-665490012f48401346384e5f13ace14781379d70.tar.gz
frost-665490012f48401346384e5f13ace14781379d70.tar.bz2
frost-665490012f48401346384e5f13ace14781379d70.zip
Fix image activity test
Diffstat (limited to 'app/src')
-rw-r--r--app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ImageActivityTest.kt19
1 files changed, 17 insertions, 2 deletions
diff --git a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ImageActivityTest.kt b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ImageActivityTest.kt
index af730651..4433de25 100644
--- a/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ImageActivityTest.kt
+++ b/app/src/androidTest/kotlin/com/pitchedapps/frost/activities/ImageActivityTest.kt
@@ -24,6 +24,7 @@ import com.pitchedapps.frost.utils.ARG_COOKIE
import com.pitchedapps.frost.utils.ARG_IMAGE_URL
import com.pitchedapps.frost.utils.ARG_TEXT
import com.pitchedapps.frost.utils.isIndirectImageUrl
+import okhttp3.internal.closeQuietly
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNull
@@ -34,6 +35,8 @@ import okhttp3.mockwebserver.MockWebServer
import okhttp3.mockwebserver.RecordedRequest
import okio.Buffer
import okio.source
+import org.junit.After
+import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.Timeout
@@ -62,10 +65,22 @@ class ImageActivityTest {
activity.launchActivity(intent)
}
- private val mockServer: MockWebServer by lazy {
+ lateinit var mockServer: MockWebServer
+
+ @Before
+ fun before() {
+ mockServer = mockServer()
+ }
+
+ @After
+ fun after() {
+ mockServer.closeQuietly()
+ }
+
+ private fun mockServer(): MockWebServer {
val img = Buffer()
img.writeAll(getResource("bayer-pattern.jpg").source())
- MockWebServer().apply {
+ return MockWebServer().apply {
dispatcher = object : Dispatcher() {
override fun dispatch(request: RecordedRequest): MockResponse =
when {