1 package leakcanary
2 
3 import leakcanary.TestUtils.assertLeak
4 import org.junit.After
5 import org.junit.Before
6 import org.junit.Test
7 import java.util.Date
8 
9 /**
10  * Tests that the [InstrumentationLeakDetector] can detect leaks
11  * in instrumentation tests
12  */
13 class InstrumentationLeakDetectorTest {
14 
setUpnull15   @Before fun setUp() {
16     AppWatcher.objectWatcher
17       .clearWatchedObjects()
18   }
19 
tearDownnull20   @After fun tearDown() {
21     AppWatcher.objectWatcher
22       .clearWatchedObjects()
23   }
24 
detectsLeaknull25   @Test fun detectsLeak() {
26     leaking = Date()
27     val objectWatcher = AppWatcher.objectWatcher
28     objectWatcher.expectWeaklyReachable(leaking, "This date should not live beyond the test")
29     assertLeak(Date::class.java)
30   }
31 
32   companion object {
33     private lateinit var leaking: Any
34   }
35 }
36