Created
May 10, 2017 15:09
-
-
Save mauricioaniche/e0591d9f89cc55db8cdc40a88e05056f to your computer and use it in GitHub Desktop.
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
package nl.tudelft.mocks; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Queue; | |
public class InvoiceFilter { | |
private InvoiceDao invoiceDao; | |
public InvoiceFilter(InvoiceDao invoiceDao) { | |
this.invoiceDao = invoiceDao; | |
} | |
public List<Invoice> filter() { | |
List<Invoice> filtered = new ArrayList<>(); | |
List<Invoice> allInvoices = invoiceDao.all(); | |
for(Invoice inv : allInvoices) { | |
if(inv.getValue() < 100.0) | |
filtered.add(inv); | |
} | |
return filtered; | |
} | |
} |
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
package nl.tudelft.mocks; | |
import static org.assertj.core.api.Assertions.assertThat; | |
import static org.mockito.Mockito.mock; | |
import static org.mockito.Mockito.when; | |
import org.junit.jupiter.api.Test; | |
import org.mockito.Mockito; | |
import java.util.Arrays; | |
import java.util.List; | |
public class InvoiceFilterTest { | |
@Test | |
void filterInvoices() { | |
InvoiceDao dao = mock(InvoiceDao.class); | |
Invoice mauricio = new Invoice("Mauricio", 20.0); | |
Invoice arie = new Invoice("Arie", 300.0); | |
List<Invoice> fakeInvoices = Arrays.asList(mauricio, arie); | |
when(dao.all()).thenReturn(fakeInvoices); | |
InvoiceFilter filter = new InvoiceFilter(dao); | |
List<Invoice> result = filter.filter(); | |
assertThat(result).containsExactly(mauricio); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment