You can use the any()
method from the ArgumentMatchers
class like this:
Class under test:
import java.util.List;
import java.util.function.Function;
public class TestedClass {
public void method(String a, Long b, Function<Long, List<String>> someFunc) {
// ...
}
}
Test:
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
class TestedClassTest {
@Test
void test() {
TestedClass testedClass = Mockito.mock(TestedClass.class);
Mockito.doNothing().when(testedClass).method(anyString(), anyLong(), any()); // use any() without parameters and let the compiler find the generic parameters for you
testedClass.method("string", 42L, null);
}
}
This answer explains the usage and how it works quite well.