### Question:
IncludeExcludeFilter { public static IncludeExcludeFilter fromConfiguration() { checkState(Configuration.isInitialized()); Set<String> filterProperties = Configuration.getConfig() .stringPropertyNames() .stream() .filter(key -> key.startsWith(FILTER_CONFIG_PREFIX)) .collect(Collectors.toSet()); if (filterProperties.isEmpty()) { return new IncludeExcludeFilter(ImmutableList.of()); } HashMap<String, Rule.Builder> ruleBuilders = new HashMap<>(); for (String propertyName : filterProperties) { String[] propertyNameParts = propertyName.split("\\."); if (propertyNameParts.length != 3) { throw new InvalidConfigurationException("Unknown property " + propertyName); } String ruleName = propertyNameParts[1]; String rulePropertyType = propertyNameParts[2]; String propertyValue = Configuration.getString(propertyName, null).get(); Rule.Builder builder = ruleBuilders.get(ruleName); if (builder == null) { builder = new Rule.Builder(ruleName); ruleBuilders.put(ruleName, builder); } if (rulePropertyType.equals("itemType")) { builder.setItemType(propertyValue); } else if (rulePropertyType.equals("filterType")) { builder.setFilterType(propertyValue); } else if (rulePropertyType.equals("filterPattern")) { builder.setFilterPattern(propertyValue); } else if (rulePropertyType.equals("action")) { builder.setAction(propertyValue); } else { throw new InvalidConfigurationException("Unknown property " + propertyName); } } List<Rule> rules = new ArrayList<>(); for (Rule.Builder builder : ruleBuilders.values()) { try { rules.add(builder.build()); } catch (IllegalStateException | IllegalArgumentException e) { throw new InvalidConfigurationException(e.getMessage()); } } return new IncludeExcludeFilter(rules); } @VisibleForTesting  IncludeExcludeFilter(List<Rule> rules); @Override String toString(); static IncludeExcludeFilter fromConfiguration(); boolean isAllowed(String value, ItemType itemType); static void main(String[] args);  }### Answer:
@Test public void fromConfiguration_notInitialized_throwsException() { thrown.expect(IllegalStateException.class); IncludeExcludeFilter.fromConfiguration(); }
@Test public void fromConfiguration_invalidProperty_throwsException() { Properties config = new Properties(); config.setProperty("includeExcludeFilter.propertyTest.unknownProperty", "prop value"); setupConfig.initConfig(config); thrown.expect(InvalidConfigurationException.class); thrown.expectMessage("Unknown property includeExcludeFilter.propertyTest.unknownProperty"); IncludeExcludeFilter.fromConfiguration(); }
@Test public void fromConfiguration_invalidPropertyFormat_throwsException() { Properties config = new Properties(); config.setProperty( "includeExcludeFilter.propertyTest.unknownProperty.unknownElement", "prop value"); setupConfig.initConfig(config); thrown.expect(InvalidConfigurationException.class); thrown.expectMessage( "Unknown property includeExcludeFilter.propertyTest.unknownProperty.unknownElement"); IncludeExcludeFilter.fromConfiguration(); }