0 votes
1 view
in Java by (2.6k points)

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'd like to validate the parameters passed to DriverManager.getConnection, but I don't know how to mock a static method. I'm using JUnit 4 and Mockito for my test cases. Is there a good way to mock/verify this specific use-case?

1 Answer

0 votes
by (46.1k points)

Try PowerMockito on head of Mockito.

Example code:



public class Mocker {


public void shouldVerifyParameters() throws Exception {





sut.execute(); // System Under Test (sut)





Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !