### Question:
BasicRosMessageRouterActivityComponent extends BaseRosMessageRouterActivityComponent<T> { void handleNewIncomingMessage(String channelId, T message) { if (!getComponentContext().canHandlerRun()) { return; } try { getComponentContext().enterHandler(); TimeProvider timeProvider = getComponentContext().getActivity().getSpaceEnvironment().getTimeProvider(); long start = timeProvider.getCurrentTime(); String handlerInvocationId = newHandlerInvocationId(); Log log = getComponentContext().getActivity().getLog(); if (log.isTraceEnabled()) { log.trace(String.format("Entering ROS route message handler invocation %s", handlerInvocationId)); } messageListener.onNewRoutableInputMessage(channelId, message); if (log.isTraceEnabled()) { log.trace(String.format("Exiting ROS route message handler invocation %s after %dms", handlerInvocationId, timeProvider.getCurrentTime() - start)); } } catch (Throwable e) { handleError(String.format("Error after receiving routing message for channel %s", channelId), e); } finally { getComponentContext().exitHandler(); } } BasicRosMessageRouterActivityComponent(String rosMessageType,
      RoutableInputMessageListener<T> messageListener); @Override String getName(); @Override String getDescription(); @Override List<String> getBaseDependencies(); @Override void onPostStartupComponent(); @Override void shutdownComponent(); @Override boolean isComponentRunning(); @Override String getNodeName(); @Override T newMessage(); @Override synchronized RouteMessagePublisher<T> registerOutputChannelTopic(String channelId, Set<String> topicNames,
      boolean latch); @Override synchronized void registerInputChannelTopic(final String channelId, Set<String> topicNames); @Override synchronized void clearAllChannelTopics(); @Override void writeOutputMessage(String outputChannelId, T message); @Override String getComponentStatusDetail(); @Override Set<String> getOutputChannelIds(); @Override RouteMessagePublisher<T> getMessagePublisher(String outputChannelId); @Override Set<String> getInputChannelIds();  }### Answer:
@Test public void testHandlerSuccess() { configuration.setValue("space.activity.routes.inputs", "foo"); configuration.setValue("space.activity.route.input.foo", "bar"); component.setComponentContext(activityComponentContext); component.configureComponent(configuration); Mockito.when(activityComponentContext.canHandlerRun()).thenReturn(true); String channelName = "foo"; String message = "bar"; component.handleNewIncomingMessage(channelName, message); Mockito.verify(messageListener).onNewRoutableInputMessage(channelName, message); activityComponentContextInOrder.verify(activityComponentContext).enterHandler(); activityComponentContextInOrder.verify(activityComponentContext).exitHandler(); }
@Test public void testHandlerFailure() { configuration.setValue("space.activity.routes.inputs", "foo"); configuration.setValue("space.activity.route.input.foo", "bar"); component.setComponentContext(activityComponentContext); component.configureComponent(configuration); Mockito.when(activityComponentContext.canHandlerRun()).thenReturn(true); String channelName = "foo"; String message = "bar"; Exception e = new RuntimeException(); Mockito.doThrow(e).when(messageListener).onNewRoutableInputMessage(channelName, message); component.handleNewIncomingMessage(channelName, message); Mockito.verify(messageListener).onNewRoutableInputMessage(channelName, message); activityComponentContextInOrder.verify(activityComponentContext).enterHandler(); activityComponentContextInOrder.verify(activityComponentContext).exitHandler(); Mockito.verify(log, Mockito.times(1)).error(Mockito.anyString(), Mockito.eq(e)); }
@Test public void testHandlerNoRun() { configuration.setValue("space.activity.routes.inputs", "foo"); configuration.setValue("space.activity.route.input.foo", "bar"); component.setComponentContext(activityComponentContext); component.configureComponent(configuration); Mockito.when(activityComponentContext.canHandlerRun()).thenReturn(false); String channelName = "foo"; String message = "bar"; component.handleNewIncomingMessage(channelName, message); Mockito.verify(messageListener, Mockito.never()) .onNewRoutableInputMessage(channelName, message); Mockito.verify(activityComponentContext, Mockito.never()).enterHandler(); Mockito.verify(activityComponentContext, Mockito.never()).exitHandler(); }