I'm trying to unit test code that runs as callback in a Consumer functional interface.
@Component
class SomeClass {
@Autowired
private SomeInteface toBeMockedDependency;
public method() {
toBeMockedDependency.doSomething(message -> {
// Logic under test goes here
// (implements java.util.function.Consumer interface)
...
});
}
}
@RunWith(MockitoJUnitRunner.class)
public class SomeClassTest {
@InjectMocks
private SomeClass someClass;
@Mock
private SomeInteface toBeMockedDependency;
@Test
public void testMethod() {
...
someClass.method();
...
}
}
Essentially I want to provide the tested code some tested "message" via "toBeMockedDependency".
How can the "toBeMockedDependency" be mocked to provide a predefined message?
Is it the right approach?