Use approval testing framework for statement printer test

It's better to store the expected text in a separate file instead of mixed
in together with the kotlin test code. This is for several reasons
- it is easier to read when the expected value is on several lines
- it is easier to update using a diff merge tool
- it is easier to read the VCS history since it will probably change
more frequently than the rest of the test code
This commit is contained in:
Emily Bache
2019-09-10 10:40:56 +02:00
parent 6d81ebd095
commit 2e599e4f1d
4 changed files with 13 additions and 10 deletions

View File

@@ -0,0 +1,6 @@
Statement for BigCo
Hamlet: $650.00 (55 seats)
As You Like It: $580.00 (35 seats)
Othello: $500.00 (40 seats)
Amount owed is $1,730.00
You earned 47 credits

View File

@@ -1,17 +1,12 @@
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Test
import org.approvaltests.Approvals.verify
class StatementPrinterTests {
@Test
internal fun exampleStatement() {
val expected = "Statement for BigCo\n" +
" Hamlet: \$650.00 (55 seats)\n" +
" As You Like It: \$580.00 (35 seats)\n" +
" Othello: \$500.00 (40 seats)\n" +
"Amount owed is \$1,730.00\n" +
"You earned 47 credits\n"
val plays = mapOf(
"hamlet" to Play("Hamlet", "tragedy"),
@@ -30,7 +25,7 @@ class StatementPrinterTests {
val statementPrinter = StatementPrinter()
val result = statementPrinter.print(invoice, plays)
assertEquals(expected, result)
verify(result)
}
@Test