Skip to content

Commit

Permalink
Convert android-instrumentation tests to Kotlin
Browse files Browse the repository at this point in the history
See #1205
  • Loading branch information
colinmarsch committed Apr 2, 2019
1 parent 9d38b80 commit e6f67af
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 55 deletions.

This file was deleted.

@@ -0,0 +1,48 @@
package com.squareup.leakcanary

import org.junit.After
import org.junit.Before
import org.junit.Test
import java.util.Date

/**
* Tests that the [InstrumentationLeakDetector] can detect leaks
* in instrumentation tests
*/
class InstrumentationLeakDetectorTest {

@Before fun setUp() {
LeakCanary.installedRefWatcher()
.clearWatchedReferences()
}

@After fun tearDown() {
LeakCanary.installedRefWatcher()
.clearWatchedReferences()
}

@Test fun detectsLeak() {
leaking = Date()
val refWatcher = LeakCanary.installedRefWatcher()
refWatcher.watch(leaking)

val leakDetector = InstrumentationLeakDetector()
val results = leakDetector.detectLeaks()

if (results.detectedLeaks.size != 1) {
throw AssertionError("Expected exactly one leak, not ${results.detectedLeaks.size}")
}

val firstResult = results.detectedLeaks[0]

val leakingClassName = firstResult.analysisResult.className

if (leakingClassName != Date::class.java.name) {
throw AssertionError("Expected a leak of Date, not $leakingClassName")
}
}

companion object {
private var leaking: Any? = null
}
}

This file was deleted.

@@ -0,0 +1,11 @@
package com.squareup.leakcanary

import android.app.Application

class InstrumentationTestApplication : Application() {
override fun onCreate() {
super.onCreate()
InstrumentationLeakDetector.instrumentationRefWatcher(this)
.buildAndInstall()
}
}

0 comments on commit e6f67af

Please sign in to comment.