// Path: sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java
// public class Sherlock {
//   private static final String TAG = Sherlock.class.getSimpleName();
//   private static Sherlock instance;
//   private final SherlockDatabaseHelper database;
//   private final CrashReporter crashReporter;
//   private AppInfoProvider appInfoProvider;
// 
//   private Sherlock(Context context) {
//     database = new SherlockDatabaseHelper(context);
//     crashReporter = new CrashReporter(context);
//     appInfoProvider = new DefaultAppInfoProvider(context);
//   }
// 
//   public static void init(final Context context) {
//     Log.d(TAG, "Initializing Sherlock...");
//     instance = new Sherlock(context);
// 
//     final Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
// 
//     Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
//       @Override
//       public void uncaughtException(Thread thread, Throwable throwable) {
//         analyzeAndReportCrash(throwable);
//         handler.uncaughtException(thread, throwable);
//       }
//     });
//   }
// 
//   public static boolean isInitialized() {
//     return instance != null;
//   }
// 
//   public static Sherlock getInstance() {
//     if (!isInitialized()) {
//       throw new SherlockNotInitializedException();
//     }
//     Log.d(TAG, "Returning existing instance...");
//     return instance;
//   }
// 
//   public List<Crash> getAllCrashes() {
//     return getInstance().database.getCrashes();
//   }
// 
//   private static void analyzeAndReportCrash(Throwable throwable) {
//     Log.d(TAG, "Analyzing Crash...");
//     CrashAnalyzer crashAnalyzer = new CrashAnalyzer(throwable);
//     Crash crash = crashAnalyzer.getAnalysis();
//     int crashId = instance.database.insertCrash(CrashRecord.createFrom(crash));
//     crash.setId(crashId);
//     instance.crashReporter.report(new CrashViewModel(crash));
//     Log.d(TAG, "Crash analysis completed!");
//   }
// 
//   public static void setAppInfoProvider(AppInfoProvider appInfoProvider) {
//     getInstance().appInfoProvider = appInfoProvider;
//   }
// 
//   public AppInfoProvider getAppInfoProvider() {
//     return getInstance().appInfoProvider;
//   }
// }


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.support.test.InstrumentationRegistry;
import com.singhajit.sherlock.core.Sherlock;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
package com.singhajit.sherlock.core.database;




public class DatabaseResetRule implements TestRule {
  @Override
  public Statement apply(final Statement base, Description description) {
    return new Statement() {
      @Override
      public void evaluate() throws Throwable {
        resetDB();
        initializeSherlock();
        base.evaluate();
      }
    };
  }

  private void initializeSherlock() {
    Context targetContext = InstrumentationRegistry.getTargetContext();
// Path: sherlock/src/main/java/com/singhajit/sherlock/core/Sherlock.java
// public class Sherlock {
//   private static final String TAG = Sherlock.class.getSimpleName();
//   private static Sherlock instance;
//   private final SherlockDatabaseHelper database;
//   private final CrashReporter crashReporter;
//   private AppInfoProvider appInfoProvider;
// 
//   private Sherlock(Context context) {
//     database = new SherlockDatabaseHelper(context);
//     crashReporter = new CrashReporter(context);
//     appInfoProvider = new DefaultAppInfoProvider(context);
//   }
// 
//   public static void init(final Context context) {
//     Log.d(TAG, "Initializing Sherlock...");
//     instance = new Sherlock(context);
// 
//     final Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
// 
//     Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
//       @Override
//       public void uncaughtException(Thread thread, Throwable throwable) {
//         analyzeAndReportCrash(throwable);
//         handler.uncaughtException(thread, throwable);
//       }
//     });
//   }
// 
//   public static boolean isInitialized() {
//     return instance != null;
//   }
// 
//   public static Sherlock getInstance() {
//     if (!isInitialized()) {
//       throw new SherlockNotInitializedException();
//     }
//     Log.d(TAG, "Returning existing instance...");
//     return instance;
//   }
// 
//   public List<Crash> getAllCrashes() {
//     return getInstance().database.getCrashes();
//   }
// 
//   private static void analyzeAndReportCrash(Throwable throwable) {
//     Log.d(TAG, "Analyzing Crash...");
//     CrashAnalyzer crashAnalyzer = new CrashAnalyzer(throwable);
//     Crash crash = crashAnalyzer.getAnalysis();
//     int crashId = instance.database.insertCrash(CrashRecord.createFrom(crash));
//     crash.setId(crashId);
//     instance.crashReporter.report(new CrashViewModel(crash));
//     Log.d(TAG, "Crash analysis completed!");
//   }
// 
//   public static void setAppInfoProvider(AppInfoProvider appInfoProvider) {
//     getInstance().appInfoProvider = appInfoProvider;
//   }
// 
//   public AppInfoProvider getAppInfoProvider() {
//     return getInstance().appInfoProvider;
//   }
// }


// Path: sherlock/src/androidTest/java/com/singhajit/sherlock/core/database/DatabaseResetRule.java
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.support.test.InstrumentationRegistry;
import com.singhajit.sherlock.core.Sherlock;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

package com.singhajit.sherlock.core.database;




public class DatabaseResetRule implements TestRule {
  @Override
  public Statement apply(final Statement base, Description description) {
    return new Statement() {
      @Override
      public void evaluate() throws Throwable {
        resetDB();
        initializeSherlock();
        base.evaluate();
      }
    };
  }

  private void initializeSherlock() {
    Context targetContext = InstrumentationRegistry.getTargetContext();
    Sherlock.init(targetContext);