Skip to content

Commit 04f7164

Browse files
authored
Merge pull request spring-projects#161 from anderius/feature/expose-context-names
Exposing context names
2 parents 1762a6a + 69192f6 commit 04f7164

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import java.util.Collection;
44
import java.util.Collections;
5+
import java.util.HashSet;
56
import java.util.List;
67
import java.util.Map;
8+
import java.util.Set;
79
import java.util.concurrent.ConcurrentHashMap;
810

911
import org.springframework.beans.BeansException;
@@ -61,6 +63,10 @@ public void setConfigurations(List<C> configurations) {
6163
}
6264
}
6365

66+
public Set<String> getContextNames() {
67+
return new HashSet<>(contexts.keySet());
68+
}
69+
6470
@Override
6571
public void destroy() {
6672
Collection<AnnotationConfigApplicationContext> values = this.contexts.values();

spring-cloud-context/src/test/java/org/springframework/cloud/context/named/NamedContextFactoryTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.NoArgsConstructor;
1313

1414
import static org.hamcrest.Matchers.is;
15+
import static org.hamcrest.Matchers.hasItems;
1516
import static org.hamcrest.Matchers.notNullValue;
1617
import static org.hamcrest.Matchers.nullValue;
1718
import static org.junit.Assert.assertThat;
@@ -37,6 +38,8 @@ public void testChildContexts() {
3738
Bar bar = factory.getInstance("bar", Bar.class);
3839
assertThat("bar was null", bar, is(notNullValue()));
3940

41+
assertThat("context names not exposed", factory.getContextNames(), hasItems("foo", "bar"));
42+
4043
Bar foobar = factory.getInstance("foo", Bar.class);
4144
assertThat("bar was not null", foobar, is(nullValue()));
4245

0 commit comments

Comments
 (0)