SystemCommander implements SystemCommanderMBean { @Override public SystemCommandStatus getCommandStatus(final UUID commandId) { return systemCommandStateBean .getCommandStatus(commandId) .orElseThrow(() -> new CommandNotFoundException(format("No SystemCommand found with id %s", commandId))); }  @Override UUID call(final String systemCommandName); @Override List<SystemCommandDetails> listCommands(); @Override SystemCommandStatus getCommandStatus(final UUID commandId);  }
@Test public void shouldGetSystemCommandStatus() throws Exception { final UUID commandId = randomUUID(); final SystemCommandStatus systemCommandStatus = mock(SystemCommandStatus.class); when(systemCommandStateBean.getCommandStatus(commandId)).thenReturn(of(systemCommandStatus)); assertThat(systemCommander.getCommandStatus(commandId), is(systemCommandStatus)); }
@Test public void shouldThrowExceptionIfSystemCommandNotFound() throws Exception { final UUID commandId = fromString("08fe90e9-c35b-4850-9af2-e5e743f6736e"); when(systemCommandStateBean.getCommandStatus(commandId)).thenReturn(empty()); try { systemCommander.getCommandStatus(commandId); fail(); } catch (CommandNotFoundException expected) { assertThat(expected.getMessage(), is("No SystemCommand found with id 08fe90e9-c35b-4850-9af2-e5e743f6736e")); } }