Created
May 19, 2015 02:20
-
-
Save mauricioaniche/8ff35c2795a0d2e0122e to your computer and use it in GitHub Desktop.
TDD For Professionals - Mocks
This file contains hidden or 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
package module2.exercise.mocks; | |
import java.util.Calendar; | |
public class Invoice { | |
private Calendar date; | |
private String customer; | |
private double amount; | |
public Invoice(Calendar date, String customer, double amount) { | |
this.date = date; | |
this.customer = customer; | |
this.amount = amount; | |
} | |
public Calendar getDate() { | |
return date; | |
} | |
public String getCustomer() { | |
return customer; | |
} | |
public double getAmount() { | |
return amount; | |
} | |
} |
This file contains hidden or 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
package module2.exercise.mocks; | |
import java.util.ArrayList; | |
import java.util.Calendar; | |
import java.util.List; | |
public class InvoiceFilter { | |
private final InvoiceRepository invoices; | |
public InvoiceFilter(InvoiceRepository invoiced) { | |
this.invoices = invoiced; | |
} | |
public List<Invoice> filter() { | |
List<Invoice> filtered = new ArrayList<Invoice>(); | |
for(Invoice invoice : invoices.all()) { | |
if (invoice.getAmount() > 2000) filtered.add(invoice); | |
else if (invoice.getAmount() < 2000 && invoice.getCustomer().equals("MICROSOFT")) filtered.add(invoice); | |
else if (invoice.getDate().get(Calendar.YEAR) < 1999) filtered.add(invoice); | |
} | |
return filtered; | |
} | |
} |
This file contains hidden or 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
package module2.exercise.mocks; | |
import java.util.List; | |
public interface InvoiceRepository { | |
List<Invoice> all(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for the code for better explanation..