Top "Mockito" questions

Mockito is a mocking framework for Java.

How to mock void methods with Mockito

How to mock methods with void return type? I implemented an observer pattern but I can't mock it with Mockito …

java unit-testing mocking mockito void
Mocking static methods with Mockito

I've written a factory to produce java.sql.Connection objects: public class MySQLDatabaseConnectionFactory implements DatabaseConnectionFactory { @Override public Connection getConnection() { try { …

java unit-testing static mocking mockito
Mockito : how to verify method was called on an object created within a method?

I am new to Mockito. Given the class below, how can I use Mockito to verify that someMethod was invoked …

java unit-testing junit mockito
Use Mockito to mock some methods but not others

Is there any way, using Mockito, to mock some methods in a class, but not others? For example, in this (…

java mocking mockito
Making a mocked method return an argument that was passed to it

Consider a method signature like: public String myFunction(String abc); Can Mockito help return the same string that the method …

java mockito
How to verify that a specific method was not called using Mockito?

How to verify that a method is not called on an object's dependency? For example: public interface Dependency { void someMethod(); } …

java tdd mockito
Mockito How to mock and assert a thrown exception?

I'm using mockito in a junit test. How do you make an exception happen and then assert that it has (…

java exception-handling junit mockito
How to verify a method is called two times with mockito verify()

I want to verify if a method is called at least once through mockito verify. I used verify and it …

junit mockito verify
Testing Private method using mockito

public class A { public void method(boolean b){ if (b == true) method1(); else method2(); } private void method1() {} private void method2() {} } …

java junit mockito
Using Mockito's generic "any()" method

I have an interface with a method that expects an array of Foo: public interface IBar { void doStuff(Foo[] arr); } …

java unit-testing mocking mockito