Mockito mock 静态 void 方法
MockedStatic<SpringContextUtils> utils = Mockito.mockStatic(SpringContextUtils.class);
utils.when(() ->SpringContextUtils.publishEvent(any())).thenAnswer(invocation -> null);
...
//最后需要关闭
utils.close();
maven
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.7.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>3.7.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>3.7.7</version>
<scope>test</scope>
</dependency>