WrapperCreatorReceiverDecorator implements IMessageReceiver { @Override public void receive(final IMessageProcessor processor) throws MessageReceiveException, AsynchronousOperationException { try { IObject stepArgs = processor.getSequence().getCurrentReceiverArguments(); IObject wrapperConfigObject = (IObject) stepArgs.getValue(wrapperFieldName); if (null != wrapperConfigObject) { IResolveDependencyStrategy conf = wrapperStrategies.get(stepArgs); if (null == conf) { conf = IOC.resolve(strategyDependencyKey, wrapperConfigObject); wrapperStrategies.put(stepArgs, conf); } processor.pushEnvironment(conf.resolve(processor.getEnvironment())); } underlyingReceiver.receive(processor); } catch (ReadValueException | InvalidArgumentException | ResolutionException | ResolveDependencyStrategyException e) { throw new MessageReceiveException(e); } } WrapperCreatorReceiverDecorator(
            final IMessageReceiver underlyingReceiver,
            final Map<Object, IResolveDependencyStrategy> wrapperStrategiesMap,
            final String strategyDependencyName); @Override void receive(final IMessageProcessor processor);  }
@Test public void Should_resolveWrapperAndPushAsEnvironment() throws Exception { IMessageReceiver decorator = new WrapperCreatorReceiverDecorator( receiverMock, map, "the wrapper resolution strategy resolution strategy"); decorator.receive(messageProcessorMock); verify(messageProcessorMock, times(1)).pushEnvironment(same(wrapperMock)); verify(wrapperResolutionStrategyResolutionStrategyMock, times(1)).resolve(same(wrapperConfMock)); assertSame(wrapperResolutionStrategyMock, map.get(stepConfMock)); decorator.receive(messageProcessorMock); verify(messageProcessorMock, times(2)).pushEnvironment(same(wrapperMock)); verify(wrapperResolutionStrategyResolutionStrategyMock, times(1)).resolve(same(wrapperConfMock)); assertSame(wrapperResolutionStrategyMock, map.get(stepConfMock)); }
@Test(expected = MessageReceiveException.class) public void Should_wrapExceptions() throws Exception { IMessageReceiver decorator = new WrapperCreatorReceiverDecorator( receiverMock, map, "the wrapper resolution strategy resolution strategy"); when(wrapperResolutionStrategyResolutionStrategyMock.resolve(any())) .thenThrow(ResolveDependencyStrategyException.class); decorator.receive(messageProcessorMock); }