ReceiverGenerator implements IReceiverGenerator { @Override public IMessageReceiver generate( final Object objInstance, final IResolveDependencyStrategy wrapperResolutionStrategy, final String methodName ) throws InvalidArgumentException, ReceiverGeneratorException { if ( null == objInstance || null == methodName || methodName.isEmpty() || null == wrapperResolutionStrategy ) { throw new InvalidArgumentException("One of the arguments null or empty."); } try { Class<IMessageReceiver> clazz = generateClass( objInstance, methodName ); return clazz.getConstructor( new Class[]{objInstance.getClass(), IResolveDependencyStrategy.class} ) .newInstance(new Object[]{objInstance, wrapperResolutionStrategy}); } catch (Throwable e) { throw new ReceiverGeneratorException( "Could not generate message receiver because of the following error:", e ); } } ReceiverGenerator(final ClassLoader classLoader); @Override IMessageReceiver generate(
            final Object objInstance,
            final IResolveDependencyStrategy wrapperResolutionStrategy,
            final String methodName
    );  }
@Test public void checkCreation() throws Exception { CustomActor a = new CustomActor(); CustomWrapper w = new CustomWrapper(); w.setGetterUsed(false); w.setSetterUsed(false); IResolveDependencyStrategy returnCustomActorStrategy = mock(IResolveDependencyStrategy.class); IResolveDependencyStrategy returnWrapperStrategy = mock(IResolveDependencyStrategy.class); IOC.register(Keys.getOrAdd("actorID"), returnCustomActorStrategy); IOC.register(Keys.getOrAdd(ICustomWrapper.class.getCanonicalName()), returnWrapperStrategy); when(returnCustomActorStrategy.resolve()).thenReturn(a); when(returnWrapperStrategy.resolve()).thenReturn(w); IObject configs = mock(IObject.class); IObject env = mock(IObject.class); IObject wrapperConfig = mock(IObject.class); when(env.getValue(new FieldName("int"))).thenReturn(1); doNothing().when(env).setValue(new FieldName("int"), 2); IMessageProcessor processor = mock(IMessageProcessor.class); when(processor.getEnvironment()).thenReturn(w); IReceiverGenerator rg = new ReceiverGenerator(null); assertNotNull(rg); IResolveDependencyStrategy strategy = mock(IResolveDependencyStrategy.class); when(strategy.resolve()).thenReturn(w); IMessageReceiver r = rg.generate(a, strategy, "doSomeWork"); assertNotNull(r); r.receive(processor); assertTrue(w.getGetterUsed()); assertTrue(w.getSetterUsed()); }
@Test(expected = InvalidArgumentException.class) public void checkInvalidArgumentExceptionOnNullParameter() throws Exception { IReceiverGenerator rg = new ReceiverGenerator(null); rg.generate(null, null, null); fail(); }
@Test(expected = ReceiverGeneratorException.class) public void checkReceiverGeneratorExceptionOn() throws Exception { CustomActor a = new CustomActor(); IResolveDependencyStrategy strategy = mock(IResolveDependencyStrategy.class); IReceiverGenerator rg = new ReceiverGenerator(null); rg.generate(a, strategy, "a"); fail(); }