### Question:
WikiTableConfigurationFactory implements IWikiTableConfigurationFactory { @Override public synchronized void addBuilInConfiguration(IWikiTableConfiguration additionalBuildInConfig){ if(additionalBuildInConfig.isReadOnly() == false){ throw new IllegalArgumentException("A not read-only configuration cannot be a build-in configuration!"); } if(isNameUnique(additionalBuildInConfig)){ this.buildInConfigurations.add(additionalBuildInConfig.clone()); }else{ throw new IllegalArgumentException("The name of the configuration " + additionalBuildInConfig.getName() + " is not unique!"); } } WikiTableConfigurationFactory(); @Override synchronized List<IWikiTableConfiguration> getConfigurations(); @Override synchronized List<IWikiTableConfiguration> getUserSpecificConfigurations(); @Override synchronized List<IWikiTableConfiguration> getBuildInConfigurations(); static synchronized IWikiTableConfigurationFactory getInstance(); @Override synchronized void addBuilInConfiguration(IWikiTableConfiguration additionalBuildInConfig); @Override synchronized void replaceBuilInConfiguration(List<IWikiTableConfiguration> configurations); @Override synchronized void replaceUserSpecificConfigurations(List<IWikiTableConfiguration> config); @Override void addUserSpecificConfigurations(IWikiTableConfiguration config); synchronized void setBuildInConfigurations(List<IWikiTableConfiguration> buildInConfigurations); synchronized void setUserSpecificConfigurations(List<IWikiTableConfiguration> userSpecificConfigurations); static List<IWikiTableConfiguration> merge(List<IWikiTableConfiguration> primary, List<IWikiTableConfiguration> secondary);  }### Answer:
@Test(expected=IllegalArgumentException.class) public void testUserSpecificWithNameConflict() { IWikiTableConfiguration mockConfigSystem = mockHelper.createMock(IWikiTableConfiguration.class); expect(mockConfigSystem.getName()).andStubReturn("B"); expect(mockConfigSystem.isReadOnly()).andStubReturn(true); expect(mockConfigSystem.clone()).andStubReturn(mockConfigSystem); IWikiTableConfiguration mockConfigUser = mockHelper.createMock(IWikiTableConfiguration.class); expect(mockConfigUser.getName()).andStubReturn("B"); expect(mockConfigUser.isReadOnly()).andStubReturn(false); expect(mockConfigUser.clone()).andStubReturn(mockConfigUser); mockHelper.replayAll(); try { classUnderTest.addBuilInConfiguration(mockConfigSystem); } catch (IllegalArgumentException e) { fail("It must be possible, to add the build-in Config."); } classUnderTest.addBuilInConfiguration(mockConfigUser); }
@Test(expected=IllegalArgumentException.class) public void testBuildInWithNameConflict() { IWikiTableConfiguration mockConfig = mockHelper.createMock(IWikiTableConfiguration.class); expect(mockConfig.getName()).andStubReturn("NewConfig"); expect(mockConfig.isReadOnly()).andStubReturn(true); expect(mockConfig.clone()).andStubReturn(mockConfig); mockHelper.replayAll(); classUnderTest.addBuilInConfiguration(mockConfig); classUnderTest.addBuilInConfiguration(mockConfig); }
@Test(expected=IllegalArgumentException.class) public void testUserSpecificAsBuildIn() { classUnderTest.addBuilInConfiguration(new GenericWikiTableConfigurationBean()); }
@Test() public void testAddBuildInConfiguration() { IWikiTableConfiguration mockConfig = mockHelper.createMock(IWikiTableConfiguration.class); expect(mockConfig.getName()).andStubReturn("NewConfig"); expect(mockConfig.isReadOnly()).andReturn(true); expect(mockConfig.clone()).andReturn(mockConfig); mockHelper.replayAll(); classUnderTest.addBuilInConfiguration(mockConfig); }