Replaced atrium asserts with Kotlin test asserts

This commit is contained in:
dankito 2022-02-13 00:17:45 +01:00
parent 55881b5e79
commit 56f951314a
28 changed files with 588 additions and 566 deletions

View File

@ -11,11 +11,8 @@ ext {
/* Test */
junitVersion = '4.12'
junit5Version = '5.5.2'
atriumVersion = "0.15.0"
assertJVersion = '3.12.2'
mockitoVersion = '2.22.0'

View File

@ -56,8 +56,6 @@ kotlin {
commonTest {
dependencies {
implementation kotlin("test")
implementation "ch.tutteli.atrium:atrium-fluent-en_GB-common:$atriumVersion"
}
}
@ -76,8 +74,6 @@ kotlin {
implementation "org.assertj:assertj-core:$assertJVersion"
implementation "org.mockito:mockito-core:$mockitoVersion"
implementation "ch.tutteli.atrium:atrium-fluent-en_GB:$atriumVersion"
// implementation project(":BankingUiCommon")
// implementation project(":BankFinder")

View File

@ -0,0 +1,73 @@
package net.dankito.banking.fints.extensions
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlin.test.fail
fun assertEquals(expected: Any?, actual: Any?) {
assertEquals(expected, actual, "'$actual' should equal expected '$expected'")
}
fun assertFalse(actual: Boolean) {
kotlin.test.assertFalse(actual, "Value should be false but isn't")
}
fun assertTrue(actual: Boolean) {
assertTrue(actual, "Value should be true but isn't")
}
@OptIn(ExperimentalContracts::class)
fun assertNotNull(actual: Any?) {
contract { returns() implies (actual != null) }
assertNotNull(actual, "Value should not be null but is")
}
fun assertNull(actual: Any?) {
kotlin.test.assertNull(actual, "'$actual' is expected to be null")
}
fun assertEmpty(string: String) {
assertTrue(string.isEmpty())
}
fun assertContains(string: String, vararg args: String) {
args.forEach { arg ->
kotlin.test.assertContains(string, arg)
}
}
fun assertSize(size: Int, collection: Collection<*>) {
assertEquals(size, collection.size, "Collection should have size $size, but has ${collection.size} elements")
}
fun assertEmpty(collection: Collection<*>) {
assertTrue(collection.isEmpty())
}
fun <T : Any?> assertContainsExactly(collection: Collection<T>, vararg items: T) {
assertEquals(collection.size, items.size, "Size of collection is ${collection.size}, but that of expected arguments is ${items.size}")
assertContains(collection, *items)
}
fun <T : Any?> assertContains(collection: Collection<T>, vararg items: T) {
items.forEach { item ->
kotlin.test.assertContains(collection, item)
}
}
inline fun <reified T : Throwable> assertThrows(action: () -> Unit) {
try {
action()
fail("action() didn't throw any exception. Expected was ${T::class.qualifiedName}")
} catch (throwable: Throwable) {
println("Throwable is of type ${throwable::class.simpleName}: $throwable")
assertTrue(throwable is T)
}
}

View File

@ -1,9 +0,0 @@
package net.dankito.banking.fints.extensions
import ch.tutteli.atrium.creating.Expect
import ch.tutteli.atrium.domain.builders.ExpectImpl
fun <T : Boolean> Expect<T>.isTrue(): Expect<T> = addAssertion(ExpectImpl.any.toBe(this, true))
fun <T : Boolean> Expect<T>.isFalse(): Expect<T> = addAssertion(ExpectImpl.any.toBe(this, false))

View File

@ -1,8 +1,5 @@
package net.dankito.banking.fints.messages
import ch.tutteli.atrium.api.fluent.en_GB.notToBeNull
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import ch.tutteli.atrium.api.verbs.expect
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.Month
@ -15,9 +12,7 @@ import net.dankito.banking.fints.response.segments.JobParameters
import net.dankito.banking.fints.response.segments.PinInfo
import net.dankito.banking.fints.response.segments.RetrieveAccountTransactionsParameters
import net.dankito.banking.fints.util.FinTsUtils
import kotlin.test.AfterTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.*
class MessageBuilderTest : FinTsTestBase() {
@ -55,7 +50,7 @@ class MessageBuilderTest : FinTsTestBase() {
val result = underTest.createAnonymousDialogInitMessage(context).createdMessage
// then
expect(result).toBe(
assertEquals(result,
"HNHBK:1:3+000000000125+300+0+1'" +
"HKIDN:2:2+280:12345678+${CustomerId}+0+0'" +
"HKVVB:3:3+0+0+${Language.code}+$ProductName+$ProductVersion'" +
@ -74,7 +69,7 @@ class MessageBuilderTest : FinTsTestBase() {
val result = underTest.createAnonymousDialogEndMessage(context).createdMessage ?: ""
// then
expect(normalizeBinaryData(result)).toBe(normalizeBinaryData(
assertEquals(normalizeBinaryData(result), normalizeBinaryData(
"HNHBK:1:3+000000000067+300+$dialogId+1'" +
"HKEND:2:1+$dialogId'" +
"HNHBS:3:1+1'"
@ -92,7 +87,7 @@ class MessageBuilderTest : FinTsTestBase() {
val result = underTest.createSynchronizeCustomerSystemIdMessage(context).createdMessage ?: ""
// then
expect(normalizeBinaryData(result)).toBe(normalizeBinaryData(
assertEquals(normalizeBinaryData(result), normalizeBinaryData(
"HNHBK:1:3+000000000397+300+0+1'" +
"HNVSK:998:3+PIN:2+998+1+1::0+1:$Date:$Time+2:2:13:@8@ :5:1+280:$BankCode:$CustomerId:V:0:0+0'" +
"HNVSD:999:1+@234@" + "HNSHK:2:4+PIN:2+${SecurityFunction.code}+$ControlReference+1+1+1::0+1+1:$Date:$Time+1:999:1+6:10:16+280:$BankCode:$CustomerId:S:0:0'" +
@ -116,7 +111,7 @@ class MessageBuilderTest : FinTsTestBase() {
val result = underTest.createDialogEndMessage(context).createdMessage ?: ""
// then
expect(normalizeBinaryData(result)).toBe(normalizeBinaryData(
assertEquals(normalizeBinaryData(result), normalizeBinaryData(
"HNHBK:1:3+000000000309+300+$dialogId+1'" +
"HNVSK:998:3+PIN:2+998+1+1::0+1:$Date:$Time+2:2:13:@8@ :5:1+280:$BankCode:$CustomerId:V:0:0+0'" +
"HNVSD:999:1+@140@" + "HNSHK:2:4+PIN:2+${SecurityFunction.code}+$ControlReference+1+1+1::0+1+1:$Date:$Time+1:999:1+6:10:16+280:$BankCode:$CustomerId:S:0:0'" +
@ -137,7 +132,7 @@ class MessageBuilderTest : FinTsTestBase() {
val result = underTest.createGetTransactionsMessage(context, GetAccountTransactionsParameter(Bank, Account))
// then
expect(result.isJobAllowed).toBe(false)
assertFalse(result.isJobAllowed)
}
@Test
@ -156,8 +151,8 @@ class MessageBuilderTest : FinTsTestBase() {
val result = underTest.createGetTransactionsMessage(context, GetAccountTransactionsParameter(Bank, account))
// then
expect(result.isJobAllowed).toBe(true)
expect(result.isJobVersionSupported).toBe(false)
assertTrue(result.isJobAllowed)
assertFalse(result.isJobVersionSupported)
}
@Test
@ -180,9 +175,9 @@ class MessageBuilderTest : FinTsTestBase() {
val result = underTest.createGetTransactionsMessage(context, GetAccountTransactionsParameter(Bank, account, false, fromDate, toDate, maxCountEntries))
// then
expect(result.createdMessage).notToBeNull()
assertNotNull(result.createdMessage)
expect(normalizeBinaryData(result.createdMessage!!)).toBe(normalizeBinaryData(
assertEquals(normalizeBinaryData(result.createdMessage!!), normalizeBinaryData(
"HNHBK:1:3+000000000361+300+0+1'" +
"HNVSK:998:3+PIN:2+998+1+1::0+1:$Date:$Time+2:2:13:@8@ :5:1+280:$BankCode:$CustomerId:V:0:0+0'" +
"HNVSD:999:1+@198@" + "HNSHK:2:4+PIN:2+${SecurityFunction.code}+$ControlReference+1+1+1::0+1+1:$Date:$Time+1:999:1+6:10:16+280:$BankCode:$CustomerId:S:0:0'" +
@ -216,9 +211,9 @@ class MessageBuilderTest : FinTsTestBase() {
GetAccountTransactionsParameter(Bank, account, false, fromDate, toDate, maxCountEntries, false))
// then
expect(result.createdMessage).notToBeNull()
assertNotNull(result.createdMessage)
expect(normalizeBinaryData(result.createdMessage!!)).toBe(normalizeBinaryData(
assertEquals(normalizeBinaryData(result.createdMessage!!), normalizeBinaryData(
"HNHBK:1:3+000000000340+300+0+1'" +
"HNVSK:998:3+PIN:2+998+1+1::0+1:$Date:$Time+2:2:13:@8@ :5:1+280:$BankCode:$CustomerId:V:0:0+0'" +
"HNVSD:999:1+@225@" + "HNSHK:2:4+PIN:2+${SecurityFunction.code}+$ControlReference+1+1+1::0+1+1:$Date:$Time+1:999:1+6:10:16+280:$BankCode:$CustomerId:S:0:0'" +

View File

@ -1,11 +1,10 @@
package net.dankito.banking.fints.messages.datenelemente.basisformate
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import ch.tutteli.atrium.api.fluent.en_GB.toThrow
import ch.tutteli.atrium.api.verbs.expect
import net.dankito.banking.fints.extensions.assertThrows
import net.dankito.banking.fints.messages.Existenzstatus
import net.dankito.banking.fints.messages.datenelementgruppen.implementierte.signatur.SicherheitsidentifikationDetails
import kotlin.test.Test
import kotlin.test.assertEquals
class TextDatenelementTest {
@ -30,9 +29,9 @@ class TextDatenelementTest {
val underTest = createTextDatenelement("α")
// when
expect {
assertThrows<IllegalArgumentException> {
underTest.validate()
}.toThrow<IllegalArgumentException>()
}
}
@Test
@ -42,9 +41,9 @@ class TextDatenelementTest {
val underTest = createTextDatenelement("Я")
// when
expect {
assertThrows<IllegalArgumentException> {
underTest.validate()
}.toThrow<IllegalArgumentException>()
}
}
@Test
@ -54,9 +53,9 @@ class TextDatenelementTest {
val underTest = createTextDatenelement("") // is only allowed by ISO-8859-15, not by ISO-8859-1
// when
expect {
assertThrows<IllegalArgumentException> {
underTest.validate()
}.toThrow<IllegalArgumentException>()
}
}
@ -75,7 +74,7 @@ class TextDatenelementTest {
// then
expect(result).toBe(expected)
assertEquals(expected, result)
}
@Test
@ -93,7 +92,7 @@ class TextDatenelementTest {
// then
expect(result).toBe(expected)
assertEquals(expected, result)
}
@Test
@ -111,7 +110,7 @@ class TextDatenelementTest {
// then
expect(result).toBe(expected)
assertEquals(expected, result)
}
@Test
@ -130,7 +129,7 @@ class TextDatenelementTest {
// then
expect(result).toBe(expected)
assertEquals(expected, result)
}

View File

@ -1,10 +1,9 @@
package net.dankito.banking.fints.messages.datenelemente.basisformate
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import ch.tutteli.atrium.api.fluent.en_GB.toThrow
import ch.tutteli.atrium.api.verbs.expect
import net.dankito.banking.fints.extensions.assertThrows
import net.dankito.banking.fints.messages.Existenzstatus
import kotlin.test.Test
import kotlin.test.assertEquals
class ZiffernDatenelementTest {
@ -19,7 +18,7 @@ class ZiffernDatenelementTest {
val result = underTest.format()
// then
expect(result).toBe("000001")
assertEquals("000001", result)
}
@ -56,9 +55,9 @@ class ZiffernDatenelementTest {
val underTest = createZiffernDatenelement(-1, 3)
// when
expect {
assertThrows<IllegalArgumentException> {
underTest.validate()
}.toThrow<IllegalArgumentException>()
}
}
@Test
@ -68,9 +67,9 @@ class ZiffernDatenelementTest {
val underTest = createZiffernDatenelement(1000, 3)
// when
expect {
assertThrows<IllegalArgumentException> {
underTest.validate()
}.toThrow<IllegalArgumentException>()
}
}

View File

@ -1,10 +1,9 @@
package net.dankito.banking.fints.messages.datenelemente.implementierte
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import ch.tutteli.atrium.api.fluent.en_GB.toThrow
import ch.tutteli.atrium.api.verbs.expect
import net.dankito.banking.fints.extensions.assertThrows
import net.dankito.banking.fints.messages.Existenzstatus
import kotlin.test.Test
import kotlin.test.assertEquals
class BPDVersionTest {
@ -19,7 +18,7 @@ class BPDVersionTest {
val result = underTest.format()
// then
expect(result).toBe("3")
assertEquals("3", result)
}
@ -56,9 +55,9 @@ class BPDVersionTest {
val underTest = BPDVersion(-1, Existenzstatus.Mandatory)
// when
expect {
assertThrows<IllegalArgumentException> {
underTest.validate()
}.toThrow<IllegalArgumentException>()
}
}
@Test
@ -68,9 +67,9 @@ class BPDVersionTest {
val underTest = BPDVersion(1000, Existenzstatus.Mandatory)
// when
expect {
assertThrows<IllegalArgumentException> {
underTest.validate()
}.toThrow<IllegalArgumentException>()
}
}
}

View File

@ -1,7 +1,6 @@
package net.dankito.banking.fints.messages.datenelemente.implementierte
import ch.tutteli.atrium.api.fluent.en_GB.toThrow
import ch.tutteli.atrium.api.verbs.expect
import net.dankito.banking.fints.extensions.assertThrows
import net.dankito.banking.fints.messages.Existenzstatus
import kotlin.test.Test
@ -28,9 +27,9 @@ class ProduktbezeichnungTest {
val underTest = Produktbezeichnung("12345678901234567890123456", Existenzstatus.Mandatory)
// when
expect {
assertThrows<IllegalArgumentException> {
underTest.validate()
}.toThrow<IllegalArgumentException>()
}
}
}

View File

@ -1,11 +1,10 @@
package net.dankito.banking.fints.messages.datenelementgruppen
import ch.tutteli.atrium.api.fluent.en_GB.isEmpty
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import ch.tutteli.atrium.api.verbs.expect
import net.dankito.banking.fints.extensions.assertEmpty
import net.dankito.banking.fints.messages.Separators
import net.dankito.banking.fints.messages.datenelementgruppen.implementierte.signatur.BenutzerdefinierteSignatur
import kotlin.test.Test
import kotlin.test.assertEquals
class DatenelementgruppeTest {
@ -22,7 +21,7 @@ class DatenelementgruppeTest {
val result = dataElementGroup.format()
// then
expect(result).toBe(pin + Separators.DataElementsSeparator + tan) // ":" does not get written to output
assertEquals(pin + Separators.DataElementsSeparator + tan, result) // ":" does not get written to output
}
@Test
@ -37,7 +36,7 @@ class DatenelementgruppeTest {
val result = dataElementGroup.format()
// then
expect(result).toBe(pin) // ":" does not get written to output
assertEquals(pin, result) // ":" does not get written to output
}
@Test
@ -52,7 +51,7 @@ class DatenelementgruppeTest {
val result = dataElementGroup.format()
// then
expect(result).isEmpty() // ":" does not get written to output
assertEmpty(result) // ":" does not get written to output
}
}

View File

@ -1,11 +1,10 @@
package net.dankito.banking.fints.messages.segmente
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import net.dankito.banking.fints.messages.Existenzstatus
import net.dankito.banking.fints.messages.datenelemente.DatenelementBase
import net.dankito.banking.fints.messages.datenelemente.basisformate.TextDatenelement
import ch.tutteli.atrium.api.verbs.expect
import kotlin.test.Test
import kotlin.test.assertEquals
class SegmentTest {
@ -32,7 +31,7 @@ class SegmentTest {
// then
// assert that empty data elements at end get cut but that the empty ones in the middle remain
expect(result).toBe("DE1+DE2++++DE6++DE8")
assertEquals("DE1+DE2++++DE6++DE8", result)
}

View File

@ -1,10 +1,8 @@
package net.dankito.banking.fints.messages.segmente.implementierte
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import net.dankito.banking.fints.FinTsTestBase
import net.dankito.banking.fints.model.MessageBaseData
import ch.tutteli.atrium.api.verbs.expect
import kotlin.test.Test
import kotlin.test.assertEquals
class IdentifikationsSegmentTest : FinTsTestBase() {
@ -19,7 +17,7 @@ class IdentifikationsSegmentTest : FinTsTestBase() {
val result = underTest.format()
// then
expect(result).toBe("HKIDN:2:2+280:12345678+0987654321+0+0")
assertEquals(result, "HKIDN:2:2+280:12345678+0987654321+0+0")
}
}

View File

@ -1,8 +1,7 @@
package net.dankito.banking.fints.messages.segmente.implementierte
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import ch.tutteli.atrium.api.verbs.expect
import kotlin.test.Test
import kotlin.test.assertEquals
class SignaturabschlussTest {
@ -20,7 +19,7 @@ class SignaturabschlussTest {
val result = underTest.format()
// then
expect(result).toBe("HNSHA:$segmentNumber:2+$controlReference++$pin")
assertEquals(result, "HNSHA:$segmentNumber:2+$controlReference++$pin")
}
}

View File

@ -1,10 +1,9 @@
package net.dankito.banking.fints.messages.segmente.implementierte
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import net.dankito.banking.fints.FinTsTestBase
import net.dankito.banking.fints.model.MessageBaseData
import ch.tutteli.atrium.api.verbs.expect
import kotlin.test.Test
import kotlin.test.assertEquals
class SignaturkopfTest : FinTsTestBase() {
@ -22,7 +21,7 @@ class SignaturkopfTest : FinTsTestBase() {
val result = underTest.format()
// then
expect(result).toBe("HNSHK:2:4+PIN:2+${SecurityFunction.code}+$controlReference+1+1+1::0+1+1:$Date:$Time+1:999:1+6:10:16+280:$BankCode:$CustomerId:S:0:0")
assertEquals(result, "HNSHK:2:4+PIN:2+${SecurityFunction.code}+$controlReference+1+1+1::0+1+1:$Date:$Time+1:999:1+6:10:16+280:$BankCode:$CustomerId:S:0:0")
}
}

View File

@ -1,10 +1,9 @@
package net.dankito.banking.fints.messages.segmente.implementierte
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import net.dankito.banking.fints.FinTsTestBase
import net.dankito.banking.fints.model.MessageBaseData
import ch.tutteli.atrium.api.verbs.expect
import kotlin.test.Test
import kotlin.test.assertEquals
class VerschluesselungskopfTest : FinTsTestBase() {
@ -20,7 +19,7 @@ class VerschluesselungskopfTest : FinTsTestBase() {
val result = underTest.format()
// then
expect(normalizeBinaryData(result)).toBe("HNVSK:998:3+PIN:2+998+1+1::0+1:$Date:$Time+2:2:13:@8@ :5:1+280:$BankCode:$CustomerId:V:0:0+0")
assertEquals(normalizeBinaryData(result), "HNVSK:998:3+PIN:2+998+1+1::0+1:$Date:$Time+2:2:13:@8@ :5:1+280:$BankCode:$CustomerId:V:0:0+0")
}
}

View File

@ -1,7 +1,6 @@
package net.dankito.banking.fints.messages.segmente.implementierte.sepa
import ch.tutteli.atrium.api.fluent.en_GB.contains
import ch.tutteli.atrium.api.verbs.expect
import net.dankito.banking.fints.extensions.assertContains
import net.dankito.banking.fints.messages.segmente.id.CustomerSegmentId
import net.dankito.banking.fints.model.*
import kotlin.test.Test
@ -42,7 +41,7 @@ class SepaBankTransferBaseTest {
// then
expect(result).contains(debitorName, debitorIban, debitorBic, recipientName, recipientIban, recipientBic,
assertContains(result, debitorName, debitorIban, debitorBic, recipientName, recipientIban, recipientBic,
amount.toString().replace(',', '.'), reference, "urn?:iso?:std?:iso?:20022?:tech?:xsd?:pain.001.001.03")
}
@ -64,7 +63,7 @@ class SepaBankTransferBaseTest {
// then
expect(result).contains(debitorName, debitorIban, debitorBic, recipientName, recipientIban, recipientBic,
assertContains(result, debitorName, debitorIban, debitorBic, recipientName, recipientIban, recipientBic,
amount.toString().replace(',', '.'), reference, "urn?:iso?:std?:iso?:20022?:tech?:xsd?:pain.001.003.03")
}

View File

@ -1,9 +1,8 @@
package net.dankito.banking.fints.messages.segmente.implementierte.sepa
import ch.tutteli.atrium.api.verbs.expect
import net.dankito.banking.fints.extensions.isFalse
import net.dankito.banking.fints.extensions.isTrue
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class SepaMessageCreatorTest {
@ -18,7 +17,7 @@ class SepaMessageCreatorTest {
val result = underTest.containsOnlyAllowedCharacters("Marieke Musterfrau")
// then
expect(result).isTrue()
assertTrue(result)
}
@Test
@ -28,7 +27,7 @@ class SepaMessageCreatorTest {
val result = underTest.containsOnlyAllowedCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,.?+-/()")
// then
expect(result).isTrue()
assertTrue(result)
}
@Test
@ -38,7 +37,7 @@ class SepaMessageCreatorTest {
val result = underTest.containsOnlyAllowedCharacters(":")
// then
expect(result).isTrue()
assertTrue(result)
}
@Test
@ -48,7 +47,7 @@ class SepaMessageCreatorTest {
val result = underTest.containsOnlyAllowedCharacters("!")
// then
expect(result).isFalse()
assertFalse(result)
}
@Test
@ -58,17 +57,17 @@ class SepaMessageCreatorTest {
val result = underTest.containsOnlyAllowedCharacters("")
// then
expect(result).isFalse()
assertFalse(result)
}
@Test
fun `containsOnlyAllowedCharacters @ is an illegal character`() {
fun `containsOnlyAllowedCharacters at sign is an illegal character`() {
// when
val result = underTest.containsOnlyAllowedCharacters("@")
// then
expect(result).isFalse()
assertFalse(result)
}
@Test
@ -78,7 +77,7 @@ class SepaMessageCreatorTest {
val result = underTest.containsOnlyAllowedCharacters("ö")
// then
expect(result).isFalse()
assertFalse(result)
}
}

View File

@ -1,13 +1,12 @@
package net.dankito.banking.fints.messages.segmente.implementierte.tan
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import ch.tutteli.atrium.api.verbs.expect
import net.dankito.banking.fints.FinTsTestBase
import net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium
import net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanMediumKlasse
import net.dankito.banking.fints.messages.datenelemente.implementierte.tan.TanMediumStatus
import net.dankito.banking.fints.response.segments.ChangeTanMediaParameters
import kotlin.test.Test
import kotlin.test.assertEquals
class TanGeneratorTanMediumAnOderUmmeldenTest: FinTsTestBase() {
@ -50,7 +49,7 @@ class TanGeneratorTanMediumAnOderUmmeldenTest: FinTsTestBase() {
// then
expect(result).toBe("HKTAU:$SegmentNumber:1+G+$CardNumber")
assertEquals(result, "HKTAU:$SegmentNumber:1+G+$CardNumber")
}
@Test
@ -67,7 +66,7 @@ class TanGeneratorTanMediumAnOderUmmeldenTest: FinTsTestBase() {
// then
expect(result).toBe("HKTAU:$SegmentNumber:1+G+$CardNumber+++$ATC+$TAN")
assertEquals(result, "HKTAU:$SegmentNumber:1+G+$CardNumber+++$ATC+$TAN")
}
@Test
@ -84,7 +83,7 @@ class TanGeneratorTanMediumAnOderUmmeldenTest: FinTsTestBase() {
// then
expect(result).toBe("HKTAU:$SegmentNumber:1+G+$CardNumber+$CardSequenceNumber")
assertEquals(result, "HKTAU:$SegmentNumber:1+G+$CardNumber+$CardSequenceNumber")
}
@Test
@ -101,7 +100,7 @@ class TanGeneratorTanMediumAnOderUmmeldenTest: FinTsTestBase() {
// then
expect(result).toBe("HKTAU:$SegmentNumber:1+G+$CardNumber+$CardSequenceNumber++$ATC+$TAN")
assertEquals(result, "HKTAU:$SegmentNumber:1+G+$CardNumber+$CardSequenceNumber++$ATC+$TAN")
}
@ -119,7 +118,7 @@ class TanGeneratorTanMediumAnOderUmmeldenTest: FinTsTestBase() {
// then
expect(result).toBe("HKTAU:$SegmentNumber:2+G+$CardNumber+++$CustomerId::$BankCountryCode:$BankCode")
assertEquals(result, "HKTAU:$SegmentNumber:2+G+$CardNumber+++$CustomerId::$BankCountryCode:$BankCode")
}
@Test
@ -136,7 +135,7 @@ class TanGeneratorTanMediumAnOderUmmeldenTest: FinTsTestBase() {
// then
expect(result).toBe("HKTAU:$SegmentNumber:2+G+$CardNumber+++$CustomerId::$BankCountryCode:$BankCode++++$ATC+$TAN")
assertEquals(result, "HKTAU:$SegmentNumber:2+G+$CardNumber+++$CustomerId::$BankCountryCode:$BankCode++++$ATC+$TAN")
}
@Test
@ -153,7 +152,7 @@ class TanGeneratorTanMediumAnOderUmmeldenTest: FinTsTestBase() {
// then
expect(result).toBe("HKTAU:$SegmentNumber:2+G+$CardNumber+$CardSequenceNumber++$CustomerId::$BankCountryCode:$BankCode")
assertEquals(result, "HKTAU:$SegmentNumber:2+G+$CardNumber+$CardSequenceNumber++$CustomerId::$BankCountryCode:$BankCode")
}
@Test
@ -170,7 +169,7 @@ class TanGeneratorTanMediumAnOderUmmeldenTest: FinTsTestBase() {
// then
expect(result).toBe("HKTAU:$SegmentNumber:2+G+$CardNumber++$CardType+$CustomerId::$BankCountryCode:$BankCode")
assertEquals(result, "HKTAU:$SegmentNumber:2+G+$CardNumber++$CardType+$CustomerId::$BankCountryCode:$BankCode")
}
@Test
@ -187,7 +186,7 @@ class TanGeneratorTanMediumAnOderUmmeldenTest: FinTsTestBase() {
// then
expect(result).toBe("HKTAU:$SegmentNumber:2+G+$CardNumber+$CardSequenceNumber+$CardType+$CustomerId::$BankCountryCode:$BankCode++++$ATC+$TAN")
assertEquals(result, "HKTAU:$SegmentNumber:2+G+$CardNumber+$CardSequenceNumber+$CardType+$CustomerId::$BankCountryCode:$BankCode++++$ATC+$TAN")
}
// TODO: may also test 'gueltig ab' and 'gueltig bis'

View File

@ -1,9 +1,8 @@
package net.dankito.banking.fints.messages.segmente.implementierte.umsaetze
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import ch.tutteli.atrium.api.verbs.expect
import net.dankito.banking.fints.FinTsTestBase
import kotlin.test.Test
import kotlin.test.assertEquals
class SaldenabfrageVersion5Test : FinTsTestBase() {
@ -18,7 +17,7 @@ class SaldenabfrageVersion5Test : FinTsTestBase() {
val result = underTest.format()
// then
expect(result).toBe("HKSAL:3:5+$CustomerId::280:$BankCode+N")
assertEquals(result, "HKSAL:3:5+$CustomerId::280:$BankCode+N")
}
@Test
@ -31,7 +30,7 @@ class SaldenabfrageVersion5Test : FinTsTestBase() {
val result = underTest.format()
// then
expect(result).toBe("HKSAL:3:5+$CustomerId::280:$BankCode+J")
assertEquals(result, "HKSAL:3:5+$CustomerId::280:$BankCode+J")
}
}

View File

@ -1,9 +1,8 @@
package net.dankito.banking.fints.messages.segmente.implementierte.umsaetze
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import net.dankito.banking.fints.FinTsTestBase
import ch.tutteli.atrium.api.verbs.expect
import kotlin.test.Test
import kotlin.test.assertEquals
class SaldenabfrageVersion7Test : FinTsTestBase() {
@ -18,7 +17,7 @@ class SaldenabfrageVersion7Test : FinTsTestBase() {
val result = underTest.format()
// then
expect(result).toBe("HKSAL:3:7+$Iban:$Bic:$CustomerId::280:$BankCode+N")
assertEquals(result, "HKSAL:3:7+$Iban:$Bic:$CustomerId::280:$BankCode+N")
}
@Test
@ -31,7 +30,7 @@ class SaldenabfrageVersion7Test : FinTsTestBase() {
val result = underTest.format()
// then
expect(result).toBe("HKSAL:3:7+$Iban:$Bic:$CustomerId::280:$BankCode+J")
assertEquals(result, "HKSAL:3:7+$Iban:$Bic:$CustomerId::280:$BankCode+J")
}
}

View File

@ -1,9 +1,8 @@
package net.dankito.banking.fints.tan
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import ch.tutteli.atrium.api.verbs.expect
import net.dankito.banking.fints.model.HHDVersion
import kotlin.test.Test
import kotlin.test.assertEquals
class FlickerCodeDecoderTest {
@ -23,7 +22,7 @@ class FlickerCodeDecoderTest {
// then
expect(response.parsedDataSet).toBe("070520829019981A")
assertEquals("070520829019981A", response.parsedDataSet)
}
@ -39,7 +38,7 @@ class FlickerCodeDecoderTest {
// then
expect(response.parsedDataSet).toBe("100520829019981849453939424F46494B")
assertEquals("100520829019981849453939424F46494B", response.parsedDataSet)
}
@Test
@ -52,7 +51,7 @@ class FlickerCodeDecoderTest {
val result = underTest.decodeChallenge(challenge, HHDVersion.HHD_1_3)
// then
expect(result.parsedDataSet).toBe("1204881696280598765432101533322C30303A")
assertEquals("1204881696280598765432101533322C30303A", result.parsedDataSet)
}
@Test
@ -65,7 +64,7 @@ class FlickerCodeDecoderTest {
val result = underTest.decodeChallenge(challenge, HHDVersion.HHD_1_3)
// then
expect(result.parsedDataSet).toBe("0604800402430B")
assertEquals("0604800402430B", result.parsedDataSet)
}
@ -79,7 +78,7 @@ class FlickerCodeDecoderTest {
val result = underTest.decodeChallenge(challenge, HHDVersion.HHD_1_4)
// then
expect(result.parsedDataSet).toBe("1F85012392301246564445323631323334353637383039383736353433323175")
assertEquals("1F85012392301246564445323631323334353637383039383736353433323175", result.parsedDataSet)
}
@Test
@ -92,7 +91,7 @@ class FlickerCodeDecoderTest {
val result = underTest.decodeChallenge(challenge, HHDVersion.HHD_1_4)
// then
expect(result.parsedDataSet).toBe("2584011093744F5644453236313233343536373830393837363534333231463130302C303008")
assertEquals("2584011093744F5644453236313233343536373830393837363534333231463130302C303008", result.parsedDataSet)
}
}

View File

@ -1,21 +1,16 @@
package net.dankito.banking.fints.transactions
import ch.tutteli.atrium.api.fluent.en_GB.hasSize
import ch.tutteli.atrium.api.fluent.en_GB.notToBeNull
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import net.dankito.banking.fints.FinTsTestBase
import net.dankito.banking.fints.transactions.mt940.Mt940Parser
import net.dankito.banking.fints.transactions.mt940.model.Balance
import net.dankito.banking.fints.transactions.mt940.model.InformationToAccountOwner
import net.dankito.banking.fints.transactions.mt940.model.StatementLine
import ch.tutteli.atrium.api.verbs.expect
import kotlinx.datetime.LocalDate
import kotlin.test.Test
import net.dankito.banking.fints.extensions.isFalse
import net.dankito.banking.fints.extensions.isTrue
import net.dankito.banking.fints.extensions.*
import net.dankito.banking.fints.model.Amount
import net.dankito.utils.multiplatform.DateFormatter
import net.dankito.utils.multiplatform.extensions.format
import net.dankito.utils.multiplatform.extensions.toStringWithTwoDigits
import kotlin.test.Test
import kotlin.test.assertContains
class Mt940ParserTest : FinTsTestBase() {
@ -57,16 +52,16 @@ class Mt940ParserTest : FinTsTestBase() {
// then
expect(result).hasSize(1)
assertSize(1, result)
val statement = result.first()
expect(statement.bankCodeBicOrIban).toBe(BankCode)
expect(statement.accountIdentifier).toBe(CustomerId)
assertEquals(BankCode, statement.bankCodeBicOrIban)
assertEquals(CustomerId, statement.accountIdentifier)
assertBalance(statement.openingBalance, true, AccountStatement1PreviousStatementBookingDate, AccountStatement1OpeningBalanceAmount)
assertBalance(statement.closingBalance, true, AccountStatement1BookingDate, AccountStatement1ClosingBalanceAmount)
expect(statement.transactions).hasSize(1)
assertSize(1, statement.transactions)
val transaction = statement.transactions.first()
assertTurnover(transaction.statementLine, AccountStatement1BookingDate, AccountStatement1Transaction1Amount)
@ -87,19 +82,19 @@ class Mt940ParserTest : FinTsTestBase() {
// then
expect(result).hasSize(1)
assertSize(1, result)
val statement = result.first()
expect(statement.bankCodeBicOrIban).toBe(BankCode)
expect(statement.accountIdentifier).toBe(CustomerId)
expect(statement.statementNumber).toBe(0)
expect(statement.sequenceNumber).toBe(null)
assertEquals(BankCode, statement.bankCodeBicOrIban)
assertEquals(CustomerId, statement.accountIdentifier)
assertEquals(0, statement.statementNumber)
assertNull(statement.sequenceNumber)
assertBalance(statement.openingBalance, true, bookingDate, Amount("0,00"))
assertBalance(statement.closingBalance, isCredit, bookingDate, amount)
expect(statement.transactions).hasSize(1)
assertSize(1, statement.transactions)
val transaction = statement.transactions.first()
assertTurnover(transaction.statementLine, bookingDate, amount, isCredit)
@ -114,16 +109,16 @@ class Mt940ParserTest : FinTsTestBase() {
// then
expect(result).hasSize(1)
assertSize(1, result)
val statement = result.first()
expect(statement.bankCodeBicOrIban).toBe(BankCode)
expect(statement.accountIdentifier).toBe(CustomerId)
assertEquals(BankCode, statement.bankCodeBicOrIban)
assertEquals(CustomerId, statement.accountIdentifier)
assertBalance(statement.openingBalance, true, AccountStatement1PreviousStatementBookingDate, AccountStatement1OpeningBalanceAmount)
assertBalance(statement.closingBalance, true, AccountStatement1BookingDate, AccountStatement1With2TransactionsClosingBalanceAmount)
expect(statement.transactions).hasSize(2)
assertSize(2, statement.transactions)
val firstTransaction = statement.transactions.first()
assertTurnover(firstTransaction.statementLine, AccountStatement1BookingDate, AccountStatement1Transaction1Amount)
@ -158,13 +153,17 @@ class Mt940ParserTest : FinTsTestBase() {
// then
expect(result).hasSize(1)
expect(result.first().transactions).hasSize(2)
assertSize(1, result)
assertSize(2, result.first().transactions)
expect(result.first().transactions[0].statementLine.bookingDate).toBe(LocalDate(2019, 12, 30))
expect(result.first().transactions[0].statementLine.valueDate).toBe(LocalDate(2020, 1, 1))
expect(result.first().transactions[1].statementLine.bookingDate).toBe(LocalDate(2019, 12, 30))
expect(result.first().transactions[1].statementLine.valueDate).toBe(LocalDate(2020, 1, 1))
result.first().transactions[0].statementLine.apply {
assertEquals(LocalDate(2019, 12, 30), bookingDate)
assertEquals(LocalDate(2020, 1, 1), valueDate)
}
result.first().transactions[1].statementLine.apply {
assertEquals(LocalDate(2019, 12, 30), bookingDate)
assertEquals(LocalDate(2020, 1, 1), valueDate)
}
}
@Test
@ -226,8 +225,8 @@ class Mt940ParserTest : FinTsTestBase() {
// then
expect(result).hasSize(3)
expect(result.flatMap { it.transactions }).hasSize(7)
assertSize(3, result)
assertSize(7, result.flatMap { it.transactions })
}
@Test
@ -265,22 +264,22 @@ class Mt940ParserTest : FinTsTestBase() {
// then
expect(result).hasSize(1)
expect(result.flatMap { it.transactions }).hasSize(3)
assertSize(1, result)
assertSize(3, result.flatMap { it.transactions })
result.flatMap { it.transactions }.forEach { transaction ->
expect(transaction.information).notToBeNull()
assertNotNull(transaction.information)
expect(transaction.information?.sepaReference).notToBeNull()
assertNotNull(transaction.information?.sepaReference)
if (transaction.information?.unparsedReference?.contains("KREF+") == true) {
expect(transaction.information?.customerReference).notToBeNull()
assertNotNull(transaction.information?.customerReference)
}
}
}
@Test
fun `Fix that ?, gets detected as field code`() {
fun `Fix that questionmark, gets detected as field code`() {
val transactionsString = """
:20:STARTUMS
:25:$BankCode/$CustomerId
@ -302,43 +301,45 @@ class Mt940ParserTest : FinTsTestBase() {
// then
expect(result).hasSize(1)
expect(result.first().transactions).hasSize(1)
assertSize(1, result)
assertSize(1, result.first().transactions)
expect(result.first().transactions[0].information?.bookingText).toBe("BASISLASTSCHRIFT")
expect(result.first().transactions[0].information?.otherPartyBankCode).toBe("TUBDDEDD")
expect(result.first().transactions[0].information?.otherPartyAccountId).toBe("DE87300308801234567890")
expect(result.first().transactions[0].information?.endToEndReference).toBe("6MKL2OT30QENNLIU")
expect(result.first().transactions[0].information?.mandateReference).toBe("?,3SQNdUbxm9z7dB)+gKYDJAKzCM0G")
expect(result.first().transactions[0].information?.sepaReference?.contains("IBAN: DE87300308801234567890 BIC: TUBDDEDD") ?: false).isTrue()
result.first().transactions[0].information?.apply {
assertEquals("BASISLASTSCHRIFT", bookingText)
assertEquals("TUBDDEDD", otherPartyBankCode)
assertEquals("DE87300308801234567890", otherPartyAccountId)
assertEquals("6MKL2OT30QENNLIU", endToEndReference)
assertEquals("?,3SQNdUbxm9z7dB)+gKYDJAKzCM0G", mandateReference)
assertContains(sepaReference ?: "", "IBAN: DE87300308801234567890 BIC: TUBDDEDD")
}
}
private fun assertBalance(balance: Balance, isCredit: Boolean, bookingDate: LocalDate, amount: Amount) {
expect(balance.isCredit).toBe(isCredit)
expect(balance.bookingDate).toBe(bookingDate)
expect(balance.amount).toBe(amount)
expect(balance.currency).toBe(Currency)
assertEquals(isCredit, balance.isCredit)
assertEquals(bookingDate, balance.bookingDate)
assertEquals(amount, balance.amount)
assertEquals(Currency, balance.currency)
}
private fun assertTurnover(statementLine: StatementLine, valueDate: LocalDate, amount: Amount, isCredit: Boolean = true,
bookingDate: LocalDate? = valueDate) {
expect(statementLine.isCredit).toBe(isCredit)
expect(statementLine.isReversal).isFalse()
expect(statementLine.valueDate).toBe(valueDate)
expect(statementLine.bookingDate).toBe(bookingDate)
expect(statementLine.amount).toBe(amount)
assertEquals(isCredit, statementLine.isCredit)
assertFalse(statementLine.isReversal)
assertEquals(valueDate, statementLine.valueDate)
assertEquals(bookingDate, statementLine.bookingDate)
assertEquals(amount, statementLine.amount)
}
private fun assertTransactionDetails(details: InformationToAccountOwner?, otherPartyName: String,
otherPartyBankCode: String, otherPartyAccountId: String) {
expect(details).notToBeNull()
assertNotNull(details)
expect(details?.otherPartyName).toBe(otherPartyName)
expect(details?.otherPartyBankCode).toBe(otherPartyBankCode)
expect(details?.otherPartyAccountId).toBe(otherPartyAccountId)
assertEquals(otherPartyName, details.otherPartyName)
assertEquals(otherPartyBankCode, details.otherPartyBankCode)
assertEquals(otherPartyAccountId, details.otherPartyAccountId)
}

View File

@ -1,12 +1,9 @@
package net.dankito.banking.fints.util
import ch.tutteli.atrium.api.fluent.en_GB.ExperimentalWithOptions
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import ch.tutteli.atrium.api.fluent.en_GB.withRepresentation
import ch.tutteli.atrium.api.verbs.expect
import net.dankito.utils.multiplatform.extensions.randomWithSeed
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertEquals
class Base64Test {
@ -31,7 +28,7 @@ class Base64Test {
private fun testEncode(input: String, expectedOutput: String) {
val actualOutput = underTest.encode(input)
expect(actualOutput).toBe(expectedOutput)
assertEquals(expectedOutput, actualOutput)
}
@ -52,12 +49,11 @@ class Base64Test {
private fun testDecode(input: String, expectedOutput: String) {
val actualOutput = underTest.decode(input)
expect(actualOutput).toBe(expectedOutput)
assertEquals(expectedOutput, actualOutput)
}
@Test
@ExperimentalWithOptions
fun testRandomStrings() {
val steps = 1000000
val random = randomWithSeed()
@ -74,7 +70,7 @@ class Base64Test {
// then
expect(decoded).withRepresentation { "Decoded string '$decoded' should actually be '$original'" }.toBe(original)
assertEquals(original, decoded, "Decoded string '$decoded' should actually be '$original'")
}
}

View File

@ -1,11 +1,10 @@
package net.dankito.banking.fints.util
import ch.tutteli.atrium.api.fluent.en_GB.toBe
import ch.tutteli.atrium.api.verbs.expect
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
import net.dankito.utils.multiplatform.extensions.of
import kotlin.test.Test
import kotlin.test.assertEquals
class FinTsUtilsTest {
@ -22,7 +21,7 @@ class FinTsUtilsTest {
val result = underTest.formatDate(date)
// then
expect(result).toBe("19880327")
assertEquals("19880327", result)
}
@Test
@ -35,7 +34,7 @@ class FinTsUtilsTest {
val result = underTest.formatDateAsInt(date)
// then
expect(result).toBe(19880327)
assertEquals(19880327, result)
}
@ -49,7 +48,7 @@ class FinTsUtilsTest {
val result = underTest.formatTime(time)
// then
expect(result).toBe("080201")
assertEquals("080201", result)
}
@Test
@ -62,7 +61,7 @@ class FinTsUtilsTest {
val result = underTest.formatTime(time)
// then
expect(result).toBe("182251")
assertEquals("182251", result)
}
@Test
@ -75,7 +74,7 @@ class FinTsUtilsTest {
val result = underTest.formatTimeAsInt(time)
// then
expect(result).toBe(80201)
assertEquals(80201, result)
}
@Test
@ -88,7 +87,7 @@ class FinTsUtilsTest {
val result = underTest.formatTimeAsInt(time)
// then
expect(result).toBe(182251)
assertEquals(182251, result)
}
}

View File

@ -88,7 +88,7 @@
// underTest.getAnonymousBankInfo(BankDataAnonymous) { result ->
//
// // then
// expect(result.successful).isTrue()
// assertTrue(result.successful)
// expect(BankDataAnonymous.supportedHbciVersions).isNotEmpty()
// expect(BankDataAnonymous.tanMethodsSupportedByBank).isNotEmpty()
// expect(BankDataAnonymous.supportedJobs).isNotEmpty()
@ -117,9 +117,9 @@
// countDownLatch.await(30, TimeUnit.SECONDS)
// val result = response.get()
//
// expect(result.successful).isTrue()
// assertTrue(result.successful)
//
// expect(didAskUserForTanMethod).isFalse()
// assertFalse(didAskUserForTanMethod)
//
// expect(Bank.bankName).isNotEmpty()
// expect(Bank.supportedJobs).isNotEmpty() // supported jobs are now known
@ -131,7 +131,7 @@
// expect(Bank.tanMethodsAvailableForUser).isNotEmpty()
// expect(Bank.selectedLanguage).notToBe(Dialogsprache.Default) // language is set now
// expect(Bank.customerSystemId).notToBe(KundensystemStatus.SynchronizingCustomerSystemId.code) // customer system id is now set
// expect(Bank.customerSystemStatus).toBe(KundensystemStatusWerte.Benoetigt) // customerSystemStatus is set now
// assertEquals(KundensystemStatusWerte.Benoetigt, Bank.customerSystemStatus) // customerSystemStatus is set now
// expect(Bank.accounts).isNotEmpty() // accounts are now known
// expect(Bank.accounts.first().allowedJobs).isNotEmpty() // allowed jobs are now known
// }
@ -205,7 +205,7 @@
// countDownLatch.await(30, TimeUnit.SECONDS)
// val result = response.get()
//
// expect(result.successful).isTrue()
// assertTrue(result.successful)
//
// expect(result.tanMediaList).notToBeNull()
// expect(result.tanMediaList!!.usageOption).toBe(TanEinsatzOption.KundeKannGenauEinMediumZuEinerZeitNutzen) // TODO: may adjust to your value
@ -263,7 +263,7 @@
// countDownLatch.await(30, TimeUnit.SECONDS)
// val result = response.get()
//
// expect(result.successful).isTrue()
// assertTrue(result.successful)
//
// }
//

View File

@ -54,8 +54,6 @@ kotlin {
dependencies {
implementation kotlin("test-common")
implementation kotlin("test-annotations-common")
implementation "ch.tutteli.atrium:atrium-fluent-en_GB-common:$atriumVersion"
}
}
@ -76,11 +74,6 @@ kotlin {
implementation "org.junit.jupiter:junit-jupiter:$junit5Version"
runtimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit5Version"
implementation "org.assertj:assertj-core:$assertJVersion"
implementation "org.mockito:mockito-core:$mockitoVersion"
implementation "ch.tutteli.atrium:atrium-fluent-en_GB:$atriumVersion"
implementation "org.slf4j:slf4j-simple:$slf4jVersion"
}

View File

@ -21,7 +21,7 @@ dependencies {
implementation 'org.docx4j:docx4j-JAXB-ReferenceImpl:8.1.3'
testImplementation "junit:junit:$junitVersion"
testImplementation "junit:junit:4.12"
testImplementation "org.assertj:assertj-core:$assertJVersion"
testImplementation "ch.qos.logback:logback-core:$logbackVersion"