Exemplo n.º 1
0
  /**
   * set property filters in use
   *
   * @param propertyFilters property filters which should be applied after loading properties
   * @return the instance of ConfigBuilder
   */
  public ConfigBuilder<T> withPropertyFilters(
      Class<? extends PropertyLoaderFilter>... propertyFilters) {
    final DefaultPropertyFilterContainer filterContainer = propertyLoader.getFilters();
    final List<PropertyLoaderFilter> filters = filterContainer.getFilters();
    filters.clear();

    for (Class<? extends PropertyLoaderFilter> propertyFilter : propertyFilters) {
      try {
        filters.add(propertyFilter.newInstance());
      } catch (InstantiationException e) {
        LOGGER.error("could not create filter '{}'", propertyFilter.getSimpleName(), e);
      } catch (IllegalAccessException e) {
        LOGGER.error("could not create filter '{}'", propertyFilter.getSimpleName(), e);
      }
    }
    return this;
  }
  @Test
  public void testWithDefaultConfig() throws Exception {

    when(propertyLocation.clear()).thenReturn(propertyLocation);
    when(propertySuffix.clear()).thenReturn(propertySuffix);
    when(propertyFilter.clear()).thenReturn(propertyFilter);

    assertEquals(propertyLoader, propertyLoader.withDefaultConfig());

    verify(propertyLocation).clear();
    verify(propertySuffix).clear();
    verify(propertyFilter).clear();
    verify(propertyLocation).atDefaultLocations();
    verify(propertySuffix).addDefaultSuffixes();
    verify(propertyFilter).withDefaultFilters();
  }