From 9e3d25e93ef9b566c966eb04f6f147eaa4949df8 Mon Sep 17 00:00:00 2001 From: dankl Date: Sun, 13 Oct 2019 01:30:41 +0200 Subject: [PATCH] Extracted createControlReference() so that it's overridable in tests --- .../net/dankito/fints/messages/MessageBuilder.kt | 6 +++++- .../net/dankito/fints/messages/MessageBuilderTest.kt | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt index 3f23635b..d34ddeb8 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/messages/MessageBuilder.kt @@ -148,7 +148,7 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg protected open fun signPayload(headerSegmentNumber: Int, bank: BankData, customer: CustomerData, date: Int, time: Int, payloadSegments: List): List { - val controlReference = Math.abs(ThreadLocalRandom.current().nextInt()).toString() + val controlReference = createControlReference() val signatureHeader = PinTanSignaturkopf( headerSegmentNumber, @@ -168,6 +168,10 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg return listOf(signatureHeader, *payloadSegments.toTypedArray(), signatureEnding) } + protected open fun createControlReference(): String { + return Math.abs(ThreadLocalRandom.current().nextInt()).toString() + } + private fun encryptPayload(bank: BankData, customer: CustomerData, date: Int, time: Int, payload: List): List { diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/MessageBuilderTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/MessageBuilderTest.kt index 7e1bd9a6..7caf8018 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/MessageBuilderTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/messages/MessageBuilderTest.kt @@ -10,7 +10,7 @@ import java.util.* class MessageBuilderTest : FinTsTestBase() { - private val underTest = MessageBuilder(utils = object : FinTsUtils() { + private val underTest = object : MessageBuilder(utils = object : FinTsUtils() { override fun formatDate(date: Date): String { return Date.toString() } @@ -18,7 +18,13 @@ class MessageBuilderTest : FinTsTestBase() { override fun formatTime(time: Date): String { return Time.toString() } - }) + }) { + + override fun createControlReference(): String { + return ControlReference + } + + } @Test