Skip to content

Instantly share code, notes, and snippets.

@alexshr
alexshr / gist:a1703a28c5742b5a1996deeab0bf2ad3
Last active Jun 2, 2017
Call it in Activity.onCreate to see facebook debug key hash
View gist:a1703a28c5742b5a1996deeab0bf2ad3
/**
* Call it in Activity.onCreate to see facebook debug key hash
*
* @param activity
*/
public static void logFbKeyHash(Activity activity) {
try {
PackageInfo info = activity.getPackageManager().getPackageInfo(
activity.getPackageName(),
PackageManager.GET_SIGNATURES);
@alexshr
alexshr / MockMyApplication.java
Last active Aug 28, 2017
Extended AndroidJUnitRunner for starting with different Application class (e.g. to replace dagger component)
View MockMyApplication.java
package com.skb.goodsapp;
import com.skb.goodsapp.di.AppComponent;
import com.skb.goodsapp.di.AppModule;
import com.skb.goodsapp.di.DaggerService;
/**
* to replace MyApplication (using MockTestRunner)
* for MockWebServer usage
*
@alexshr
alexshr / TestSchedulerRule.java
Created May 6, 2017
Test rule for rxjava test (override schedulers for testing, reset hook).
View TestSchedulerRule.java
package com.skb.goodsapp;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import io.reactivex.Scheduler;
import io.reactivex.android.plugins.RxAndroidPlugins;
import io.reactivex.internal.schedulers.ExecutorScheduler;
import io.reactivex.plugins.RxJavaPlugins;
@alexshr
alexshr / MockDispatcher.java
Created May 6, 2017
MockWebServer dispatcher supports requests plan, assert the request history, can take file for response from path/
View MockDispatcher.java
package com.skb.goodsapp;
import android.util.Log;
import org.junit.Assert;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@alexshr
alexshr / EspressoExecutor.java
Last active Mar 4, 2019
The utility repeats runnable or callable executing until it pass without errors or throws throwable after timeout. It works perfectly for Espresso tests.
View EspressoExecutor.java
/**
* Created by alexshr on 02.05.2017.
*/
package com.skb.goodsapp;
import android.os.SystemClock;
import android.util.Log;
import java.util.Date;