Mockito.doNothing()仍在运行

时间:2015-11-30 16:04:11

标签: testing gwt mockito

我正在尝试测试一小段代码。我不想测试方法之一并使用Mockito.doNothing(),但这个方法仍在运行。我怎么能这样做?

 protected EncoderClientCommandEventHandler clientCommandEventHandlerProcessStop = new EncoderClientCommand.EncoderClientCommandEventHandler() {
    @Override
    public void onCommandPerformed(
        EncoderClientCommand clientCommand) {
      setWatcherActivated(false);
      buttonsBackToNormal();
    }
  };

  protected void processStop() {
    EncoderServerCommand serverCommand = new EncoderServerCommand();
    serverCommand.setAction(EncoderAction.STOP);

    checkAndSetExtension();
    serverCommand.setKey(getArchiveJobKey());
    getCommandFacade().performCommand(
        serverCommand,
        EncoderClientCommand.getType(),
        clientCommandEventHandlerProcessStop);
  }

  @Test
  public void testClientCommandEventHandlerProcessStop() {
    EncoderClientCommand encoderClientCommand = mock(EncoderClientCommand.class);

    Mockito.doNothing().when(encoderCompositeSpy).buttonsBackToNormal();

    when(encoderCompositeSpy.isWatcherActivated()).thenReturn(false);
    encoderCompositeSpy.clientCommandEventHandlerProcessStop.onCommandPerformed(encoderClientCommand);

1 个答案:

答案 0 :(得分:0)

我发现了这个问题。其中一个变量已经在buttonsBackNormal()中被模拟。