This commit is contained in:
Phillip Webb
2015-06-24 16:15:12 -07:00
parent bc9321734f
commit 778e3eb091
6 changed files with 38 additions and 43 deletions

View File

@@ -350,24 +350,23 @@ public class ConfigurationMetadataAnnotationProcessorTests {
@Test
public void mergingOfSimpleHint() throws Exception {
writeAdditionalHints(
ItemHint.newHint("simple.the-name", new ItemHint.ValueHint("boot", "Bla bla"),
new ItemHint.ValueHint("spring", null)));
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")
.withValue(1, "spring", null));
assertThat(metadata,
containsHint("simple.the-name").withValue(0, "boot", "Bla bla")
.withValue(1, "spring", null));
}
@Test
public void mergingOfHintWithNonCanonicalName() throws Exception {
writeAdditionalHints(
ItemHint.newHint("simple.theName", new ItemHint.ValueHint("boot", "Bla bla")));
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"));
assertThat(metadata,
containsHint("simple.the-name").withValue(0, "boot", "Bla bla"));
}
@Test

View File

@@ -241,8 +241,7 @@ public class ConfigurationMetadataMatchers {
description.appendText("missing hint " + this.name);
}
else {
description.appendText(
"was hint ").appendValue(itemHint);
description.appendText("was hint ").appendValue(itemHint);
}
}
@@ -260,8 +259,7 @@ public class ConfigurationMetadataMatchers {
return new ContainsHintMatcher(this.name, values);
}
private ItemHint getFirstHintWithName(ConfigurationMetadata metadata,
String name) {
private ItemHint getFirstHintWithName(ConfigurationMetadata metadata, String name) {
for (ItemHint hint : metadata.getHints()) {
if (name.equals(hint.getName())) {
return hint;
@@ -273,8 +271,11 @@ public class ConfigurationMetadataMatchers {
}
public static class ValueHintMatcher extends BaseMatcher<ItemHint> {
private final int index;
private final Object value;
private final String description;
public ValueHintMatcher(int index, Object value, String description) {
@@ -290,12 +291,11 @@ public class ConfigurationMetadataMatchers {
return false;
}
ItemHint.ValueHint valueHint = hint.getValues().get(this.index);
if (this.value != null
&& !this.value.equals(valueHint.getValue())) {
if (this.value != null && !this.value.equals(valueHint.getValue())) {
return false;
}
if (this.description != null
&& !this.description.equals(valueHint.getDescription())) {
&& !this.description.equals(valueHint.getDescription())) {
return false;
}
return true;
@@ -303,7 +303,7 @@ public class ConfigurationMetadataMatchers {
@Override
public void describeTo(Description description) {
description.appendText("value hint at index '"+this.index+"'");
description.appendText("value hint at index '" + this.index + "'");
if (this.value != null) {
description.appendText(" value ").appendValue(this.value);
}
@@ -312,15 +312,6 @@ public class ConfigurationMetadataMatchers {
}
}
private ItemHint.ValueHint getValueHint(ItemHint hint) {
for (ItemHint.ValueHint valueHint : hint.getValues()) {
if (this.value.equals(valueHint.getValue())) {
return valueHint;
}
}
return null;
}
}
}

View File

@@ -74,7 +74,8 @@ public class JsonMarshallerTests {
containsProperty("f").withDefaultValue(is(new boolean[] { true, false })));
assertThat(read, containsGroup("d"));
assertThat(read, containsHint("a.b"));
assertThat(read, containsHint("c").withValue(0, 123, "hey").withValue(1, 456, null));
assertThat(read,
containsHint("c").withValue(0, 123, "hey").withValue(1, 456, null));
}
}