File tree Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,10 @@ kotlin {
89
89
dependencies {
90
90
implementation ' org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.7'
91
91
implementation ' androidx.test.ext:junit:1.1.1'
92
+ implementation ' org.robolectric:robolectric:4.3.1'
93
+ implementation ' org.jetbrains.kotlin:kotlin-test'
94
+ implementation ' org.jetbrains.kotlin:kotlin-test-junit'
95
+ implementation ' io.ktor:ktor-client-android:1.3.2'
92
96
}
93
97
}
94
98
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ private class DispatcherImpl: Dispatcher() {
32
32
33
33
if (it.body != null ) {
34
34
setBody(it.body)
35
+ } else {
36
+ setHeader(" Content-Length" , 0 )
35
37
}
36
38
}
37
39
} ? : MockResponse ()
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package dev.michallaskowski.mokttp
2
2
3
3
import io.ktor.client.HttpClient
4
4
import io.ktor.client.request.get
5
+ import io.ktor.client.statement.HttpResponse
6
+ import io.ktor.http.HttpStatusCode
5
7
import kotlin.test.AfterTest
6
8
import kotlin.test.BeforeTest
7
9
import kotlin.test.Test
@@ -25,12 +27,7 @@ class HttpServerTest: BaseTest() {
25
27
}
26
28
27
29
@Test
28
- fun someTest () = runTest {
29
- assertEquals(1 , 1 )
30
- }
31
-
32
- @Test
33
- fun returns200OkForProperPath () = runTest {
30
+ fun returnsResponsePerPath () = runTest {
34
31
server.router = object : Router {
35
32
override fun handleRequest (request : Request ): Response {
36
33
if (request.path != " /test" ) {
@@ -44,6 +41,8 @@ class HttpServerTest: BaseTest() {
44
41
45
42
val response = client.get<String >(" http://localhost:8080/test" )
46
43
assertEquals(response, " test" )
47
- }
48
44
45
+ val httpResponse = client.get<HttpResponse >(" http://localhost:8080/notTest" )
46
+ assertEquals(httpResponse.status, HttpStatusCode .NotFound )
47
+ }
49
48
}
You can’t perform that action at this time.
0 commit comments