Skip to content

Commit

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

- [ ] Add a test to highlight the issue in Invoice, using the test data builder pattern
- [ ] Create a test data builder for the Invoice class
- [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
- [x] Create test data builder for Author
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.murex.tbw.purchase;

import com.murex.tbw.domain.country.Country;
import com.murex.tbw.domain.country.TestCountries;

import java.util.ArrayList;

public class InvoiceTestDataBuilder {

private final ArrayList<PurchasedBook> purchasedBooks = new ArrayList<>();
private Country country = TestCountries.USA;

public static InvoiceTestDataBuilder anInvoice() {
return new InvoiceTestDataBuilder();
}

public InvoiceTestDataBuilder with(PurchasedBookTestDataBuilder... purchasedBookTestDataBuilders) {
for (PurchasedBookTestDataBuilder purchasedBookTestDataBuilder : purchasedBookTestDataBuilders) {
purchasedBooks.add(purchasedBookTestDataBuilder.build());
}
return this;
}

public InvoiceTestDataBuilder sentTo(Country country) {
this.country = country;
return this;
}

public Invoice build() {
Invoice invoice = new Invoice("John Doe", this.country);
for (PurchasedBook purchasedBook : purchasedBooks) {
invoice.addPurchasedBook(purchasedBook);
}
return invoice;
}
}

0 comments on commit bb3391f

Please sign in to comment.