Finish assignment

Signed-off-by: Severin Kaderli <severin@kaderli.dev>
This commit is contained in:
Severin Kaderli 2022-03-30 19:17:43 +02:00
parent c016d3cf61
commit af528d26c4
Signed by: severinkaderli
GPG key ID: F419F8835B72F0C4
11 changed files with 145 additions and 25 deletions

View file

@ -0,0 +1,35 @@
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"))
)
}
}
}