RouterRegistrationObjectListener implements IReceiverObjectListener { @Override public void acceptItem(Object itemId, Object item) throws ReceiverObjectListenerException, InvalidReceiverPipelineException, InvalidArgumentException { if (null == item) { throw new InvalidArgumentException("Item is null."); } if (null == itemId) { throw new InvalidReceiverPipelineException( "Item identifier is null. The filter defining object address is missing or does not work correct."); } IMessageReceiver receiver; try { receiver = (IMessageReceiver) item; } catch (ClassCastException e) { throw new InvalidReceiverPipelineException( "Item is not a message receiver."); } try { IRouter router = IOC.resolve(Keys.getOrAdd(IRouter.class.getCanonicalName())); router.register(itemId, receiver); } catch (ResolutionException e) { throw new ReceiverObjectListenerException(e); } }  @Override void acceptItem(Object itemId, Object item); @Override void endItems();  }
@Test(expected = InvalidArgumentException.class) public void Should_throwWhenItemIsNull() throws Exception { new RouterRegistrationObjectListener().acceptItem("idx", null); }
@Test(expected = InvalidReceiverPipelineException.class) public void Should_throwWhenItemIdentifierIsUndefined() throws Exception { new RouterRegistrationObjectListener().acceptItem(null, receiverMocks[0]); }
@Test(expected = InvalidReceiverPipelineException.class) public void Should_throwWhenItemIsNotAReceiver() throws Exception { new RouterRegistrationObjectListener().acceptItem("idx", new Object()); }
@Test(expected = ReceiverObjectListenerException.class) public void Should_throwWhenRouterResolutionFails() throws Exception { when(routerStrategy.resolve()).thenThrow(ResolveDependencyStrategyException.class); new RouterRegistrationObjectListener().acceptItem("idx", receiverMocks[0]); }