Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

package org.springframework.core.env;

import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import org.springframework.lang.Nullable;

/**
* Holder containing one or more {@link PropertySource} objects.
*
* @author Chris Beams
* @author Christoph Dreis
* @since 3.1
*/
public interface PropertySources extends Iterable<PropertySource<?>> {
Expand All @@ -39,4 +43,12 @@ public interface PropertySources extends Iterable<PropertySource<?>> {
@Nullable
PropertySource<?> get(String name);

/**
* Returns a sequential {@code Stream} for the {@link PropertySource objects}
* contained in this instance.
*/
default Stream<PropertySource<?>> stream() {
return StreamSupport.stream(spliterator(), false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/**
* @author Chris Beams
* @author Juergen Hoeller
* @author Christoph Dreis
*/
public class MutablePropertySourcesTests {

Expand Down Expand Up @@ -153,4 +154,23 @@ public void getNonExistentPropertySourceReturnsNull() {
assertThat(sources.get("bogus"), nullValue());
}

@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 ->
source.getName().equals("test")), is(true));
assertThat(sources.stream().anyMatch(source ->
source.getName().equals("bogus")), is(false));
}

@Test
public void streamIsNotNullForEmptySources() {
MutablePropertySources sources = new MutablePropertySources();
assertThat(sources.stream(), notNullValue());
assertThat(sources.stream().count(), is(0L));
}

}