File tree Expand file tree Collapse file tree
main/java/eu/europa/ec/eudi/verifier/core/transfer
test/java/eu/europa/ec/eudi/verifier/core/transfer Expand file tree Collapse file tree Original file line number Diff line number Diff 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
357358val qrText: String =
358359 " mdoc:owBjMS4wAYIB2BhYS6QBAiABIVggN ... 86vSyDAgGjAPUB9ApQmCMM53MkSc202zKjnzq9LA"
359360transferManager.startQRDeviceEngagement(qrText)
Original file line number Diff line number Diff 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 " )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments