Merge pull request #161 from anderius/feature/expose-context-names

Exposing context names
This commit is contained in:
Ryan Baxter
2017-01-04 12:41:59 -05:00
committed by GitHub
2 changed files with 9 additions and 0 deletions

View File

@@ -2,8 +2,10 @@ package org.springframework.cloud.context.named;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.beans.BeansException;
@@ -61,6 +63,10 @@ public abstract class NamedContextFactory<C extends NamedContextFactory.Specific
}
}
public Set<String> getContextNames() {
return new HashSet<>(contexts.keySet());
}
@Override
public void destroy() {
Collection<AnnotationConfigApplicationContext> values = this.contexts.values();

View File

@@ -12,6 +12,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
@@ -37,6 +38,8 @@ public class NamedContextFactoryTests {
Bar bar = factory.getInstance("bar", Bar.class);
assertThat("bar was null", bar, is(notNullValue()));
assertThat("context names not exposed", factory.getContextNames(), hasItems("foo", "bar"));
Bar foobar = factory.getInstance("foo", Bar.class);
assertThat("bar was not null", foobar, is(nullValue()));