@Test
  public void onMachineShouldBeDestroyed() {
    when(terminalFactory.create(machineState)).thenReturn(terminal);

    container.addOrShowTerminal(machineState);

    verify(terminalFactory).create(machineState);
    reset(terminalFactory);

    when(terminalFactory.create(machineState)).thenReturn(terminal);

    container.onMachineDestroyed(machineStateEvent);

    container.addOrShowTerminal(machineState);

    verify(terminalFactory).create(machineState);
  }
  @Test
  public void terminalShouldBeAdded() {
    when(terminalFactory.create(machineState)).thenReturn(terminal);

    container.addOrShowTerminal(machineState);

    verify(terminalFactory).create(machineState);
    verify(view).addTerminal(terminal);

    verify(terminal, never()).connect();
    verify(view, never()).showTerminal(terminal);
  }
  @Test
  public void shouldShowStopProcessButtonAtAddingTerminal() throws Exception {
    MachineDto machineDto = mock(MachineDto.class);
    MachineConfigDto machineConfigDto = mock(MachineConfigDto.class);
    when(machineDto.getConfig()).thenReturn(machineConfigDto);
    when(machineConfigDto.isDev()).thenReturn(true);
    when(machineDto.getStatus()).thenReturn(MachineStatus.RUNNING);

    ProcessTreeNode machineNode = mock(ProcessTreeNode.class);
    when(machineNode.getId()).thenReturn(MACHINE_ID);
    List<ProcessTreeNode> children = new ArrayList<>();
    children.add(machineNode);
    presenter.rootNode = new ProcessTreeNode(ROOT_NODE, null, null, null, children);

    Machine machine = mock(Machine.class);
    when(entityFactory.createMachine(anyObject())).thenReturn(machine);
    TerminalPresenter terminal = mock(TerminalPresenter.class);
    when(terminalFactory.create(machine)).thenReturn(terminal);
    IsWidget terminalWidget = mock(IsWidget.class);
    when(terminal.getView()).thenReturn(terminalWidget);

    presenter.addCommandOutput(MACHINE_ID, outputConsole);
    presenter.onAddTerminal(MACHINE_ID);

    verify(machinePromise).then(machineCaptor.capture());
    machineCaptor.getValue().apply(machineDto);

    verify(entityFactory).createMachine(anyObject());
    verify(terminalFactory).create(eq(machine));
    verify(terminal).getView();
    verify(view, times(2)).setProcessesData(anyObject());
    verify(view, times(2)).selectNode(anyObject());
    verify(view).addProcessWidget(anyString(), eq(terminalWidget));
    verify(view, times(2)).addProcessNode(anyObject());
    verify(terminal).setVisible(eq(true));
    verify(terminal).connect();
    verify(terminal).setListener(anyObject());
    verify(view).setProcessRunning(anyString(), eq(true));
  }