1 package leakcanary 2 3 import android.database.sqlite.SQLiteDatabase 4 import androidx.test.platform.app.InstrumentationRegistry 5 import leakcanary.internal.activity.db.LeaksDbHelper 6 import leakcanary.internal.activity.db.ScopedLeaksDb 7 import org.junit.rules.TestRule 8 import org.junit.runner.Description 9 import org.junit.runners.model.Statement 10 <lambda>null11class DatabaseRule(private val updateDb: (SQLiteDatabase) -> Unit = {}) : TestRule { applynull12 override fun apply( 13 base: Statement, 14 description: Description 15 ): Statement { 16 return object : Statement() { 17 override fun evaluate() { 18 val instrumentation = InstrumentationRegistry.getInstrumentation() 19 val context = instrumentation.targetContext 20 context.deleteDatabase(LeaksDbHelper.DATABASE_NAME) 21 ScopedLeaksDb.writableDatabase(context, updateDb) 22 base.evaluate() 23 context.deleteDatabase(LeaksDbHelper.DATABASE_NAME) 24 } 25 } 26 } 27 } 28