如何在Mockito中使用超级关键字调用方法?代码如下面的代码段所示:
@Override
protected void doExecute()
{
//only show port context menu in edit mode
ICommandContext commandContext = getCommandContext();
if( commandContext instanceof ContextMenuCommandContext )
{
ContextMenuCommandContext contextMenuContext = (ContextMenuCommandContext) commandContext;
if( !contextMenuContext.getRelationsContext().isAuthoringMode() )
{
return;
}
}
super.doExecute();
}
答案 0 :(得分:0)
请试试这个, 考虑您的派生类名称
class BaseClass {
public void doExecute() {...}
}
public ChildClass extends BaseClass {
@override
public void doExecute(){
//some codes
super.doExecute();
}
}
我认为你的代码是这样的,
@Test
public void testdoExecute() {
DerivedClassName cn= Mockito.cn(new DerivedClassName());
// Prevent/stub logic in super.doExecute();
Mockito.doNothing().when((BaseClassName)cn).doExecute();
// When
cn.doExecute();
// Then
verify(cn).load();
}