ConfigurableServiceUtil { public static ConfigurableService asConfigurableService(Function<String, @Nullable Object> propertyResolver) { return new ConfigurableService() { @Override public Class<? extends Annotation> annotationType() { return ConfigurableService.class; } @Override public String label() { return resolveString(propertyResolver, SERVICE_PROPERTY_LABEL); } @Override public boolean factory() { return resolveBoolean(propertyResolver, SERVICE_PROPERTY_FACTORY_SERVICE); } @Override public String description_uri() { return resolveString(propertyResolver, SERVICE_PROPERTY_DESCRIPTION_URI); } @Override public String category() { return resolveString(propertyResolver, SERVICE_PROPERTY_CATEGORY); } }; }  static ConfigurableService asConfigurableService(Function<String, @Nullable Object> propertyResolver); static final String CONFIGURABLE_SERVICE_FILTER; static final String CONFIGURABLE_MULTI_CONFIG_SERVICE_FILTER; }
@Test public void asConfigurableServiceDefinedProperties() { String category = "system"; String descriptionURI = "system:inbox"; boolean factory = true; String label = "Inbox"; Properties properties = new Properties(); properties.put(SERVICE_PROPERTY_CATEGORY, category); properties.put(SERVICE_PROPERTY_DESCRIPTION_URI, descriptionURI); properties.put(SERVICE_PROPERTY_FACTORY_SERVICE, factory); properties.put(SERVICE_PROPERTY_LABEL, label); ConfigurableService configurableService = ConfigurableServiceUtil .asConfigurableService((key) -> properties.get(key)); assertThat(configurableService.annotationType(), is(ConfigurableService.class)); assertThat(configurableService.category(), is(category)); assertThat(configurableService.description_uri(), is(descriptionURI)); assertThat(configurableService.factory(), is(factory)); assertThat(configurableService.label(), is(label)); }
@Test public void asConfigurableServiceUndefinedProperties() { Properties properties = new Properties(); ConfigurableService configurableService = ConfigurableServiceUtil .asConfigurableService((key) -> properties.get(key)); assertThat(configurableService.annotationType(), is(ConfigurableService.class)); assertThat(configurableService.category(), is(emptyString())); assertThat(configurableService.description_uri(), is(emptyString())); assertThat(configurableService.factory(), is(false)); assertThat(configurableService.label(), is(emptyString())); }