TopLevelObjectCreator implements IReceiverObjectCreator { @Override public void create(IReceiverObjectListener listener, IObject config, IObject context) throws ReceiverObjectListenerException, InvalidReceiverPipelineException, ReceiverObjectCreatorException { try { Object object = IOC.resolve( IOC.resolve(IOC.getKeyForKeyStorage(), config.getValue(dependencyFieldName)), config ); context.setValue(topLevelObjectFieldName, object); listener.acceptItem(null, object); listener.endItems(); } catch (InvalidArgumentException | ReadValueException | ChangeValueException | ResolutionException e) { throw new ReceiverObjectCreatorException(e); } } TopLevelObjectCreator(); @Override void create(IReceiverObjectListener listener, IObject config, IObject context); @Override Collection<Object> enumIdentifiers(IObject config, IObject context);  }
@Test public void Should_resolveObjectNotifyListenerAndStoreItInContext() throws Exception { IReceiverObjectCreator creator = new TopLevelObjectCreator(); creator.create(listenerMock, configMock, contextMock); verify(objectResolutionStrategy, times(1)).resolve(any()); verify(listenerMock).acceptItem(isNull(), same(object)); verify(listenerMock).endItems(); verify(contextMock).setValue(eq(IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), "topLevelObject")), same(object)); }
@Test(expected = ReceiverObjectCreatorException.class) public void Should_wrapExceptionWhenErrorOccursResolvingObject() throws Exception { IReceiverObjectCreator creator = new TopLevelObjectCreator(); when(objectResolutionStrategy.resolve(any())).thenThrow(ResolveDependencyStrategyException.class); creator.create(listenerMock, configMock, contextMock); }