@Test
  public void machineShouldBeAddedToTreeWhenItIsJustCreated() {
    MachineStartingEvent startingEvent = mock(MachineStartingEvent.class);

    when(startingEvent.getMachineState()).thenReturn(machineState1);

    presenter.onMachineStarting(startingEvent);

    verify(view).setData(rootNode);
    verify(view).selectNode(machineNode1);

    assertThat(presenter.isMachineRunning(), is(false));
  }
  @Test
  public void requestShouldBeSendToGetMachine() throws Exception {
    presenter.onMachineSelected(machineState1);

    verify(machineState1).getId();

    verify(machinePromise).then(operationMachineCaptor.capture());
    operationMachineCaptor.getValue().apply(machineDescriptor1);

    verify(entityFactory).createMachine(machineDescriptor1);
    verify(appliance).showAppliance(machine1);

    assertThat(machineState1, is(equalTo(presenter.getSelectedMachineState())));
    assertThat(presenter.isMachineRunning(), is(true));
  }
  @Test
  public void machineShouldBeSelectedWhenItIsRunning() {
    MachineStartingEvent startingEvent = mock(MachineStartingEvent.class);

    when(startingEvent.getMachineState()).thenReturn(machineState1);
    when(stateEvent.getMachineState()).thenReturn(machineState1);

    presenter.onMachineStarting(startingEvent);
    reset(view);

    presenter.onMachineRunning(stateEvent);

    verify(view).selectNode(machineNode1);

    assertThat(presenter.isMachineRunning(), is(true));
  }
  @Test
  public void stubShouldBeDisplayedWhenWeTryGetMachineWhichIsNotCreatedYet() throws Exception {
    PromiseError error = mock(PromiseError.class);

    presenter.onMachineSelected(machineState1);

    verify(machinePromise).catchError(errorPromiseCaptor.capture());
    errorPromiseCaptor.getValue().apply(error);

    verify(machineState1).getName();
    verify(locale).unavailableMachineStarting(anyString());
    verify(appliance).showStub(anyString());

    assertThat(presenter.isMachineRunning(), is(false));
    assertThat(machineState1, is(equalTo(presenter.getSelectedMachineState())));
  }
  @Test
  public void machineShouldBeGotFromCacheWhenWeSelectMachineTheSecondTime() throws Exception {
    presenter.onMachineSelected(machineState1);

    verify(machinePromise).then(operationMachineCaptor.capture());
    operationMachineCaptor.getValue().apply(machineDescriptor1);
    reset(service, appliance);

    presenter.onMachineSelected(machineState1);

    verify(appliance).showAppliance(machine1);

    verify(service, never()).getMachine(anyString());

    assertThat(machineState1, is(equalTo(presenter.getSelectedMachineState())));
    assertThat(presenter.isMachineRunning(), is(true));
  }