HandlerRouterReceiverCreator extends BasicIntermediateReceiverObjectCreator { @Override public void acceptItem(Object itemId, Object item) throws ReceiverObjectListenerException, InvalidReceiverPipelineException, InvalidArgumentException { if (null == item) { throw new InvalidArgumentException("Item is null."); } IMessageReceiver receiverItem; try { receiverItem = (IMessageReceiver) item; } catch (ClassCastException e) { throw new InvalidReceiverPipelineException("Underlying object is not a receiver.", e); } if (null == itemId) { throw new InvalidReceiverPipelineException("Underlying object has no identifier."); } if (null != handlersMap.put(itemId, receiverItem)) { throw new InvalidReceiverPipelineException("Duplicate underlying object identifier: " + String.valueOf(itemId)); } } HandlerRouterReceiverCreator(IReceiverObjectCreator underlyingObjectCreator, IObject filterConfig, IObject objectConfig); @Override Collection<Object> enumIdentifiers(IObject config, IObject context); @Override void acceptItem(Object itemId, Object item); @Override void endItems();  }
@Test(expected = InvalidReceiverPipelineException.class) public void Should_throwIfReceiversWithDuplicateIdentifiersPassed() throws Exception { IReceiverObjectCreator creator = new HandlerRouterReceiverCreator(creatorMock, filterConfig, objectConfig); creator.create(listenerMock, objectConfig, context); ArgumentCaptor<IReceiverObjectListener> listenerCaptor = ArgumentCaptor.forClass(IReceiverObjectListener.class); verify(creatorMock).create(listenerCaptor.capture(), same(objectConfig), same(context)); listenerCaptor.getValue().acceptItem("idz", receiverMocks[1]); listenerCaptor.getValue().acceptItem("idz", receiverMocks[2]); }
@Test(expected = InvalidReceiverPipelineException.class) public void Should_throwIfAnyOfItemsHasUndefinedIdentifier() throws Exception { IReceiverObjectCreator creator = new HandlerRouterReceiverCreator(creatorMock, filterConfig, objectConfig); creator.create(listenerMock, objectConfig, context); ArgumentCaptor<IReceiverObjectListener> listenerCaptor = ArgumentCaptor.forClass(IReceiverObjectListener.class); verify(creatorMock).create(listenerCaptor.capture(), same(objectConfig), same(context)); listenerCaptor.getValue().acceptItem(null, receiverMocks[1]); }
@Test(expected = InvalidReceiverPipelineException.class) public void Should_throwIfItemIsNotAReceiver() throws Exception { IReceiverObjectCreator creator = new HandlerRouterReceiverCreator(creatorMock, filterConfig, objectConfig); creator.create(listenerMock, objectConfig, context); ArgumentCaptor<IReceiverObjectListener> listenerCaptor = ArgumentCaptor.forClass(IReceiverObjectListener.class); verify(creatorMock).create(listenerCaptor.capture(), same(objectConfig), same(context)); listenerCaptor.getValue().acceptItem("idz", new Object()); }
@Test(expected = InvalidArgumentException.class) public void Should_throwIfItemIsNull() throws Exception { IReceiverObjectCreator creator = new HandlerRouterReceiverCreator(creatorMock, filterConfig, objectConfig); creator.create(listenerMock, objectConfig, context); ArgumentCaptor<IReceiverObjectListener> listenerCaptor = ArgumentCaptor.forClass(IReceiverObjectListener.class); verify(creatorMock).create(listenerCaptor.capture(), same(objectConfig), same(context)); listenerCaptor.getValue().acceptItem("idz", null); }