Fixed that balance of pre booked transactions may be empty

This commit is contained in:
dankito 2020-06-09 00:25:39 +02:00
parent 16284e5782
commit 75e77eb84a
2 changed files with 34 additions and 3 deletions

View File

@ -599,7 +599,7 @@ open class ResponseParser(
// dataElementGroups[1] is account details // dataElementGroups[1] is account details
val balance = parseBalance(dataElementGroups[4]) val balance = parseBalance(dataElementGroups[4])
val balanceOfPreBookedTransactions = if (dataElementGroups.size > 5) parseBalanceToNullIfZero(dataElementGroups[5]) else null val balanceOfPreBookedTransactions = if (dataElementGroups.size > 5) parseBalanceToNullIfZeroOrNotSet(dataElementGroups[5]) else null
return BalanceSegment( return BalanceSegment(
balance.amount, balance.amount,
@ -611,7 +611,11 @@ open class ResponseParser(
) )
} }
protected open fun parseBalanceToNullIfZero(dataElementGroup: String): Balance? { protected open fun parseBalanceToNullIfZeroOrNotSet(dataElementGroup: String): Balance? {
if (dataElementGroup.isEmpty()) {
return null
}
val parsedBalance = parseBalance(dataElementGroup) val parsedBalance = parseBalance(dataElementGroup)
if (BigDecimal.ZERO.equals(parsedBalance.amount)) { if (BigDecimal.ZERO.equals(parsedBalance.amount)) {

View File

@ -989,7 +989,7 @@ class ResponseParserTest : FinTsTestBase() {
} }
@Test @Test
fun parseBalance_BalanceOfPreBookedTransactionsIsOmitted() { fun parseBalance_BalanceOfPreBookedTransactionsIsZero() {
// given // given
val balance = BigDecimal.ZERO val balance = BigDecimal.ZERO
@ -1015,6 +1015,33 @@ class ResponseParserTest : FinTsTestBase() {
?: run { fail("No segment of type BalanceSegment found in ${result.receivedSegments}") } ?: run { fail("No segment of type BalanceSegment found in ${result.receivedSegments}") }
} }
@Test
fun parseBalance_BalanceOfPreBookedTransactionsIsEmpty() {
// given
val balance = BigDecimal.ZERO
val date = com.soywiz.klock.Date(2020, 6, 11)
val bankCode = "12345678"
val accountId = "0987654321"
val accountProductName = "Girokonto"
// when
// "HISAL:7:5:3+0987654321:Girokonto:280:12345678+Girokonto+EUR++0,:EUR'"
val result = underTest.parse("HISAL:7:5:3+$accountId:$accountProductName:280:$bankCode+$accountProductName+EUR+C:0,:EUR:${convertDate(date)}:204204++0,:EUR'")
// then
assertSuccessfullyParsedSegment(result, InstituteSegmentId.Balance, 7, 5, 3)
result.getFirstSegmentById<BalanceSegment>(InstituteSegmentId.Balance)?.let { segment ->
expect(segment.balance).toBe(balance)
expect(segment.currency).toBe("EUR")
expect(segment.date).toBe(date)
expect(segment.accountProductName).toBe(accountProductName)
expect(segment.balanceOfPreBookedTransactions).toBe(null)
}
?: run { fail("No segment of type BalanceSegment found in ${result.receivedSegments}") }
}
private fun assertSuccessfullyParsedSegment(result: Response, segmentId: ISegmentId, segmentNumber: Int, private fun assertSuccessfullyParsedSegment(result: Response, segmentId: ISegmentId, segmentNumber: Int,
segmentVersion: Int, referenceSegmentNumber: Int? = null) { segmentVersion: Int, referenceSegmentNumber: Int? = null) {