DebuggerActor { public void executeCommand(final CommandMessage message) throws ReadValueException, ChangeValueException, InvalidArgumentException, SessionNotFoundException { debuggerAddress = message.getDebuggerAddress(); String command = message.getCommand(); try { if (globalCommands.containsKey(command)) { Object args = message.getCommandArguments(); if (null == args) { args = message.getSessionId(); } message.setCommandResult(globalCommands.get(command).execute(args)); } else { String sessionId = message.getSessionId(); Object args = message.getCommandArguments(); message.setCommandResult(getSession(sessionId).executeCommand(command, args)); } } catch (CommandExecutionException e) { message.setException(e); } }  void executeCommand(final CommandMessage message); void interrupt(final DebuggableMessage message);  }
@Test public void Should_executeSessionCommands() throws Exception { Object args = new Object(); Object result = new Object(); when(session[0].executeCommand(eq("theCommand"), same(args))).thenReturn(result); DebuggerActor actor = new DebuggerActor(); String id = doCreateSession(actor, session[0]); reset(commandMessageMock); when(commandMessageMock.getDebuggerAddress()).thenReturn(debuggerAddress); when(commandMessageMock.getCommandArguments()).thenReturn(args); when(commandMessageMock.getCommand()).thenReturn("theCommand"); when(commandMessageMock.getSessionId()).thenReturn(id); actor.executeCommand(commandMessageMock); verify(commandMessageMock).setCommandResult(same(result)); }
@Test public void Should_throwWhenSessionIsNotPresent() throws Exception { DebuggerActor actor = new DebuggerActor(); when(commandMessageMock.getCommand()).thenReturn("closeSession"); when(commandMessageMock.getCommandArguments()).thenReturn("non-exist"); actor.executeCommand(commandMessageMock); verify(commandMessageMock).setException(any()); }
@Test public void Should_throwWhenCannotResolveSession() throws Exception { DebuggerActor actor = new DebuggerActor(); when(sessionStrategyMock.resolve(any(), any(), any())).thenThrow(ResolveDependencyStrategyException.class); when(commandMessageMock.getCommand()).thenReturn("newSession"); actor.executeCommand(commandMessageMock); verify(commandMessageMock).setException(any()); }