The document discusses testing the graphical user interface (GUI) of an application. It covers presenting code, GUI testing concepts like the passive view pattern, and using mocks. Mocks are classes that simulate real objects and are used to test GUI logic without dependencies on other layers of the application. Manual mocks can be created by implementing interfaces, while Mockito provides a mocking framework to simplify mock creation and verification.
13. R?CZNIE UTWORZONY MOCK
@Test
public void orderShouldBeFilled() {
Order order = new Order(POTATOES, 50);
WarehouseMock warehouse = new WarehouseMock();
order.fill(warehouse);
warehouse.verifyRemoved(POTATOES, 50);
}
public interface Warehouse {
void remove(String product, int quantity);
}
14. R?CZNIE UTWORZONY MOCK
public class WarehouseMock implements Warehouse {
private String productFromCall;
private int quantityFromCall;
@Override
public void remove(String product, int quantity) {
this.productFromCall = product;
this.quantityFromCall = quantity;
}
public void verifyRemoved(String product, int quantity)
{
assertEquals(productFromCall, product);
assertEquals(quantityFromCall, quantity);
}
}
15. MOCKITO
@Test
public void orderShouldBeFilled() {
Order order = new Order(POTATOES, 50);
WarehouseMock warehouse = mock(Warehouse.class);
order.fill(warehouse);
verify(warehouse).remove(POTATOES, 50);
}