Extracted test DataGenerator
This commit is contained in:
parent
29650d2660
commit
a512456a48
|
@ -1,12 +1,9 @@
|
||||||
package net.codinux.invoicing.creation
|
package net.codinux.invoicing.creation
|
||||||
|
|
||||||
import assertk.assertThat
|
import assertk.assertThat
|
||||||
|
import assertk.assertions.contains
|
||||||
import assertk.assertions.isNotEmpty
|
import assertk.assertions.isNotEmpty
|
||||||
import net.codinux.invoicing.model.Invoice
|
import net.codinux.invoicing.test.DataGenerator
|
||||||
import net.codinux.invoicing.model.LineItem
|
|
||||||
import net.codinux.invoicing.model.Party
|
|
||||||
import java.math.BigDecimal
|
|
||||||
import java.time.LocalDate
|
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
|
||||||
class EInvoiceCreatorTest {
|
class EInvoiceCreatorTest {
|
||||||
|
@ -20,7 +17,7 @@ class EInvoiceCreatorTest {
|
||||||
|
|
||||||
val result = underTest.createXRechnungXml(invoice)
|
val result = underTest.createXRechnungXml(invoice)
|
||||||
|
|
||||||
assertThat(result).isNotEmpty()
|
assertInvoiceXml(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -29,36 +26,17 @@ class EInvoiceCreatorTest {
|
||||||
|
|
||||||
val result = underTest.createZugferdXml(invoice)
|
val result = underTest.createZugferdXml(invoice)
|
||||||
|
|
||||||
assertThat(result).isNotEmpty()
|
assertInvoiceXml(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun createInvoice(
|
private fun createInvoice() = DataGenerator.createInvoice()
|
||||||
invoiceNumber: String = "12345",
|
|
||||||
invoicingDate: LocalDate = LocalDate.of(2015, 10, 21),
|
|
||||||
sender: Party = createParty("Hochwürdiger Leistungserbringer"),
|
|
||||||
recipient: Party = createParty("Untertänigster Leistungsempfänger"),
|
|
||||||
items: List<LineItem> = listOf(createItem()),
|
|
||||||
dueDate: LocalDate? = null
|
|
||||||
) = Invoice(invoiceNumber, invoicingDate, sender, recipient, items, dueDate)
|
|
||||||
|
|
||||||
private fun createParty(
|
private fun assertInvoiceXml(xml: String) {
|
||||||
name: String,
|
assertThat(xml).isNotEmpty()
|
||||||
streetName: String = "Fun Street 1",
|
|
||||||
postalCode: String = "12345",
|
|
||||||
city: String = "Glückstadt",
|
|
||||||
country: String? = null,
|
|
||||||
taxNumber: String? = "DE12345678",
|
|
||||||
email: String? = null,
|
|
||||||
) = Party(name, streetName, postalCode, city, country, taxNumber, email)
|
|
||||||
|
|
||||||
private fun createItem(
|
assertThat(xml).contains("<ram:ID>${DataGenerator.InvoiceNumber}</ram:ID>")
|
||||||
name: String = "Erbrachte Dienstleistungen",
|
assertThat(xml).contains("""<udt:DateTimeString format="102">${DataGenerator.InvoicingDate.toString().replace("-", "")}</udt:DateTimeString>""")
|
||||||
unit: String = "",
|
}
|
||||||
quantity: BigDecimal = BigDecimal(1),
|
|
||||||
price: BigDecimal = BigDecimal(99),
|
|
||||||
vatPercentage: BigDecimal = BigDecimal(0.19),
|
|
||||||
description: String? = null,
|
|
||||||
) = LineItem(name, unit, quantity, price, vatPercentage, description)
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package net.codinux.invoicing.test
|
||||||
|
|
||||||
|
import net.codinux.invoicing.model.Invoice
|
||||||
|
import net.codinux.invoicing.model.LineItem
|
||||||
|
import net.codinux.invoicing.model.Party
|
||||||
|
import java.math.BigDecimal
|
||||||
|
import java.time.LocalDate
|
||||||
|
|
||||||
|
object DataGenerator {
|
||||||
|
|
||||||
|
const val InvoiceNumber = "12345"
|
||||||
|
val InvoicingDate = LocalDate.of(2015, 10, 21)
|
||||||
|
|
||||||
|
const val SenderName = "Hochwürdiger Leistungserbringer"
|
||||||
|
const val SenderStreet = "Fun Street 1"
|
||||||
|
const val SenderPostalCode = "12345"
|
||||||
|
const val SenderCity = "Glückstadt"
|
||||||
|
val SenderCountry: String? = null
|
||||||
|
const val SenderVatId = "DE12345678"
|
||||||
|
const val SenderEmail = "working-class-hero@rock.me"
|
||||||
|
|
||||||
|
const val RecipientName = "Untertänigster Leistungsempfänger"
|
||||||
|
const val RecipientStreet = "Party Street 1"
|
||||||
|
const val RecipientPostalCode = SenderPostalCode
|
||||||
|
const val RecipientCity = SenderCity
|
||||||
|
val RecipientCountry: String? = SenderCountry
|
||||||
|
const val RecipientVatId = "DE87654321"
|
||||||
|
const val RecipientEmail = "exploiter@your.boss"
|
||||||
|
|
||||||
|
const val ItemName = "Erbrachte Dienstleistungen"
|
||||||
|
const val ItemUnit = "HUR" // EN code for 'hour'
|
||||||
|
val ItemQuantity = BigDecimal(1)
|
||||||
|
val ItemPrice = BigDecimal(99)
|
||||||
|
val ItemVat = BigDecimal(0.19)
|
||||||
|
val ItemDescription: String? = null
|
||||||
|
|
||||||
|
|
||||||
|
fun createInvoice(
|
||||||
|
invoiceNumber: String = InvoiceNumber,
|
||||||
|
invoicingDate: LocalDate = InvoicingDate,
|
||||||
|
sender: Party = createParty(SenderName, SenderStreet, SenderPostalCode, SenderCity, SenderCountry, SenderVatId, SenderEmail),
|
||||||
|
recipient: Party = createParty(RecipientName, RecipientStreet, RecipientPostalCode, RecipientCity, RecipientCountry, RecipientVatId, RecipientEmail),
|
||||||
|
items: List<LineItem> = listOf(createItem()),
|
||||||
|
dueDate: LocalDate? = null
|
||||||
|
) = Invoice(invoiceNumber, invoicingDate, sender, recipient, items, dueDate)
|
||||||
|
|
||||||
|
fun createParty(
|
||||||
|
name: String,
|
||||||
|
streetName: String = SenderStreet,
|
||||||
|
postalCode: String = SenderPostalCode,
|
||||||
|
city: String = SenderCity,
|
||||||
|
country: String? = SenderCountry,
|
||||||
|
taxNumber: String? = SenderVatId,
|
||||||
|
email: String? = SenderEmail,
|
||||||
|
) = Party(name, streetName, postalCode, city, country, taxNumber, email)
|
||||||
|
|
||||||
|
fun createItem(
|
||||||
|
name: String = ItemName,
|
||||||
|
unit: String = ItemUnit,
|
||||||
|
quantity: BigDecimal = ItemQuantity,
|
||||||
|
price: BigDecimal = ItemPrice,
|
||||||
|
vatPercentage: BigDecimal = ItemVat,
|
||||||
|
description: String? = ItemDescription,
|
||||||
|
) = LineItem(name, unit, quantity, price, vatPercentage, description)
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue