Mocking static methods with Mockito

后端 未结 15 1147
Happy的楠姐
Happy的楠姐 2020-11-21 06:51

I\'ve written a factory to produce java.sql.Connection objects:

public class MySQLDatabaseConnectionFactory implements DatabaseConnectionFactory         


        
15条回答
  •  我寻月下人不归
    2020-11-21 07:32

    I also wrote a combination of Mockito and AspectJ: https://github.com/iirekm/varia/tree/develop/ajmock

    Your example becomes:

    when(() -> DriverManager.getConnection(...)).thenReturn(...);
    

提交回复
热议问题