This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun setPrefetchBound(viewType: Int, count: Int) { | |
| recycledViewsBounds[viewType] = max(defaultMaxRecycledViews, count) | |
| viewHolderSupplier.setPrefetchBound(viewType, count) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PrefetchViewPool( | |
| private val defaultMaxRecycledViews: Int, | |
| private val viewHolderSupplier: ViewHolderSupplier | |
| ) : RecyclerView.RecycledViewPool() { | |
| private val recycledViewsBounds = mutableMapOf<Int, Int>() | |
| init { | |
| attachToPreventFromClearing() | |
| viewHolderSupplier.viewHolderConsumer = ::putViewFromSupplier |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class BaseTestCase : MockModelScope { | |
| @get:Rule | |
| val rule: RuleChain by lazy { | |
| var chain = RuleChain.outerRule(RetryTestRule()) | |
| if (isMockServerEnabled) chain = chain.around(mockWebServerRule) | |
| chain = chain.around(activityTestRule) | |
| chain | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MockDispatcher(httpMocks: Set<MockModelWrapper>) : Dispatcher() { | |
| private val httpMocksMap: Map<RequestMarkers, MockResponseModel> | |
| private val requestsCount = mutableMapOf<RequestMarkers, Int>() | |
| init { | |
| httpMocksMap = mutableMapOf<RequestMarkers, MockResponseModel>().apply { | |
| putAll(httpMocks.map { wrapper -> wrapper.markers to wrapper.responseModel }) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MockResponseModel( | |
| private val code: Int = 200, | |
| private val headers: Map<String, String> = mapOf(), | |
| private val body: String = "{}", | |
| val retryAttempts: Map<Int, MockResponseModel> = mapOf() | |
| ) { | |
| val asMockResponse: MockResponse | |
| get() = MockResponse() | |
| .setResponseCode(code) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data class RequestMarkers( | |
| val path: String, | |
| val methodName: String? = null | |
| ) | |
| val RecordedRequest.asRequestMarkers: RequestMarkers | |
| get() { | |
| val jsonBody = runCatching { JSONObject(body.inputStream().readToString()) }.getOrNull() | |
| return RequestMarkers( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MockModelWrapper( | |
| val markers: RequestMarkers, | |
| val responseModel: MockResponseModel | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| staging { | |
| buildConfigField 'String', 'BASE_URL', '\"https://some_staging_url.com\"' | |
| } | |
| production { | |
| buildConfigField 'String', 'BASE_URL', '\"https://some_production_url.com\"' | |
| } | |
| instrumented { | |
| buildConfigField 'String', 'BASE_URL', '\"http://localhost:8000\"' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| staging { | |
| buildConfigField 'String', 'BASE_URL', '\"https://some_staging_url.com\"' | |
| } | |
| production { | |
| buildConfigField 'String', 'BASE_URL', '\"https://some_production_url.com\"' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MockWebServerRule(httpMocks: Set<MockModelWrapper>) : TestRule { | |
| private val server = MockWebServer() | |
| init { | |
| server.setDispatcher(MockDispatcher(httpMocks)) | |
| val port = BuildConfig.BASE_URL.substringAfterLast(':').toInt() | |
| server.start(port) | |
| } |