Proper arguments

Report a typo

Imagine that you have to test this class:

public class Calculator {
    private CalculatorEngine engine;

    public Calculator(CalculatorEngine engine) {
        this.engine = engine;
    }

    public int sum(int a, int b) {
        return engine.calculate(a, b, "+");
    }
}

This is the corresponding unit test:

class CalculatorTest {
    private CalculatorEngine engine = mock(CalculatorEngine.class);
    private Calculator calculator = new Calculator(engine);

    @Test
    void test() {
        when(engine.calculate(eq(2), 3, anyString())).thenReturn(5);

        int result = calculator.sum(2, 3);

        assertEquals(5, result);
    }
}

What will happen if you run it?

Select one option from the list
___

Create a free account to access the full topic