HandlerRoutingReceiverCreator implements IRoutedObjectCreator { @Override public void createObject(final IRouter router, final IObject description) throws ObjectCreationException, InvalidArgumentException { try { Map<Object, IMessageReceiver> handlerReceiversMap = new HashMap<>(); IWrapperGenerator wg = IOC.resolve(Keys.getOrAdd(IWrapperGenerator.class.getCanonicalName())); IReceiverGenerator rg = IOC.resolve(Keys.getOrAdd(IReceiverGenerator.class.getCanonicalName())); Object object = IOC.resolve( Keys.getOrAdd((String) description.getValue(this.dependency)), description ); List<Method> methods = new LinkedList<>(Arrays.asList(object.getClass().getDeclaredMethods())); methods.removeIf(m -> m.isSynthetic() || !Modifier.isPublic(m.getModifiers())); for (Method m : methods) { Class wrapperInterface = m.getParameterTypes()[0]; Object wrapper = wg.generate(wrapperInterface); IResolveDependencyStrategy strategy = new ApplyFunctionToArgumentsStrategy( (arg) -> { try { return wrapper.getClass().newInstance(); } catch (Throwable e) { throw new RuntimeException( "Could not create instance of " + wrapper.getClass().getCanonicalName() + "." , e ); } } ); IMessageReceiver handlerReceiver = rg.generate(object, strategy, m.getName()); handlerReceiversMap.put(m.getName(), handlerReceiver); } IMessageReceiver handlerRoutingReceiver = new HandlerRoutingReceiver(handlerReceiversMap); router.register(description.getValue(this.name), handlerRoutingReceiver); } catch (Throwable e) { throw new ObjectCreationException("Could not create receiver chain.", e); } } HandlerRoutingReceiverCreator(); @Override void createObject(final IRouter router, final IObject description);  }
@Test (expected = ObjectCreationException.class) public void checkMethodExceptionOnWrongArgs() throws Exception { IOC.register( IOC.resolve(IOC.getKeyForKeyStorage(), "info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), new ResolveByNameIocStrategy( (a) -> { try { return new FieldName((String) a[0]); } catch (Throwable e) { throw new RuntimeException("Could not create new instance of FieldName", e); } } ) ); HandlerRoutingReceiverCreator hrrc = new HandlerRoutingReceiverCreator(); hrrc.createObject(null, null); fail(); }