Polish
This commit is contained in:
@@ -44,8 +44,10 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
|
||||
public ItemHint(String name, List<ValueHint> values, List<ProviderHint> providers) {
|
||||
this.name = toCanonicalName(name);
|
||||
this.values = (values != null ? new ArrayList<ValueHint>(values) : new ArrayList<ValueHint>());
|
||||
this.providers = (providers != null ? new ArrayList<ProviderHint>(providers) : new ArrayList<ProviderHint>());
|
||||
this.values = (values != null ? new ArrayList<ValueHint>(values)
|
||||
: new ArrayList<ValueHint>());
|
||||
this.providers = (providers != null ? new ArrayList<ProviderHint>(providers)
|
||||
: new ArrayList<ProviderHint>());
|
||||
}
|
||||
|
||||
private String toCanonicalName(String name) {
|
||||
@@ -76,7 +78,8 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
}
|
||||
|
||||
public static ItemHint newHint(String name, ValueHint... values) {
|
||||
return new ItemHint(name, Arrays.asList(values), Collections.<ProviderHint>emptyList());
|
||||
return new ItemHint(name, Arrays.asList(values),
|
||||
Collections.<ProviderHint> emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,8 +116,10 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
}
|
||||
|
||||
public static class ProviderHint {
|
||||
|
||||
private final String name;
|
||||
private final Map<String,Object> parameters;
|
||||
|
||||
private final Map<String, Object> parameters;
|
||||
|
||||
public ProviderHint(String name, Map<String, Object> parameters) {
|
||||
this.name = name;
|
||||
@@ -122,18 +127,19 @@ public class ItemHint implements Comparable<ItemHint> {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Map<String, Object> getParameters() {
|
||||
return parameters;
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Provider{" + "name='" + this.name + ", parameters=" + this.parameters +
|
||||
'}';
|
||||
return "Provider{" + "name='" + this.name + ", parameters=" + this.parameters
|
||||
+ '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -110,10 +110,13 @@ public class JsonMarshaller {
|
||||
for (ItemHint.ProviderHint providerHint : hint.getProviders()) {
|
||||
JSONObject providerHintObject = new JSONOrderedObject();
|
||||
providerHintObject.put("name", providerHint.getName());
|
||||
if (providerHint.getParameters() != null && !providerHint.getParameters().isEmpty()) {
|
||||
if (providerHint.getParameters() != null
|
||||
&& !providerHint.getParameters().isEmpty()) {
|
||||
JSONObject parametersObject = new JSONOrderedObject();
|
||||
for (Map.Entry<String, Object> entry : providerHint.getParameters().entrySet()) {
|
||||
parametersObject.put(entry.getKey(), extractItemValue(entry.getValue()));
|
||||
for (Map.Entry<String, Object> entry : providerHint.getParameters()
|
||||
.entrySet()) {
|
||||
parametersObject.put(entry.getKey(),
|
||||
extractItemValue(entry.getValue()));
|
||||
}
|
||||
providerHintObject.put("parameters", parametersObject);
|
||||
}
|
||||
@@ -218,7 +221,7 @@ public class JsonMarshaller {
|
||||
|
||||
private ItemHint.ProviderHint toProviderHint(JSONObject object) {
|
||||
String name = object.getString("name");
|
||||
Map<String,Object> parameters = new HashMap<String,Object>();
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
if (object.has("parameters")) {
|
||||
JSONObject parametersObject = object.getJSONObject("parameters");
|
||||
for (Object k : parametersObject.keySet()) {
|
||||
|
||||
@@ -330,7 +330,6 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
@Test
|
||||
public void mergingOfAdditionalProperty() throws Exception {
|
||||
File additionalMetadataFile = createAdditionalMetadataFile();
|
||||
|
||||
JSONObject property = new JSONObject();
|
||||
property.put("name", "foo");
|
||||
property.put("type", "java.lang.String");
|
||||
@@ -339,12 +338,9 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
properties.put(property);
|
||||
JSONObject additionalMetadata = new JSONObject();
|
||||
additionalMetadata.put("properties", properties);
|
||||
|
||||
writeMetadata(additionalMetadataFile, additionalMetadata);
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
|
||||
assertThat(metadata, containsProperty("simple.comparator"));
|
||||
|
||||
assertThat(metadata,
|
||||
containsProperty("foo", String.class)
|
||||
.fromSource(AdditionalMetadata.class));
|
||||
@@ -354,7 +350,6 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
public void mergingOfSimpleHint() throws Exception {
|
||||
writeAdditionalHints(ItemHint.newHint("simple.the-name", new ItemHint.ValueHint(
|
||||
"boot", "Bla bla"), new ItemHint.ValueHint("spring", null)));
|
||||
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata,
|
||||
containsHint("simple.the-name").withValue(0, "boot", "Bla bla")
|
||||
@@ -365,7 +360,6 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
public void mergingOfHintWithNonCanonicalName() throws Exception {
|
||||
writeAdditionalHints(ItemHint.newHint("simple.theName", new ItemHint.ValueHint(
|
||||
"boot", "Bla bla")));
|
||||
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata,
|
||||
containsHint("simple.the-name").withValue(0, "boot", "Bla bla"));
|
||||
@@ -373,16 +367,16 @@ public class ConfigurationMetadataAnnotationProcessorTests {
|
||||
|
||||
@Test
|
||||
public void mergingOfHintWithProvider() throws Exception {
|
||||
writeAdditionalHints(
|
||||
new ItemHint("simple.theName", Collections.<ItemHint.ValueHint>emptyList(), Arrays.asList(
|
||||
new ItemHint.ProviderHint("first", Collections.<String,Object>singletonMap("target", "org.foo")),
|
||||
new ItemHint.ProviderHint("second", null))
|
||||
));
|
||||
|
||||
writeAdditionalHints(new ItemHint("simple.theName",
|
||||
Collections.<ItemHint.ValueHint> emptyList(), Arrays.asList(
|
||||
new ItemHint.ProviderHint("first", Collections
|
||||
.<String, Object> singletonMap("target", "org.foo")),
|
||||
new ItemHint.ProviderHint("second", null))));
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata, containsHint("simple.the-name")
|
||||
.withProvider("first", "target", "org.foo")
|
||||
.withProvider("second"));
|
||||
assertThat(metadata,
|
||||
containsHint("simple.the-name")
|
||||
.withProvider("first", "target", "org.foo")
|
||||
.withProvider("second"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -212,10 +212,12 @@ public class ConfigurationMetadataMatchers {
|
||||
private final List<ProviderHintMatcher> providers;
|
||||
|
||||
public ContainsHintMatcher(String name) {
|
||||
this(name, new ArrayList<ValueHintMatcher>(), new ArrayList<ProviderHintMatcher>());
|
||||
this(name, new ArrayList<ValueHintMatcher>(),
|
||||
new ArrayList<ProviderHintMatcher>());
|
||||
}
|
||||
|
||||
public ContainsHintMatcher(String name, List<ValueHintMatcher> values, List<ProviderHintMatcher> providers) {
|
||||
public ContainsHintMatcher(String name, List<ValueHintMatcher> values,
|
||||
List<ProviderHintMatcher> providers) {
|
||||
this.name = name;
|
||||
this.values = values;
|
||||
this.providers = providers;
|
||||
@@ -273,14 +275,17 @@ public class ConfigurationMetadataMatchers {
|
||||
return new ContainsHintMatcher(this.name, values, this.providers);
|
||||
}
|
||||
|
||||
public ContainsHintMatcher withProvider(int index, String provider, Map<String,Object> parameters) {
|
||||
List<ProviderHintMatcher> providers = new ArrayList<ProviderHintMatcher>(this.providers);
|
||||
public ContainsHintMatcher withProvider(int index, String provider,
|
||||
Map<String, Object> parameters) {
|
||||
List<ProviderHintMatcher> providers = new ArrayList<ProviderHintMatcher>(
|
||||
this.providers);
|
||||
providers.add(new ProviderHintMatcher(index, provider, parameters));
|
||||
return new ContainsHintMatcher(this.name, this.values, providers);
|
||||
}
|
||||
|
||||
public ContainsHintMatcher withProvider(String provider, String key, Object value) {
|
||||
return withProvider(this.providers.size(), provider, Collections.singletonMap(key, value));
|
||||
return withProvider(this.providers.size(), provider,
|
||||
Collections.singletonMap(key, value));
|
||||
}
|
||||
|
||||
public ContainsHintMatcher withProvider(String provider) {
|
||||
@@ -359,9 +364,8 @@ public class ConfigurationMetadataMatchers {
|
||||
if (this.index + 1 > hint.getProviders().size()) {
|
||||
return false;
|
||||
}
|
||||
ItemHint.ProviderHint providerHint = hint.getProviders().get(index);
|
||||
if (this.name != null
|
||||
&& !this.name.equals(providerHint.getName())) {
|
||||
ItemHint.ProviderHint providerHint = hint.getProviders().get(this.index);
|
||||
if (this.name != null && !this.name.equals(providerHint.getName())) {
|
||||
return false;
|
||||
}
|
||||
if (this.parameters != null) {
|
||||
|
||||
@@ -58,8 +58,8 @@ public class JsonMarshallerTests {
|
||||
metadata.add(ItemHint.newHint("a.b"));
|
||||
metadata.add(ItemHint.newHint("c", new ItemHint.ValueHint(123, "hey"),
|
||||
new ItemHint.ValueHint(456, null)));
|
||||
metadata.add(new ItemHint("d", null, Arrays.asList(
|
||||
new ItemHint.ProviderHint("first", Collections.<String,Object>singletonMap("target", "foo")),
|
||||
metadata.add(new ItemHint("d", null, Arrays.asList(new ItemHint.ProviderHint(
|
||||
"first", Collections.<String, Object> singletonMap("target", "foo")),
|
||||
new ItemHint.ProviderHint("second", null))));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JsonMarshaller marshaller = new JsonMarshaller();
|
||||
@@ -81,8 +81,7 @@ public class JsonMarshallerTests {
|
||||
assertThat(read, containsHint("a.b"));
|
||||
assertThat(read,
|
||||
containsHint("c").withValue(0, 123, "hey").withValue(1, 456, null));
|
||||
assertThat(read, containsHint("d")
|
||||
.withProvider("first", "target", "foo")
|
||||
assertThat(read, containsHint("d").withProvider("first", "target", "foo")
|
||||
.withProvider("second"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user