MethodInvokerReceiverResolutionStrategy implements IResolveDependencyStrategy { @Override public <T> T resolve(final Object... args) throws ResolveDependencyStrategyException { Object targetObject = args[0]; Method method = (Method) args[1]; IObject invokerConfig = (IObject) args[2]; if (method.getParameterCount() != 1) { throw new ResolveDependencyStrategyException( String.format("Unexpected amount of arguments in method %s of class %s.", method.getName(), method.getDeclaringClass().getCanonicalName())); } try { Object wrapperResolutionStrategyDependency = invokerConfig.getValue(wrapperResolutionStrategyDependencyFieldName); if (null == wrapperResolutionStrategyDependency) { wrapperResolutionStrategyDependency = "default wrapper resolution strategy dependency for invoker receiver"; } IResolveDependencyStrategy wrapperResolutionStrategy = IOC.resolve( IOC.resolve(IOC.getKeyForKeyStorage(), wrapperResolutionStrategyDependency), method.getParameterTypes()[0] ); return (T) receiverGenerator.generate(targetObject, wrapperResolutionStrategy, method.getName()); } catch (ReadValueException | InvalidArgumentException | ResolutionException | ReceiverGeneratorException e) { throw new ResolveDependencyStrategyException(e); } } MethodInvokerReceiverResolutionStrategy(); @Override T resolve(final Object... args);  }
@Test(expected = ResolveDependencyStrategyException.class) public void Should_throwWhenMethodHasTooMuchArguments() throws Exception { strategy.resolve( object, object.getClass().getMethod("method2", Object.class, Object.class), configMock ); }
@Test public void Should_generateReceiverWithDefaultWrapperStrategy() throws Exception { assertSame(receiverMock1, strategy.resolve( object, object.getClass().getMethod("method1", Object.class), configMock )); }
@Test public void Should_generateReceiverWithSpecificWrapperStrategy() throws Exception { when(configMock.getValue(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "wrapperResolutionStrategyDependency"))) .thenReturn("special wrapper resolution strategy dependency for invoker receiver"); assertSame(receiverMock2, strategy.resolve( object, object.getClass().getMethod("method1", Object.class), configMock )); }