35 lines
No EOL
1.3 KiB
Kotlin
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"))
|
|
)
|
|
}
|
|
}
|
|
} |