From e79d0ac399d33ce69976ecbccb081c6fd5cc4616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Garc=C3=ADa?= Date: Mon, 7 Oct 2024 16:30:50 +0200 Subject: [PATCH] fix NoWhenBranchMatchedException #ANDROID-15269 (#24) --- .../com/telefonica/mock/ResponseDispatcher.kt | 4 ++-- .../main/java/com/telefonica/mock/models.kt | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mock/src/main/java/com/telefonica/mock/ResponseDispatcher.kt b/mock/src/main/java/com/telefonica/mock/ResponseDispatcher.kt index 1a3654e..f9ef8c6 100644 --- a/mock/src/main/java/com/telefonica/mock/ResponseDispatcher.kt +++ b/mock/src/main/java/com/telefonica/mock/ResponseDispatcher.kt @@ -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() @@ -45,4 +45,4 @@ class ResponseDispatcher @Inject constructor() { val mockListUpdated = (responses[requestInfo] ?: LinkedList()).apply { add(mockedResponse) } responses[requestInfo] = mockListUpdated } -} \ No newline at end of file +} diff --git a/mock/src/main/java/com/telefonica/mock/models.kt b/mock/src/main/java/com/telefonica/mock/models.kt index 80094bc..d1e4baf 100644 --- a/mock/src/main/java/com/telefonica/mock/models.kt +++ b/mock/src/main/java/com/telefonica/mock/models.kt @@ -12,8 +12,8 @@ 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 @@ -21,10 +21,10 @@ sealed class MockedResponse( } } -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, @@ -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, @@ -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) \ No newline at end of file +internal class RequestInfoWithPattern(val pathPattern: PatternMatcher, val method: Method)