从 Jmockit 转换为 Mockito
我正在尝试将方法从 Jmockit 转换为 mockito 框架,但无法执行它。 添加了相关依赖项和 @RunWith(MockitoJUnitRunner.class),适用于同一类中的其他方法。
public class MavenUtilTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Mock
private KitLogger log;
@Mock
MavenProject mavenProject;
@Mock
BuildPluginManager pluginManager;
@Test
//Jmockit
public void testCallMavenPluginWithGoal(@Mocked BuildPluginManager pluginManager) throws PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
// Given
MavenProject mavenProject = getMavenProject();
MavenSession mavenSession = getMavenSession();
MavenUtil.callMavenPluginWithGoal(mavenProject, mavenSession, pluginManager, "org.apache.maven.plugins:maven-help-plugin:help", log);
// Then
new Verifications() {{
pluginManager.executeMojo(mavenSession, (MojoExecution)any);
times = 1;
}};
}
}
//mockito
@Test
public void testCallMavenPluginWithGoal() throws PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
// Given
MavenProject mavenProject = getMavenProject();
MavenSession mavenSession = getMavenSession();
// When
MavenUtil.callMavenPluginWithGoal(mavenProject, mavenSession, pluginManager, "org.apache.maven.plugins:maven-help-plugin:help", log);
// Then
verify(pluginManager,Mockito.times(1)).executeMojo(mavenSession,any(MojoExecution.class));
}
I'm trying to convert a method from Jmockit to mockito framework, not able to execute it.
Added relevant dependencies and @RunWith(MockitoJUnitRunner.class), working for other methods in the same class.
public class MavenUtilTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Mock
private KitLogger log;
@Mock
MavenProject mavenProject;
@Mock
BuildPluginManager pluginManager;
@Test
//Jmockit
public void testCallMavenPluginWithGoal(@Mocked BuildPluginManager pluginManager) throws PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
// Given
MavenProject mavenProject = getMavenProject();
MavenSession mavenSession = getMavenSession();
MavenUtil.callMavenPluginWithGoal(mavenProject, mavenSession, pluginManager, "org.apache.maven.plugins:maven-help-plugin:help", log);
// Then
new Verifications() {{
pluginManager.executeMojo(mavenSession, (MojoExecution)any);
times = 1;
}};
}
}
//mockito
@Test
public void testCallMavenPluginWithGoal() throws PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
// Given
MavenProject mavenProject = getMavenProject();
MavenSession mavenSession = getMavenSession();
// When
MavenUtil.callMavenPluginWithGoal(mavenProject, mavenSession, pluginManager, "org.apache.maven.plugins:maven-help-plugin:help", log);
// Then
verify(pluginManager,Mockito.times(1)).executeMojo(mavenSession,any(MojoExecution.class));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论