CoreConfigurationBuilder extends DefaultConfigurationBuilder { @Override public Configuration build() { Configuration cfg = new CoreConfiguration( new DefaultConfigurationContext( serviceContext, this.propertyFilters, this.propertySources, this.propertyConverters, this.metaDataProvider )); built = true; return cfg; } CoreConfigurationBuilder();  CoreConfigurationBuilder(Configuration config);  CoreConfigurationBuilder(ConfigurationContext context); @Override Configuration build();  }
@Test public void setContext() throws Exception { ConfigurationContext context = Configuration.current().getContext(); ConfigurationBuilder b = new CoreConfigurationBuilder() .setContext(context); assertThat(b.build().getContext()).isEqualTo(context); }
@Test public void setConfiguration() throws Exception { Configuration cfg = Configuration.current(); ConfigurationBuilder b = new CoreConfigurationBuilder() .setConfiguration(cfg); assertThat(b.build()).isEqualTo(cfg); }
@Test public void addPropertySources_Array() throws Exception { PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2"); ConfigurationBuilder b = new CoreConfigurationBuilder() .addPropertySources(testPropertySource, testPS2); Configuration cfg = b.build(); ConfigurationContext ctx = cfg.getContext(); assertThat(ctx.getPropertySources()).hasSize(2).contains(testPropertySource, testPS2); }
@Test public void removePropertySources_Array() throws Exception { PropertySource testPS2 = new TestPropertySource("addPropertySources_Array_2"); ConfigurationBuilder b = new CoreConfigurationBuilder() .addPropertySources(testPropertySource, testPS2); Configuration cfg = b.build(); ConfigurationContext ctx = cfg.getContext(); assertThat(ctx.getPropertySources()).hasSize(2).contains(testPropertySource, testPS2); b = new CoreConfigurationBuilder() .addPropertySources(testPropertySource, testPS2); b.removePropertySources(testPropertySource); cfg = b.build(); ctx = cfg.getContext(); assertThat(ctx.getPropertySources()).hasSize(1).contains(testPS2); }
@Test public void addPropertyFilters_Array() throws Exception { PropertyFilter filter1 = (value, ctx) -> value; PropertyFilter filter2 = (value, ctx) -> value; CoreConfigurationBuilder b = new CoreConfigurationBuilder(); b.addPropertyFilters(filter1, filter2); Configuration cfg = b.build(); ConfigurationContext ctx = cfg.getContext(); assertThat(ctx.getPropertyFilters()).hasSize(2).contains(filter1, filter2); b = new CoreConfigurationBuilder(); b.addPropertyFilters(filter1, filter2); b.addPropertyFilters(filter1, filter2); assertThat(ctx.getPropertyFilters()).hasSize(2); }
@Test public void removePropertyFilters_Array() throws Exception { PropertyFilter filter1 = (value, ctx) -> value; PropertyFilter filter2 = (value, ctx) -> value; ConfigurationBuilder b = new CoreConfigurationBuilder() .addPropertyFilters(filter1, filter2); Configuration cfg = b.build(); ConfigurationContext ctx = cfg.getContext(); assertThat(ctx.getPropertyFilters()).hasSize(2).contains(filter1, filter2); b = new CoreConfigurationBuilder() .addPropertyFilters(filter1, filter2); b.removePropertyFilters(filter1); cfg = b.build(); ctx = cfg.getContext(); assertThat(ctx.getPropertyFilters()).hasSize(1).contains(filter2); }
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void addPropertyConverter() throws Exception { PropertyConverter converter = (value, ctx) -> value.toLowerCase(); ConfigurationBuilder b = new CoreConfigurationBuilder() .addPropertyConverters(TypeLiteral.of(String.class), converter); Configuration cfg = b.build(); ConfigurationContext ctx = cfg.getContext(); assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class))).contains(converter); assertThat(ctx.getPropertyConverters()).hasSize(1); b = new CoreConfigurationBuilder() .addPropertyConverters(TypeLiteral.of(String.class), converter); b.addPropertyConverters(TypeLiteral.of(String.class), converter); assertThat(ctx.getPropertyConverters()).hasSize(1); }
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void removePropertyConverters_Array() throws Exception { PropertyConverter converter = (value, ctx) -> value.toLowerCase(); ConfigurationBuilder b = new CoreConfigurationBuilder() .addPropertyConverters(TypeLiteral.of(String.class), converter); Configuration cfg = b.build(); ConfigurationContext ctx = cfg.getContext(); assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class))).hasSize(1).contains(converter); b = new CoreConfigurationBuilder() .addPropertyConverters(TypeLiteral.of(String.class), converter); b.removePropertyConverters(TypeLiteral.of(String.class), converter); cfg = b.build(); ctx = cfg.getContext(); assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class))).doesNotContain(converter).isEmpty(); }
@Test public void build() throws Exception { assertThat(new CoreConfigurationBuilder().build()).isNotNull(); }