Polish (Mutable)PropertySources

* PropertySources is now an Iterable<PropertySource> in favor of
  exposing an asList() method
* Otherwise reduced the set of methods exposed by PropertySources to the
  absolute minimum
* Added Javadoc for both types and all methods
This commit is contained in:
Chris Beams
2011-01-05 22:25:24 +00:00
parent 7f8ede1407
commit bc41cb2f27
7 changed files with 174 additions and 114 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.junit.Test;
public class DefaultEnvironmentTests {
@@ -29,9 +27,9 @@ public class DefaultEnvironmentTests {
@Test
public void propertySourceOrder() {
ConfigurableEnvironment env = new DefaultEnvironment();
List<PropertySource<?>> sources = env.getPropertySources().asList();
MutablePropertySources sources = env.getPropertySources();
assertThat(sources.precedenceOf(PropertySource.named(DefaultEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(0));
assertThat(sources.precedenceOf(PropertySource.named(DefaultEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(1));
assertThat(sources.size(), is(2));
assertThat(sources.get(0).getName(), equalTo(DefaultEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME));
assertThat(sources.get(1).getName(), equalTo(DefaultEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME));
}
}

View File

@@ -53,43 +53,43 @@ public class PropertySourcesTests {
sources.addAfter("b", new MockPropertySource("c"));
assertThat(sources.size(), equalTo(5));
assertThat(sources.asList().indexOf(PropertySource.named("a")), is(0));
assertThat(sources.asList().indexOf(PropertySource.named("b")), is(1));
assertThat(sources.asList().indexOf(PropertySource.named("c")), is(2));
assertThat(sources.asList().indexOf(PropertySource.named("d")), is(3));
assertThat(sources.asList().indexOf(PropertySource.named("f")), is(4));
assertThat(sources.precedenceOf(PropertySource.named("a")), is(0));
assertThat(sources.precedenceOf(PropertySource.named("b")), is(1));
assertThat(sources.precedenceOf(PropertySource.named("c")), is(2));
assertThat(sources.precedenceOf(PropertySource.named("d")), is(3));
assertThat(sources.precedenceOf(PropertySource.named("f")), is(4));
sources.addBefore("f", new MockPropertySource("e"));
sources.addAfter("f", new MockPropertySource("g"));
assertThat(sources.size(), equalTo(7));
assertThat(sources.asList().indexOf(PropertySource.named("a")), is(0));
assertThat(sources.asList().indexOf(PropertySource.named("b")), is(1));
assertThat(sources.asList().indexOf(PropertySource.named("c")), is(2));
assertThat(sources.asList().indexOf(PropertySource.named("d")), is(3));
assertThat(sources.asList().indexOf(PropertySource.named("e")), is(4));
assertThat(sources.asList().indexOf(PropertySource.named("f")), is(5));
assertThat(sources.asList().indexOf(PropertySource.named("g")), is(6));
assertThat(sources.precedenceOf(PropertySource.named("a")), is(0));
assertThat(sources.precedenceOf(PropertySource.named("b")), is(1));
assertThat(sources.precedenceOf(PropertySource.named("c")), is(2));
assertThat(sources.precedenceOf(PropertySource.named("d")), is(3));
assertThat(sources.precedenceOf(PropertySource.named("e")), is(4));
assertThat(sources.precedenceOf(PropertySource.named("f")), is(5));
assertThat(sources.precedenceOf(PropertySource.named("g")), is(6));
sources.addLast(new MockPropertySource("a"));
assertThat(sources.size(), equalTo(7));
assertThat(sources.asList().indexOf(PropertySource.named("b")), is(0));
assertThat(sources.asList().indexOf(PropertySource.named("c")), is(1));
assertThat(sources.asList().indexOf(PropertySource.named("d")), is(2));
assertThat(sources.asList().indexOf(PropertySource.named("e")), is(3));
assertThat(sources.asList().indexOf(PropertySource.named("f")), is(4));
assertThat(sources.asList().indexOf(PropertySource.named("g")), is(5));
assertThat(sources.asList().indexOf(PropertySource.named("a")), is(6));
assertThat(sources.precedenceOf(PropertySource.named("b")), is(0));
assertThat(sources.precedenceOf(PropertySource.named("c")), is(1));
assertThat(sources.precedenceOf(PropertySource.named("d")), is(2));
assertThat(sources.precedenceOf(PropertySource.named("e")), is(3));
assertThat(sources.precedenceOf(PropertySource.named("f")), is(4));
assertThat(sources.precedenceOf(PropertySource.named("g")), is(5));
assertThat(sources.precedenceOf(PropertySource.named("a")), is(6));
sources.addFirst(new MockPropertySource("a"));
assertThat(sources.size(), equalTo(7));
assertThat(sources.asList().indexOf(PropertySource.named("a")), is(0));
assertThat(sources.asList().indexOf(PropertySource.named("b")), is(1));
assertThat(sources.asList().indexOf(PropertySource.named("c")), is(2));
assertThat(sources.asList().indexOf(PropertySource.named("d")), is(3));
assertThat(sources.asList().indexOf(PropertySource.named("e")), is(4));
assertThat(sources.asList().indexOf(PropertySource.named("f")), is(5));
assertThat(sources.asList().indexOf(PropertySource.named("g")), is(6));
assertThat(sources.precedenceOf(PropertySource.named("a")), is(0));
assertThat(sources.precedenceOf(PropertySource.named("b")), is(1));
assertThat(sources.precedenceOf(PropertySource.named("c")), is(2));
assertThat(sources.precedenceOf(PropertySource.named("d")), is(3));
assertThat(sources.precedenceOf(PropertySource.named("e")), is(4));
assertThat(sources.precedenceOf(PropertySource.named("f")), is(5));
assertThat(sources.precedenceOf(PropertySource.named("g")), is(6));
assertEquals(sources.remove("a"), PropertySource.named("a"));
assertThat(sources.size(), equalTo(6));
@@ -109,15 +109,15 @@ public class PropertySourcesTests {
sources.addFirst(new MockPropertySource("a"));
assertThat(sources.size(), equalTo(7));
assertThat(sources.asList().indexOf(PropertySource.named("a")), is(0));
assertThat(sources.asList().indexOf(PropertySource.named("b")), is(1));
assertThat(sources.asList().indexOf(PropertySource.named("c")), is(2));
assertThat(sources.precedenceOf(PropertySource.named("a")), is(0));
assertThat(sources.precedenceOf(PropertySource.named("b")), is(1));
assertThat(sources.precedenceOf(PropertySource.named("c")), is(2));
sources.replace("a", new MockPropertySource("a-replaced"));
assertThat(sources.size(), equalTo(7));
assertThat(sources.asList().indexOf(PropertySource.named("a-replaced")), is(0));
assertThat(sources.asList().indexOf(PropertySource.named("b")), is(1));
assertThat(sources.asList().indexOf(PropertySource.named("c")), is(2));
assertThat(sources.precedenceOf(PropertySource.named("a-replaced")), is(0));
assertThat(sources.precedenceOf(PropertySource.named("b")), is(1));
assertThat(sources.precedenceOf(PropertySource.named("c")), is(2));
sources.replace("a-replaced", new MockPropertySource("a"));