@@ -27,9 +27,10 @@ import org.junit.runner.RunWith
2727import org.lightningdevkit.ldknode.Event
2828import org.mockito.kotlin.any
2929import org.mockito.kotlin.anyOrNull
30- import org.mockito.kotlin.argumentCaptor
30+ import org.mockito.kotlin.doAnswer
3131import org.mockito.kotlin.mock
3232import org.mockito.kotlin.never
33+ import org.mockito.kotlin.stub
3334import org.mockito.kotlin.verify
3435import org.mockito.kotlin.whenever
3536import org.robolectric.Robolectric
@@ -83,24 +84,30 @@ class LightningNodeServiceTest : BaseUnitTest() {
8384 @BindValue
8485 val cacheStore = mock<CacheStore >()
8586
86- private val captor = argumentCaptor< NodeEventHandler >()
87+ private var capturedHandler : NodeEventHandler ? = null
8788 private val cacheData = MutableSharedFlow <AppCacheData >(replay = 1 )
8889 private val context = ApplicationProvider .getApplicationContext<Context >()
8990
9091 @Before
9192 fun setUp () = runBlocking {
9293 hiltRule.inject()
93- whenever(
94- lightningRepo.start(
95- any(),
96- anyOrNull(),
97- any(),
98- anyOrNull(),
99- anyOrNull(),
100- captor.capture(),
101- anyOrNull(),
102- )
103- ).thenReturn(Result .success(Unit ))
94+ lightningRepo.stub {
95+ onBlocking {
96+ start(
97+ any(),
98+ anyOrNull(),
99+ any(),
100+ anyOrNull(),
101+ anyOrNull(),
102+ anyOrNull(),
103+ anyOrNull(),
104+ )
105+ } doAnswer {
106+ @Suppress(" UNCHECKED_CAST" )
107+ capturedHandler = it.getArgument(5 ) as ? NodeEventHandler
108+ Result .success(Unit )
109+ }
110+ }
104111 whenever(lightningRepo.stop()).thenReturn(Result .success(Unit ))
105112
106113 // Set up CacheStore mock
@@ -139,7 +146,6 @@ class LightningNodeServiceTest : BaseUnitTest() {
139146 controller.create().startCommand(0 , 0 )
140147 testScheduler.advanceUntilIdle()
141148
142- val capturedHandler = captor.lastValue
143149 assertNotNull(" Event handler should be captured" , capturedHandler)
144150
145151 val event = Event .PaymentReceived (
@@ -186,7 +192,7 @@ class LightningNodeServiceTest : BaseUnitTest() {
186192 customRecords = emptyList()
187193 )
188194
189- captor.lastValue ?.invoke(event)
195+ capturedHandler ?.invoke(event)
190196 testScheduler.advanceUntilIdle()
191197
192198 val notificationManager = context.getSystemService(Context .NOTIFICATION_SERVICE ) as NotificationManager
@@ -214,7 +220,7 @@ class LightningNodeServiceTest : BaseUnitTest() {
214220 customRecords = emptyList()
215221 )
216222
217- captor.lastValue ?.invoke(event)
223+ capturedHandler ?.invoke(event)
218224 testScheduler.advanceUntilIdle()
219225
220226 val notificationManager = context.getSystemService(Context .NOTIFICATION_SERVICE ) as NotificationManager
0 commit comments