@@ -48,15 +48,12 @@ class AnrProfilingIntegrationTest {
4848
4949 @Test
5050 fun `onForeground starts monitoring thread` () {
51- // Arrange
5251 val integration = AnrProfilingIntegration ()
5352 integration.register(mockScopes, options)
5453
55- // Act
5654 integration.onForeground()
5755 Thread .sleep(100 ) // Allow thread to start
5856
59- // Assert
6057 val thread = integration.getProperty<Thread ?>(" thread" )
6158 assertNotNull(thread)
6259 assertTrue(thread.isAlive)
@@ -65,7 +62,6 @@ class AnrProfilingIntegrationTest {
6562
6663 @Test
6764 fun `onBackground stops monitoring thread` () {
68- // Arrange
6965 val integration = AnrProfilingIntegration ()
7066 integration.register(mockScopes, options)
7167 integration.onForeground()
@@ -74,17 +70,14 @@ class AnrProfilingIntegrationTest {
7470 val thread = integration.getProperty<Thread ?>(" thread" )
7571 assertNotNull(thread)
7672
77- // Act
7873 integration.onBackground()
7974 thread.join(2000 ) // Wait for thread to stop
8075
81- // Assert
8276 assertTrue(! thread.isAlive)
8377 }
8478
8579 @Test
8680 fun `close disables integration and interrupts thread` () {
87- // Arrange
8881 val integration = AnrProfilingIntegration ()
8982 integration.register(mockScopes, options)
9083 integration.onForeground()
@@ -93,19 +86,19 @@ class AnrProfilingIntegrationTest {
9386 val thread = integration.getProperty<Thread ?>(" thread" )
9487 assertNotNull(thread)
9588
96- // Act
89+ assertTrue(AppState .getInstance().lifecycleObserver.listeners.isNotEmpty())
90+
9791 integration.close()
9892 thread.join(2000 )
9993
100- // Assert
10194 assertTrue(! thread.isAlive)
10295 val enabled = integration.getProperty< java.util.concurrent.atomic.AtomicBoolean > (" enabled" )
10396 assertTrue(! enabled.get())
97+ assertTrue(AppState .getInstance().lifecycleObserver.listeners.isEmpty())
10498 }
10599
106100 @Test
107101 fun `lifecycle methods have no influence after close` () {
108- // Arrange
109102 val integration = AnrProfilingIntegration ()
110103 integration.register(mockScopes, options)
111104 integration.close()
@@ -118,11 +111,9 @@ class AnrProfilingIntegrationTest {
118111
119112 @Test
120113 fun `multiple foreground calls do not create multiple threads` () {
121- // Arrange
122114 val integration = AnrProfilingIntegration ()
123115 integration.register(mockScopes, options)
124116
125- // Act
126117 integration.onForeground()
127118 Thread .sleep(100 )
128119 val thread1 = integration.getProperty<Thread ?>(" thread" )
@@ -131,7 +122,6 @@ class AnrProfilingIntegrationTest {
131122 Thread .sleep(100 )
132123 val thread2 = integration.getProperty<Thread ?>(" thread" )
133124
134- // Assert
135125 assertNotNull(thread1)
136126 assertNotNull(thread2)
137127 assertEquals(thread1, thread2, " Should reuse the same thread" )
@@ -145,7 +135,6 @@ class AnrProfilingIntegrationTest {
145135 val integration = AnrProfilingIntegration ()
146136 integration.register(mockScopes, options)
147137
148- // Act
149138 integration.onForeground()
150139 Thread .sleep(100 )
151140 val thread1 = integration.getProperty<Thread ?>(" thread" )
@@ -156,7 +145,6 @@ class AnrProfilingIntegrationTest {
156145 Thread .sleep(100 )
157146 val thread2 = integration.getProperty<Thread ?>(" thread" )
158147
159- // Assert
160148 assertNotNull(thread1)
161149 assertNotNull(thread2)
162150 assertTrue(thread1 != thread2, " Should create a new thread after background" )
@@ -166,15 +154,13 @@ class AnrProfilingIntegrationTest {
166154
167155 @Test
168156 fun `properly walks through state transitions and collects stack traces` () {
169- // Arrange
170157 val mainThread = Thread .currentThread()
171158 SystemClock .setCurrentTimeMillis(1_00 )
172159
173160 val integration = AnrProfilingIntegration ()
174161 integration.register(mockScopes, options)
175162 integration.onForeground()
176163
177- // Act
178164 SystemClock .setCurrentTimeMillis(1_000 )
179165 integration.checkMainThread(mainThread)
180166 assertEquals(AnrProfilingIntegration .MainThreadState .IDLE , integration.state)
0 commit comments