Fix Leak canary test

This commit is contained in:
maskara 2017-11-07 02:27:10 +05:30
parent 0101dc4820
commit 6a6ba7d542
2 changed files with 10 additions and 4 deletions

View file

@ -130,11 +130,9 @@ public class CommonsApplication extends Application implements HasActivityInject
public void onCreate() {
super.onCreate();
if (LeakCanary.isInAnalyzerProcess(this)) {
refWatcher = RefWatcher.DISABLED;
if (setupLeakCanary() == RefWatcher.DISABLED) {
return;
}
refWatcher = LeakCanary.install(this);
Timber.plant(new Timber.DebugTree());
@ -159,6 +157,13 @@ public class CommonsApplication extends Application implements HasActivityInject
cacheData = new CacheController();
}
protected RefWatcher setupLeakCanary() {
if (LeakCanary.isInAnalyzerProcess(this)) {
return RefWatcher.DISABLED;
}
return LeakCanary.install(this);
}
public static RefWatcher getRefWatcher(Context context) {
CommonsApplication application = (CommonsApplication) context.getApplicationContext();
return application.refWatcher;

View file

@ -4,7 +4,8 @@ import com.squareup.leakcanary.RefWatcher;
// This class is automatically discovered by Robolectric
public class TestCommonsApplication extends CommonsApplication {
@Override protected RefWatcher setupLeakCanary() {
@Override
protected RefWatcher setupLeakCanary() {
// No leakcanary in unit tests.
return RefWatcher.DISABLED;
}