Skip to content

Commit 16fd390

Browse files
committed
chore: cleanup LightningNodeServiceTest
1 parent ed1f232 commit 16fd390

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

app/src/test/java/to/bitkit/androidServices/LightningNodeServiceTest.kt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ class LightningNodeServiceTest : BaseUnitTest() {
7070

7171
@BindValue
7272
@JvmField
73-
val lightningRepo: LightningRepo = mock()
73+
val lightningRepo = mock<LightningRepo>()
7474

7575
@BindValue
7676
@JvmField
77-
val walletRepo: WalletRepo = mock()
77+
val walletRepo = mock<WalletRepo>()
7878

7979
@BindValue
8080
@JvmField
81-
val notifyPaymentReceivedHandler: NotifyPaymentReceivedHandler = mock()
81+
val notifyPaymentReceivedHandler = mock<NotifyPaymentReceivedHandler>()
8282

8383
@BindValue
8484
@JvmField
85-
val cacheStore: CacheStore = mock()
85+
val cacheStore = mock<CacheStore>()
8686

8787
@BindValue
8888
@UiDispatcher
@@ -99,16 +99,15 @@ class LightningNodeServiceTest : BaseUnitTest() {
9999
@JvmField
100100
val ioDispatcher: CoroutineDispatcher = testDispatcher
101101

102-
private val eventHandlerCaptor: KArgumentCaptor<NodeEventHandler?> = argumentCaptor()
102+
private val handlerCaptor: KArgumentCaptor<NodeEventHandler?> = argumentCaptor()
103103
private val cacheDataFlow = MutableSharedFlow<AppCacheData>(replay = 1)
104104
private val context = ApplicationProvider.getApplicationContext<Context>()
105105

106106
@Before
107107
fun setUp() = runBlocking {
108108
hiltRule.inject()
109-
whenever(
110-
lightningRepo.start(any(), anyOrNull(), any(), anyOrNull(), anyOrNull(), eventHandlerCaptor.capture())
111-
).thenReturn(Result.success(Unit))
109+
whenever(lightningRepo.start(any(), anyOrNull(), any(), anyOrNull(), anyOrNull(), handlerCaptor.capture()))
110+
.thenReturn(Result.success(Unit))
112111
whenever(lightningRepo.stop()).thenReturn(Result.success(Unit))
113112

114113
// Set up CacheStore mock
@@ -125,9 +124,8 @@ class LightningNodeServiceTest : BaseUnitTest() {
125124
title = context.getString(R.string.notification_received_title),
126125
body = "Received ₿ 100 ($0.10)",
127126
)
128-
whenever(notifyPaymentReceivedHandler.invoke(any())).thenReturn(
129-
Result.success(NotifyPaymentReceived.Result.ShowNotification(sheet, notification))
130-
)
127+
whenever(notifyPaymentReceivedHandler.invoke(any()))
128+
.thenReturn(Result.success(NotifyPaymentReceived.Result.ShowNotification(sheet, notification)))
131129

132130
// Grant permissions for notifications
133131
val app = context as Application
@@ -148,7 +146,7 @@ class LightningNodeServiceTest : BaseUnitTest() {
148146
controller.create().startCommand(0, 0)
149147
testScheduler.advanceUntilIdle()
150148

151-
val capturedHandler = eventHandlerCaptor.lastValue
149+
val capturedHandler = handlerCaptor.lastValue
152150
assertNotNull("Event handler should be captured", capturedHandler)
153151

154152
val event = Event.PaymentReceived(
@@ -195,7 +193,7 @@ class LightningNodeServiceTest : BaseUnitTest() {
195193
customRecords = emptyList()
196194
)
197195

198-
eventHandlerCaptor.lastValue?.invoke(event)
196+
handlerCaptor.lastValue?.invoke(event)
199197
testScheduler.advanceUntilIdle()
200198

201199
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
@@ -223,7 +221,7 @@ class LightningNodeServiceTest : BaseUnitTest() {
223221
customRecords = emptyList()
224222
)
225223

226-
eventHandlerCaptor.lastValue?.invoke(event)
224+
handlerCaptor.lastValue?.invoke(event)
227225
testScheduler.advanceUntilIdle()
228226

229227
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
@@ -235,6 +233,6 @@ class LightningNodeServiceTest : BaseUnitTest() {
235233
assertNotNull("Payment notification should be present", paymentNotification)
236234

237235
val body = paymentNotification?.extras?.getString(Notification.EXTRA_TEXT)
238-
assertEquals("Received ₿ 100 (\$0.10)", body)
236+
assertEquals($$"Received ₿ 100 ($0.10)", body)
239237
}
240238
}

0 commit comments

Comments
 (0)