Skip to content

Instantly share code, notes, and snippets.

View yatsinar's full-sized avatar

Roman Iatcyna yatsinar

View GitHub Profile
package io.reactivex.android.schedulers;
public class HandlerScheduler extends Scheduler {
//...
private static final class HandlerWorker extends Worker {
public Disposable schedule(Runnable run, long delay, TimeUnit unit) {
@Test
fun `WHEN local holding is missing in Portfolio THEN it is removed from memory and DB`() {
//code stubbing this particular case is omitted due to complexity here
repository.observePortfolio(forceReload = true).test()
ioScheduler.triggerActions()
verify(holdingsDao).deleteHoldingById(eq("4"))
verify(memoryCache).remove(eq("${HOLDING}_4"))
@Test
fun `NOT FORCE observing data WHEN memory cache IS NOT EMPTY`() {
whenever(fromMemory.invoke(eq(key), eq(params))).thenReturn(cachedDomain)
whenever(paramsKey.invoke(eq(params))).thenReturn(key)
val testObserver = dataObservableDelegate.observe(params = params, forceReload = false).test()
testObserver.assertValueCount(1)
testObserver.assertValueAt(0) {
it.content == cachedDomain && it.error == null && !it.loading
private val observePortfolioDod: DataObservableDelegate<Any, String, Portfolio> = DataObservableDelegate(
//other dod params
toMemory = { key, _, portfolio ->
memoryCache[key] = portfolio
//Update holdingsDod with holdings present in Portfolio
portfolio.holdings.forEach { holding ->
holdingsDod.updateAll(holding.id, holding)
}
./gradlew startSwarm ./gradlew executeScreenshotTests -Pandroid.testInstrumentationRunnerArguments.package=com.revolut.espresso.tests.screenshots stopSwarm
apply plugin: 'keith.thompson.swarmer'
swarmer {
virtualDevices {
Pixel_XL {
packages = "system-images;android-26;google_apis;x86"
androidAbi = "google_apis/x86"
pathToConfigIni = "emulator_config.ini"
class StockRateDelegateTest {
private lateinit var delegate: StockRateDelegate
private lateinit var vh: StockRateDelegate.ViewHolder
private fun stubStockDelegateModel(
title: String,
ticker: String,
price: String
) = StockRateDelegate.Model(
fun <T, VH : RecyclerView.ViewHolder> BaseRecyclerViewDelegate<T, VH>.bind(vh: VH, model: T) =
InstrumentationRegistry.getInstrumentation().runOnMainSync {
onBindViewHolder(vh, model, 0, null)
}
fun RecyclerView.ViewHolder.setUpAndSnap() {
ViewHelpers.setupView(itemView).setExactWidthDp(DELEGATE_TEST_WIDTH_DP).layout()
Screenshot.snap(itemView).record()
}
class TestRunner : AndroidJUnitRunner() {
override fun onCreate(arguments: Bundle?) {
ScreenshotRunner.onCreate(this, arguments);
super.onCreate(arguments)
}
override fun finish(resultCode: Int, results: Bundle?) {
ScreenshotRunner.onDestroy();
super.finish(resultCode, results)
apply plugin: 'com.facebook.testing.screenshot'
apply plugin: 'shot'
shot {
appId = 'com.revolut.revolut.test'
instrumentationTestTask = 'connectedQaInstrumentationDebugAndroidTest'
packageTestApkTask = 'packageQaInstrumentationDebugAndroidTest'
}
android {