When a dependency is passed into a method as a parameter rather than injected into the class, you mock it the same way - create it with mock(), then pass the mock instance directly as the method argument.
For a method processOrder(Order order, PaymentStrategy strategy), you'd mock PaymentStrategy, stub pay() to return true, and pass it directly into processOrder() to verify the order is confirmed.
PaymentStrategy strategy = mock(PaymentStrategy.class);
when(strategy.pay(100.0)).thenReturn(true);
boolean confirmed = orderProcessor.processOrder(order, strategy);
assertTrue(confirmed);
verify(strategy).pay(100.0);A concise interview answer is
I mock the parameter type with mock(), stub its expected behavior, and pass the mock directly as the method argument, just like a real object. Afterward I can use verify() to confirm the method under test interacted with that parameter correctly.
Last updated: 16 July 2026
Previous question: How do you mock final classes and methods in Mockito? Is it possible in earlier versions of Mockito?
Next question: How do you handle method chaining (e.g., foo.bar().baz()) in Mockito?