Fixed generating the correct amount of lines according to specification (that is no empty lines after 10th line and no line separator after 12th line)
This commit is contained in:
parent
0d32afda75
commit
3c129a9e46
|
@ -65,14 +65,23 @@ open class EpcQrCodeGenerator {
|
||||||
epcQrCodeBuilder.appendLine(epcQrCode.iban)
|
epcQrCodeBuilder.appendLine(epcQrCode.iban)
|
||||||
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.amount?.let { (epcQrCode.currencyCode ?: EpcQrCodeValues.CurrencyCodeDefaultValue) + it })) // TODO: ensure that amount is converted to the correct format
|
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.amount?.let { (epcQrCode.currencyCode ?: EpcQrCodeValues.CurrencyCodeDefaultValue) + it })) // TODO: ensure that amount is converted to the correct format
|
||||||
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.purposeCode))
|
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.purposeCode))
|
||||||
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.remittanceReference))
|
|
||||||
|
|
||||||
if (epcQrCode.remittanceText != null || epcQrCode.originatorInformation != null) {
|
if (epcQrCode.remittanceText != null || epcQrCode.originatorInformation != null) {
|
||||||
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.remittanceText))
|
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.remittanceReference))
|
||||||
|
} else {
|
||||||
|
epcQrCodeBuilder.append(mapNullable(epcQrCode.remittanceReference))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (epcQrCode.remittanceText != null || epcQrCode.originatorInformation != null) {
|
||||||
|
if (epcQrCode.originatorInformation != null) {
|
||||||
|
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.remittanceText))
|
||||||
|
} else {
|
||||||
|
epcQrCodeBuilder.append(mapNullable(epcQrCode.remittanceText))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (epcQrCode.originatorInformation != null) {
|
if (epcQrCode.originatorInformation != null) {
|
||||||
epcQrCodeBuilder.appendLine(epcQrCode.originatorInformation)
|
epcQrCodeBuilder.append(epcQrCode.originatorInformation)
|
||||||
}
|
}
|
||||||
|
|
||||||
return epcQrCodeBuilder.toString()
|
return epcQrCodeBuilder.toString()
|
||||||
|
|
|
@ -11,10 +11,12 @@ class EpcQrCodeGeneratorTest {
|
||||||
private const val ReceiverIban = "DE01234567890123456789"
|
private const val ReceiverIban = "DE01234567890123456789"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private val underTest = EpcQrCodeGenerator()
|
private val underTest = EpcQrCodeGenerator()
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun basicDataOnly() {
|
fun mandatoryDataOnly() {
|
||||||
val config = basicDataConfig()
|
val config = basicDataConfig()
|
||||||
|
|
||||||
val result = underTest.generateAsString(config)
|
val result = underTest.generateAsString(config)
|
||||||
|
@ -25,36 +27,88 @@ class EpcQrCodeGeneratorTest {
|
||||||
1
|
1
|
||||||
SCT
|
SCT
|
||||||
|
|
||||||
Liebe
|
$ReceiverName
|
||||||
DE01234567890123456789
|
$ReceiverIban
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
""".trimIndent())
|
||||||
|
|
||||||
|
assertEquals(10, result.lines().size) // if no reference text or note to user is set, then QR code may only contain the minimum of 10 lines and no empty lines afterwards
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun includingReferenceText() {
|
||||||
|
val referenceText = "Her mit der Knete"
|
||||||
|
val config = basicDataConfig(referenceText = referenceText)
|
||||||
|
|
||||||
|
val result = underTest.generateAsString(config)
|
||||||
|
|
||||||
|
assertEquals(actual = result, expected = """
|
||||||
|
BCD
|
||||||
|
002
|
||||||
|
1
|
||||||
|
SCT
|
||||||
|
|
||||||
|
$ReceiverName
|
||||||
|
$ReceiverIban
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$referenceText
|
||||||
|
""".trimIndent())
|
||||||
|
|
||||||
|
assertEquals(11, result.lines().size) // no note to user -> no 12th line may be contained in generated QR code
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun includingNoteToUser() {
|
||||||
|
val noteToUser = "Mach uns reich, Baby"
|
||||||
|
val config = basicDataConfig(noteToUser = noteToUser)
|
||||||
|
|
||||||
|
val result = underTest.generateAsString(config)
|
||||||
|
|
||||||
|
assertEquals(actual = result, expected = """
|
||||||
|
BCD
|
||||||
|
002
|
||||||
|
1
|
||||||
|
SCT
|
||||||
|
|
||||||
|
$ReceiverName
|
||||||
|
$ReceiverIban
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$noteToUser
|
||||||
""".trimIndent())
|
""".trimIndent())
|
||||||
|
|
||||||
|
assertEquals(12, result.lines().size) // note to user set -> contains the maximum of 12 lines but no line separator at end of 12th line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun png() {
|
fun png() {
|
||||||
val result = underTest.generateEpcQrCode(basicDataConfig(ImageFormat.PNG))
|
val result = underTest.generateEpcQrCode(basicDataConfig(imageFormat = ImageFormat.PNG))
|
||||||
|
|
||||||
// don't know why, in JavaScript it's 1000643, on all other platforms 10446 bytes
|
// don't know why, in JavaScript it's 1000643, on all other platforms 10459 bytes
|
||||||
assertTrue(listOf(10446, 1000643).contains(result.bytes.size))
|
assertTrue(listOf(10459, 1000643).contains(result.bytes.size))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun bmp() {
|
fun bmp() {
|
||||||
val result = underTest.generateEpcQrCode(basicDataConfig(ImageFormat.BMP))
|
val result = underTest.generateEpcQrCode(basicDataConfig(imageFormat = ImageFormat.BMP))
|
||||||
|
|
||||||
assertEquals(1000054, result.bytes.size)
|
assertEquals(1000054, result.bytes.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun tga() {
|
fun tga() {
|
||||||
val result = underTest.generateEpcQrCode(basicDataConfig(ImageFormat.TGA))
|
val result = underTest.generateEpcQrCode(basicDataConfig(imageFormat = ImageFormat.TGA))
|
||||||
|
|
||||||
assertEquals(1000018, result.bytes.size)
|
assertEquals(1000018, result.bytes.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun basicDataConfig(imageFormat: ImageFormat = ImageFormat.PNG) = EpcQrCodeConfig(ReceiverName, ReceiverIban, imageFormat = imageFormat)
|
private fun basicDataConfig(referenceText: String? = null, noteToUser: String? = null, imageFormat: ImageFormat = ImageFormat.PNG) =
|
||||||
|
EpcQrCodeConfig(ReceiverName, ReceiverIban, reference = referenceText, noteToUser = noteToUser, imageFormat = imageFormat)
|
||||||
}
|
}
|
Loading…
Reference in New Issue