PrependSensorReceiverStrategy implements IResolveDependencyStrategy { @Override public <T> T resolve(final Object... args) throws ResolveDependencyStrategyException { final IMessageReceiver originalReceiver = (IMessageReceiver) args[0]; final IMessageReceiver sensorReceiver = (IMessageReceiver) args[1]; if (originalReceiver == null) { return (T) sensorReceiver; } return (T) new CompositeSensorReceiver(sensorReceiver, originalReceiver); }  @Override T resolve(final Object... args);  }
@Test public void Should_returnSensorWhenThereWasNoOriginalReceiver() throws Exception { IMessageReceiver sr = mock(IMessageReceiver.class); assertSame(sr, new PrependSensorReceiverStrategy().resolve(null, sr)); }
@Test public void Should_returnCompositeReceiverWhenBothOriginalReceiverAndSensorReceiverArePresent() throws Exception { IMessageReceiver sr = mock(IMessageReceiver.class); IMessageReceiver or = mock(IMessageReceiver.class); IMessageReceiver cr = new PrependSensorReceiverStrategy().resolve(or, sr); IMessageProcessor mp = mock(IMessageProcessor.class); cr.receive(mp); verify(sr).receive(same(mp)); verify(or).receive(same(mp)); }