private Stream<PropertySource<?>> getPropertySources() { if (this.environment == null) { return Stream.empty(); } return this.environment.getPropertySources().stream() .filter((source) -> !ConfigurationPropertySources .isAttachedConfigurationPropertySource(source)); }
@Override public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { MutablePropertySources propertySources = environment.getPropertySources(); propertySources.stream().map(JsonPropertyValue::get).filter(Objects::nonNull) .findFirst().ifPresent((v) -> processJson(environment, v)); }
@Test public void streamContainsPropertySource() { MutablePropertySources sources = new MutablePropertySources(); sources.addLast(new MockPropertySource("test")); assertThat(sources.stream(), notNullValue()); assertThat(sources.stream().count(), is(1L)); assertThat(sources.stream().anyMatch(source -> "test".equals(source.getName())), is(true)); assertThat(sources.stream().anyMatch(source -> "bogus".equals(source.getName())), is(false)); }
private Integer getPropertyAsInteger(ConfigurableEnvironment environment, String property, Integer defaultValue) { return environment.getPropertySources().stream() .filter((source) -> !source.getName().equals( TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME)) .map((source) -> getPropertyAsInteger(source, property, environment)) .filter(Objects::nonNull).findFirst().orElse(defaultValue); }