Skip to content

Instantly share code, notes, and snippets.

@mauricioaniche
Created May 19, 2015 02:20
Show Gist options
  • Save mauricioaniche/8ff35c2795a0d2e0122e to your computer and use it in GitHub Desktop.
Save mauricioaniche/8ff35c2795a0d2e0122e to your computer and use it in GitHub Desktop.
TDD For Professionals - Mocks
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;
}
}
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;
}
}
package module2.exercise.mocks;
import java.util.List;
public interface InvoiceRepository {
List<Invoice> all();
}
@LogeshV26
Copy link

Thank you for the code for better explanation..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment