ConstantsSectionStrategy implements ISectionStrategy { @Override public void onLoadConfig(final IObject config) throws ConfigurationProcessingException { try { IObject constants = IOC.resolve(Keys.getOrAdd("global constants")); List<IObject> section = (List<IObject>) config.getValue(sectionFieldName); for (IObject obj : section) { IFieldName cFName = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.ifield_name.IFieldName"), obj.getValue(constantNameFN)); Object cValue = obj.getValue(constantValueFN); constants.setValue(cFName, cValue); } } catch (ReadValueException | InvalidArgumentException | ResolutionException | ChangeValueException e) { throw new ConfigurationProcessingException(e); } } ConstantsSectionStrategy(); @Override void onLoadConfig(final IObject config); @Override IFieldName getSectionName();  }
@Test public void Should_writeConstantsToGlobalObject() throws Exception { ISectionStrategy strategy = new ConstantsSectionStrategy(); strategy.onLoadConfig(configMock); verify(globalConstantsObjectMock).setValue(const1FieldName, 1); verify(globalConstantsObjectMock).setValue(const2FieldName, "2"); }
@Test(expected = ConfigurationProcessingException.class) public void Should_wrapExceptionOccurredProcessingConfig() throws Exception { ISectionStrategy strategy = new ConstantsSectionStrategy(); doThrow(ChangeValueException.class).when(globalConstantsObjectMock).setValue(any(), any()); strategy.onLoadConfig(configMock); }