What is the best way to mock a static method using Mockito?
I’ve written a factory to produce java.sql.Connection
objects:
public class MySQLDatabaseConnectionFactory implements DatabaseConnectionFactory {
@Override
public Connection getConnection() {
try {
return DriverManager.getConnection(...);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
I want to validate the parameters passed to DriverManager.getConnection
, but since it’s a static method, I don’t know how to mock it. I’m using JUnit 4 and mockito mock static method for testing. What is the best approach for this use case?