Skip to content

Commit

Permalink
Add test on Invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
philou committed Mar 18, 2024
1 parent bb3391f commit 5652c04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion java/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
We will be using the mikado method to incrementally create the test data builder pattern for the Invoice class.
Indentation represents dependencies, and should be done first

- [ ] Add a test to highlight the issue in Invoice, using the test data builder pattern
- [x] Add a test to highlight the issue in Invoice, using the test data builder pattern
- [x] Create a test data builder for the Invoice class
- [x] Create a test data builder for the PurchaseBook class
- [x] Create a test data builder for the Novel class
Expand Down
15 changes: 6 additions & 9 deletions java/src/test/java/com/murex/tbw/purchase/InvoiceTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.murex.tbw.purchase;

import com.murex.tbw.domain.country.TestCountries;
import org.junit.jupiter.api.Test;

import static com.murex.tbw.domain.book.NovelTestDataBuilder.aNovel;
import static com.murex.tbw.purchase.InvoiceTestDataBuilder.anInvoice;
import static com.murex.tbw.purchase.PurchasedBookTestDataBuilder.aPurchase;
import static org.junit.jupiter.api.Assertions.assertEquals;

class InvoiceTest {
@Test
Expand Down Expand Up @@ -32,17 +35,11 @@ void Mikado_Method_Constraint_Applies_tax_rules_when_computing_total_amount() {
@Test
void Mikado_Method_And_Test_Data_Builders_Constraint_Applies_tax_rules_when_computing_total_amount() {
// Using the Mikado method and the Test Data Builder pattern:
// Instantiate an Invoice sent to USA
// InvoiceBuilder.anInvoice()
// .sentTo("USA")
// .withItem(aNovel()
// .costing(50))
// .build();

aPurchase().of(aNovel().costing(50)).quantity(1).build();

Invoice invoice = anInvoice().sentTo(TestCountries.USA)
.with(aPurchase().of(aNovel().costing(50))).build();

// Add it a purchased novel costing 50
// Assert the total amount of the invoice is 56,35 : 15% of taxes plus a 2% reduction on novels
assertEquals(56.35, invoice.computeTotalAmount());
}
}

0 comments on commit 5652c04

Please sign in to comment.