-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISSUE-604: LeakCanary added to dependencies, also created DetectMemor…
…yLeaksRule
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
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
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
42 changes: 42 additions & 0 deletions
42
...c/main/kotlin/com/kaspersky/kaspresso/testcases/api/testcaserule/DetectMemoryLeaksRule.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,42 @@ | ||
package com.kaspersky.kaspresso.testcases.api.testcaserule | ||
|
||
import com.kaspersky.kaspresso.testcases.core.sections.AfterTestSection | ||
import com.kaspersky.kaspresso.testcases.core.sections.InitSection | ||
import com.kaspersky.kaspresso.testcases.core.testcontext.BaseTestContext | ||
import com.kaspersky.kaspresso.testcases.core.testcontext.TestContext | ||
import leakcanary.LeakAssertions | ||
import org.junit.rules.TestRule | ||
import org.junit.runner.Description | ||
import org.junit.runners.model.Statement | ||
|
||
class DetectMemoryLeaksRule( | ||
testClassName: String | ||
) : TestRule { | ||
|
||
val kaspressoRule = TestCaseRule(testClassName) | ||
|
||
override fun apply(base: Statement, description: Description): Statement { | ||
return kaspressoRule.apply(base, description) | ||
} | ||
|
||
fun before(actions: BaseTestContext.() -> Unit) = After(kaspressoRule.before { | ||
actions(this) | ||
}) | ||
|
||
class After( | ||
private val after: AfterTestSection<Unit, Unit> | ||
) { | ||
fun after(actions: BaseTestContext.() -> Unit) = Init(after.after { | ||
LeakAssertions.assertNoLeaks() | ||
actions(this) | ||
}) | ||
} | ||
|
||
class Init( | ||
private val init: InitSection<Unit, Unit> | ||
) { | ||
fun run(steps: TestContext<Unit>.() -> Unit) = init.run { | ||
steps(this) | ||
} | ||
} | ||
} |