Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert android-instrumentation tests to Kotlin #1240

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.squareup.leakcanary

import android.app.Application

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