MapsSectionProcessingStrategy implements ISectionStrategy { @Override public void onLoadConfig(final IObject config) throws ConfigurationProcessingException { try { List<IObject> section = (List<IObject>) config.getValue(name); IChainStorage chainStorage = IOC.resolve(Keys.getOrAdd(IChainStorage.class.getCanonicalName())); for (IObject mapDescription : section) { Object mapId = IOC.resolve(Keys.getOrAdd("chain_id_from_map_name"), mapDescription.getValue(mapIdFieldName)); try { chainStorage.register(mapId, mapDescription); } catch (ChainCreationException e) { throw new ConfigurationProcessingException("Could not create chain for map #'" + String.valueOf(mapId) + "'.", e); } } } catch (InvalidArgumentException | ResolutionException | ReadValueException e) { throw new ConfigurationProcessingException("Error occurred loading \"maps\" section of configuration.", e); } } MapsSectionProcessingStrategy(); @Override void onLoadConfig(final IObject config); @Override IFieldName getSectionName();  }
@Test public void Should_wrapExceptionThrownByChainStorage() throws Exception { doThrow(ChainCreationException.class).when(chainStorageMock).register(chain2id, section.get(1)); try { ISectionStrategy strategy = new MapsSectionProcessingStrategy(); strategy.onLoadConfig(configMock); fail(); } catch (ConfigurationProcessingException e) { assertSame(ChainCreationException.class, e.getCause().getClass()); verify(chainStorageMock).register(chain1id, section.get(0)); } }
@Test(expected = ConfigurationProcessingException.class) public void Should_wrapExceptionsThrownByIOC() throws Exception { when(IOC.resolve(chainStorageKey)).thenThrow(ResolutionException.class); new MapsSectionProcessingStrategy().onLoadConfig(configMock); }