SearchConfiguration { static SearchConfiguration from(Configuration configuration) throws ConfigurationException { String searchOption = configuration.getString("implementation", Implementation.ElasticSearch.name()); if (searchOption.equalsIgnoreCase(Implementation.ElasticSearch.name())) { return elasticSearch(); } if (searchOption.equalsIgnoreCase(Implementation.Scanning.name())) { return scanning(); } throw new ConfigurationException(String.format("'implementation' parameter in '%s.properties' should have '%s' or '%s' value", SEARCH_CONFIGURATION_NAME, Implementation.ElasticSearch.name(), Implementation.Scanning.name())); } SearchConfiguration(Implementation implementation); static SearchConfiguration parse(PropertiesProvider propertiesProvider); static SearchConfiguration scanning(); static SearchConfiguration elasticSearch(); Implementation getImplementation(); static final String SEARCH_CONFIGURATION_NAME; }
@Test void unknownSearchImplementationShouldThrow() { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.addProperty("implementation", "unknown"); assertThatThrownBy(() -> SearchConfiguration.from(configuration)) .isInstanceOf(ConfigurationException.class); }