Extracted createControlReference() so that it's overridable in tests

This commit is contained in:
dankl 2019-10-13 01:30:41 +02:00 committed by dankito
parent 08f991deba
commit 9e3d25e93e
2 changed files with 13 additions and 3 deletions

View File

@ -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, protected open fun signPayload(headerSegmentNumber: Int, bank: BankData, customer: CustomerData, date: Int, time: Int,
payloadSegments: List<Segment>): List<Segment> { payloadSegments: List<Segment>): List<Segment> {
val controlReference = Math.abs(ThreadLocalRandom.current().nextInt()).toString() val controlReference = createControlReference()
val signatureHeader = PinTanSignaturkopf( val signatureHeader = PinTanSignaturkopf(
headerSegmentNumber, headerSegmentNumber,
@ -168,6 +168,10 @@ open class MessageBuilder(protected val generator: ISegmentNumberGenerator = Seg
return listOf(signatureHeader, *payloadSegments.toTypedArray(), signatureEnding) 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, private fun encryptPayload(bank: BankData, customer: CustomerData, date: Int, time: Int,
payload: List<Segment>): List<Segment> { payload: List<Segment>): List<Segment> {

View File

@ -10,7 +10,7 @@ import java.util.*
class MessageBuilderTest : FinTsTestBase() { class MessageBuilderTest : FinTsTestBase() {
private val underTest = MessageBuilder(utils = object : FinTsUtils() { private val underTest = object : MessageBuilder(utils = object : FinTsUtils() {
override fun formatDate(date: Date): String { override fun formatDate(date: Date): String {
return Date.toString() return Date.toString()
} }
@ -18,7 +18,13 @@ class MessageBuilderTest : FinTsTestBase() {
override fun formatTime(time: Date): String { override fun formatTime(time: Date): String {
return Time.toString() return Time.toString()
} }
}) }) {
override fun createControlReference(): String {
return ControlReference
}
}
@Test @Test