-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add InvoiceTestDataBuilder for creating test data for Invoice class
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
java/src/test/java/com/murex/tbw/purchase/InvoiceTestDataBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |