Testing tooling

Mockito mock

Creates a test double for the given type. Framework or debugger behavior source-reviewed; actual tool execution NOT RUN.

Formal Syntax & Structure

java syntaxjava
mock(Catalog.class)

Working Example

Example Snippetjava
package example.books;
import org.junit.jupiter.api.Test;import static org.junit.jupiter.api.Assertions.*;import static org.mockito.Mockito.*;
class CheckoutTest {    @Test    void pricesFromCatalog() {        Catalog catalog = mock(Catalog.class);        when(catalog.price("B1")).thenReturn(17);        assertEquals(34, new Checkout(catalog).total("B1", 2));    }
    @Test    void rejectsBeforeCatalogAccess() {        Catalog catalog = mock(Catalog.class);        assertThrows(IllegalArgumentException.class,                () -> new Checkout(catalog).total("B1", -1));        verify(catalog, never()).price("B1");    }}
Java Reference