Skip to content

Commit

Permalink
fix NoWhenBranchMatchedException #ANDROID-15269 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
juangardi21 authored Oct 7, 2024
1 parent 2b2d2a0 commit e79d0ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions mock/src/main/java/com/telefonica/mock/ResponseDispatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ResponseDispatcher @Inject constructor() {
return when {
responseList.isNullOrEmpty() -> MockResponse().setResponseCode(MockedServer.RESPONSE_NOT_FOUND_CODE)
else -> {
val response = responseList.poll()
val response = responseList.poll() ?: return MockResponse().setResponseCode(MockedServer.RESPONSE_NOT_FOUND_CODE)
responseList.add(response)
when (response) {
is MockedApiResponse -> MockResponse()
Expand All @@ -45,4 +45,4 @@ class ResponseDispatcher @Inject constructor() {
val mockListUpdated = (responses[requestInfo] ?: LinkedList()).apply { add(mockedResponse) }
responses[requestInfo] = mockListUpdated
}
}
}
18 changes: 9 additions & 9 deletions mock/src/main/java/com/telefonica/mock/models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ sealed class Method(val value: String) {
}

sealed class MockedResponse(
val httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
val delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
open val httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
open val delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
) {
companion object {
const val DEFAULT_MOCK_DELAY_IN_MILLIS = 0L
const val DEFAULT_MOCK_HTTP_RESPONSE_CODE = 200
}
}

class MockedApiResponse(
data class MockedApiResponse(
val body: String = DEFAULT_BODY,
httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
override val httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
override val delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
) : MockedResponse(
httpResponseCode,
delayInMillis,
Expand All @@ -34,10 +34,10 @@ class MockedApiResponse(
}
}

class MockedBufferedResponse(
data class MockedBufferedResponse(
val buffer: Buffer,
httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
override val httpResponseCode: Int = DEFAULT_MOCK_HTTP_RESPONSE_CODE,
override val delayInMillis: Long = DEFAULT_MOCK_DELAY_IN_MILLIS,
) : MockedResponse(
httpResponseCode,
delayInMillis,
Expand All @@ -48,4 +48,4 @@ internal class RequestAndResponse(val requestInfo: RequestInfo, val mockedRespon
data class RequestInfo(val path: Path, val method: Method)
typealias Path=String

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

0 comments on commit e79d0ac

Please sign in to comment.