PerReceiverActorSynchronizationReceiverCreator 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 item of actor synchronization receiver is not a receiver.", e); } try { IMessageReceiver synchronizedReceiver = IOC.resolve(Keys.getOrAdd("create actor synchronization receiver"), receiverItem); getListener().acceptItem(itemId, synchronizedReceiver); } catch (ResolutionException e) { throw new ReceiverObjectListenerException(e); } } PerReceiverActorSynchronizationReceiverCreator(IReceiverObjectCreator underlyingObjectCreator, IObject filterConfig, IObject objectConfig); @Override void acceptItem(Object itemId, Object item);  }
@Test public void Should_createActorDecoratorsForAllReceivers() throws Exception { IReceiverObjectCreator creator = new PerReceiverActorSynchronizationReceiverCreator(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("id1", receiverMocks[0]); listenerCaptor.getValue().acceptItem("id2", receiverMocks[2]); verify(listenerMock).acceptItem(eq("id1"), same(receiverMocks[1])); verify(listenerMock).acceptItem(eq("id2"), same(receiverMocks[3])); reset(listenerMock); listenerCaptor.getValue().endItems(); verify(listenerMock).endItems(); }
@Test(expected = InvalidReceiverPipelineException.class) public void Should_throwWhenItemIsNotAReceiver() throws Exception { IReceiverObjectCreator creator = new PerReceiverActorSynchronizationReceiverCreator(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("idx", new Object()); }
@Test(expected = InvalidArgumentException.class) public void Should_throwWhenItemIsNull() throws Exception { IReceiverObjectCreator creator = new PerReceiverActorSynchronizationReceiverCreator(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("idx", null); }
@Test(expected = ReceiverObjectListenerException.class) public void Should_throwWhenActorReceiverCreationStrategyThrows() throws Exception { when(actorReceiverResolutionStrategy.resolve(same(receiverMocks[0]))).thenThrow(ResolveDependencyStrategyException.class); IReceiverObjectCreator creator = new PerReceiverActorSynchronizationReceiverCreator(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("idx", receiverMocks[0]); }