From 787b91f7a89b37ef6de44663736d75b24e0611e4 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 22 Oct 2020 20:28:10 +0200 Subject: [PATCH] Fixed that credit card transactions list may is empty --- .../banking/fints/response/ResponseParser.kt | 2 +- .../fints/response/ResponseParserTest.kt | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt index 8b5a04ad..4f719290 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt @@ -685,7 +685,7 @@ open class ResponseParser( protected open fun parseCreditCardTransactions(segment: String, dataElementGroups: List): ReceivedCreditCardTransactionsAndBalance { val balance = parseBalance(dataElementGroups[3]) - val transactionsDataElementGroups = dataElementGroups.subList(6, dataElementGroups.size) + val transactionsDataElementGroups = if (dataElementGroups.size < 7) listOf() else dataElementGroups.subList(6, dataElementGroups.size) return ReceivedCreditCardTransactionsAndBalance( balance, diff --git a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt index 4273db27..7091a8d3 100644 --- a/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt +++ b/fints4k/src/commonTest/kotlin/net/dankito/banking/fints/response/ResponseParserTest.kt @@ -1119,6 +1119,31 @@ class ResponseParserTest : FinTsTestBase() { ?: run { fail("No segment of type ReceivedCreditCardTransactionsAndBalance found in ${result.receivedSegments}") } } + @Test + fun parseCreditCardAccountTransactionsWithEmptyTransactionsList() { + + // given + val creditCardNumber = "4263540122107989" + val balance = "189,5" + val otherPartyName = "Bundesanzeiger Verlag Koeln 000" + val amount = "6,5" + + // when + val result = underTest.parse("DIKKU:7:2:3+$creditCardNumber++C:$balance:EUR:20200923:021612'") + + // then + assertSuccessfullyParsedSegment(result, InstituteSegmentId.CreditCardTransactions, 7, 2, 3) + + result.getFirstSegmentById(InstituteSegmentId.CreditCardTransactions)?.let { segment -> + expect(segment.balance.amount.string).toBe(balance) + expect(segment.balance.date).toBe(Date(2020, 9, 23)) + expect(segment.balance.time).notToBeNull() + + expect(segment.transactions).isEmpty() + } + ?: run { fail("No segment of type ReceivedCreditCardTransactionsAndBalance found in ${result.receivedSegments}") } + } + @Test fun parseCreditCardAccountTransactionsParameters() {