Skip to content

Commit 5a1199d

Browse files
committed
transfer manager test correction
1 parent 3375349 commit 5a1199d

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ transferManager.addListener { event ->
354354

355355
// use scanner library of your choice to scan the QR for device engagement
356356
// when qr content is available, call startQRDeviceEngagement()
357+
// if qrText is malformed an IllegalArgumentException is propagated to TransferEvent.Error callback
357358
val qrText: String =
358359
"mdoc:owBjMS4wAYIB2BhYS6QBAiABIVggN ... 86vSyDAgGjAPUB9ApQmCMM53MkSc202zKjnzq9LA"
359360
transferManager.startQRDeviceEngagement(qrText)

verifier-core/src/main/java/eu/europa/ec/eudi/verifier/core/transfer/TransferManagerImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class TransferManagerImpl(
137137
/**
138138
* Starts device engagement using a QR code.
139139
* @param qrCode The QR code string.
140-
* @throws IllegalArgumentException if the QR code is invalid.
140+
* If the QR code is invalid, the error will be reported via the [TransferEvent.Error] callback.
141141
*/
142142
override fun startQRDeviceEngagement(qrCode: String) {
143143
logger?.d(TAG, "QR Engagement Request: $qrCode")

verifier-core/src/test/java/eu/europa/ec/eudi/verifier/core/transfer/TransferManagerImplTest.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,19 @@ class TransferManagerImplTest {
140140
}
141141

142142
@Test
143-
fun `startQRDeviceEngagement with garbage QR code throws`() {
143+
fun `startQRDeviceEngagement with garbage QR code triggers error event`() {
144+
transferManager.addListener(listener)
144145
val garbageQr = "hYS6QBAiABIVgg0Gzvq_N_tpQNv"
145-
every { verificationHelper.setDeviceEngagementFromQrCode(garbageQr) } throws IllegalArgumentException("Invalid QR")
146146

147-
assertFailsWith<IllegalArgumentException> {
148-
transferManager.startQRDeviceEngagement(garbageQr)
147+
val thrown = runCatching { transferManager.startQRDeviceEngagement(garbageQr) }.exceptionOrNull()
148+
assertNull(thrown, "startQRDeviceEngagement should not throw for invalid QR; error is async")
149+
150+
// Simulate what the underlying helper would do
151+
val ex = IllegalArgumentException("Invalid QR")
152+
capturedVerificationListener.onError(ex)
153+
154+
verify {
155+
listener.onEvent(match { it is TransferEvent.Error && it.error == ex })
149156
}
150157
}
151158

0 commit comments

Comments
 (0)