BTI2015-Assessment-2/src/test/kotlin/InvoiceTest.kt
Severin Kaderli af528d26c4
Finish assignment
Signed-off-by: Severin Kaderli <severin@kaderli.dev>
2022-03-30 19:17:43 +02:00

35 lines
No EOL
1.3 KiB
Kotlin

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
import java.util.stream.Stream
internal class InvoiceTest {
@ParameterizedTest(name = "Test that the invoice has {0} products and a total price of {1}")
@MethodSource("provideValidInvoices")
fun getTotalPrice(numberOfProducts: Int, totalPrice: Float, invoice: Invoice) {
assertEquals(numberOfProducts, invoice.products.size)
assertEquals(totalPrice, invoice.totalPrice)
}
@Test
fun `test invalid columns`() {
assertThrows<ParseException> {
Invoice.fromFile("src/test/resources/invoice_with_invalid_column.txt")
}
}
companion object {
@JvmStatic
fun provideValidInvoices(): Stream<Arguments> {
return Stream.of(
Arguments.of(6, 3950.3f, Invoice.fromFile("src/test/resources/invoice1.txt")),
Arguments.of(6, 3950.3f, Invoice.fromFile("src/test/resources/invoice2.txt")),
Arguments.of(6, 3950.3f, Invoice.fromFile("src/test/resources/invoice3.txt"))
)
}
}
}