Skip to content

Commit e79d0ac

Browse files
authored
fix NoWhenBranchMatchedException #ANDROID-15269 (#24)
1 parent 2b2d2a0 commit e79d0ac

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

mock/src/main/java/com/telefonica/mock/ResponseDispatcher.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ResponseDispatcher @Inject constructor() {
2424
return when {
2525
responseList.isNullOrEmpty() -> MockResponse().setResponseCode(MockedServer.RESPONSE_NOT_FOUND_CODE)
2626
else -> {
27-
val response = responseList.poll()
27+
val response = responseList.poll() ?: return MockResponse().setResponseCode(MockedServer.RESPONSE_NOT_FOUND_CODE)
2828
responseList.add(response)
2929
when (response) {
3030
is MockedApiResponse -> MockResponse()
@@ -45,4 +45,4 @@ class ResponseDispatcher @Inject constructor() {
4545
val mockListUpdated = (responses[requestInfo] ?: LinkedList()).apply { add(mockedResponse) }
4646
responses[requestInfo] = mockListUpdated
4747
}
48-
}
48+
}

mock/src/main/java/com/telefonica/mock/models.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ sealed class Method(val value: String) {
1212
}
1313

1414
sealed class MockedResponse(
15-
val httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
16-
val delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
15+
open val httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
16+
open val delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
1717
) {
1818
companion object {
1919
const val DEFAULT_MOCK_DELAY_IN_MILLIS = 0L
2020
const val DEFAULT_MOCK_HTTP_RESPONSE_CODE = 200
2121
}
2222
}
2323

24-
class MockedApiResponse(
24+
data class MockedApiResponse(
2525
val body: String = DEFAULT_BODY,
26-
httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
27-
delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
26+
override val httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
27+
override val delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
2828
) : MockedResponse(
2929
httpResponseCode,
3030
delayInMillis,
@@ -34,10 +34,10 @@ class MockedApiResponse(
3434
}
3535
}
3636

37-
class MockedBufferedResponse(
37+
data class MockedBufferedResponse(
3838
val buffer: Buffer,
39-
httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
40-
delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
39+
override val httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
40+
override val delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
4141
) : MockedResponse(
4242
httpResponseCode,
4343
delayInMillis,
@@ -48,4 +48,4 @@ internal class RequestAndResponse(val requestInfo: RequestInfo, val mockedRespon
4848
data class RequestInfo(val path: Path, val method: Method)
4949
typealias Path=String
5050

51-
internal class RequestInfoWithPattern(val pathPattern: PatternMatcher, val method: Method)
51+
internal class RequestInfoWithPattern(val pathPattern: PatternMatcher, val method: Method)

0 commit comments

Comments
 (0)