### Question:
IndividualSettingsValidator implements ConfigurationValidator { @Override public Map<String,String> validate( @Nonnull Config config, @Nonnull Log log ) throws InvalidSettingException { Map<String,String> rawConfig = config.getRaw(); Map<String,String> validConfig = stringMap(); for ( SettingValidator validator : settingValidators ) { validConfig.putAll( validator.validate( rawConfig, log::warn ) ); } final boolean strictValidation = config.get( strict_config_validation ); rawConfig.forEach( ( key, value ) -> { if ( !validConfig.containsKey( key ) ) { if ( reservedPrefixes.stream().anyMatch( key::startsWith ) ) { if ( warnOnUnknownSettings ) { log.warn( "Unknown config option: %s", key ); } if ( strictValidation ) { throw new InvalidSettingException( String.format( "Unknown config option '%s'. To resolve either remove it from your configuration " + "or set '%s' to false.", key, strict_config_validation.name() ) ); } else { validConfig.put( key, value ); } } else { validConfig.put( key, value ); } } } ); return Collections.emptyMap(); } IndividualSettingsValidator( Collection<SettingValidator> settingValidators, boolean warnOnUnknownSettings ); @Override Map<String,String> validate( @Nonnull Config config, @Nonnull Log log );  }### Answer:
@Test public void nonStrictRetainsSettings() { IndividualSettingsValidator iv = new IndividualSettingsValidator( singletonList( strict_config_validation ), true ); final Map<String,String> rawConfig = stringMap( strict_config_validation.name(), FALSE, "dbms.jibber.jabber", "bla", "external_plugin.foo", "bar" ); Config config = mockConfig( rawConfig ); iv.validate( config, log ); verify( log ).warn( "Unknown config option: %s", "dbms.jibber.jabber" ); verifyNoMoreInteractions( log ); }
@Test public void strictErrorsOnUnknownSettingsInOurNamespace() { IndividualSettingsValidator iv = new IndividualSettingsValidator( singletonList( strict_config_validation ), true ); final Map<String,String> rawConfig = stringMap( strict_config_validation.name(), TRUE, "dbms.jibber.jabber", "bla", "external_plugin.foo", "bar" ); Config config = mockConfig( rawConfig ); expected.expect( InvalidSettingException.class ); expected.expectMessage( String.format( "Unknown config option 'dbms.jibber.jabber'. To resolve either remove" + " it from your configuration or set '%s' to false.", strict_config_validation.name() ) ); iv.validate( config, log ); }
@Test public void strictAllowsStuffOutsideOurNamespace() { IndividualSettingsValidator iv = new IndividualSettingsValidator( singletonList( strict_config_validation ), true ); final Map<String,String> rawConfig = stringMap( strict_config_validation.name(), TRUE, "external_plugin.foo", "bar" ); Config config = mockConfig( rawConfig ); iv.validate( config, log ); verifyNoMoreInteractions( log ); }