ConfigurationManager implements IConfigurationManager { @Override public void addSectionStrategy(final ISectionStrategy strategy) throws InvalidArgumentException { if (null == strategy) { throw new InvalidArgumentException("Strategy should not be null."); } if (!registeredSections.add(strategy.getSectionName())) { throw new InvalidArgumentException("Strategy for the section is already registered."); } sectionStrategies.add(strategy); } ConfigurationManager(); @Override void addSectionStrategy(final ISectionStrategy strategy); @Override void applyConfig(final IObject config);  }
@Test(expected = InvalidArgumentException.class) public void Should_notAddStrategiesWithDuplicateSectionName() throws Exception { IFieldName sectionNameMock = mock(IFieldName.class); ISectionStrategy sectionStrategy1 = mock(ISectionStrategy.class); ISectionStrategy sectionStrategy2 = mock(ISectionStrategy.class); when(sectionStrategy1.getSectionName()).thenReturn(sectionNameMock); when(sectionStrategy2.getSectionName()).thenReturn(sectionNameMock); IConfigurationManager configurationManager = new ConfigurationManager(); try { configurationManager.addSectionStrategy(sectionStrategy1); } catch (Exception e) { fail(); } configurationManager.addSectionStrategy(sectionStrategy2); }
@Test(expected = InvalidArgumentException.class) public void Should_throwWhenStrategyIsNull() throws Exception { new ConfigurationManager().addSectionStrategy(null); }