Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert android-instrumentation tests to Kotlin
See #1205
- Loading branch information
1 parent
9d38b80
commit e6f67af
Showing
4 changed files
with
59 additions
and
55 deletions.
There are no files selected for viewing
44 changes: 0 additions & 44 deletions
44
...ntation/src/androidTest/java/com/squareup/leakcanary/InstrumentationLeakDetectorTest.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
...mentation/src/androidTest/java/com/squareup/leakcanary/InstrumentationLeakDetectorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
...entation/src/androidTest/java/com/squareup/leakcanary/InstrumentationTestApplication.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
...umentation/src/androidTest/java/com/squareup/leakcanary/InstrumentationTestApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |