Add @UnmappedPropertyValue support

Update @PropertyMapping support to allow single enum values to be marked
as an @UnmappedPropertyValue. This change is primarily so that users can
replace "default" values globally for across all tests.

See gh-6455
This commit is contained in:
Phillip Webb
2016-07-25 12:23:17 -07:00
parent ab9834a92e
commit 8355d8516b
4 changed files with 94 additions and 1 deletions

View File

@@ -185,6 +185,20 @@ public class AnnotationsPropertySourceTests {
assertThat(source.getProperty("aliasing.value")).isEqualTo("baz");
}
@Test
public void enumValueMapped() throws Exception {
AnnotationsPropertySource source = new AnnotationsPropertySource(
EnumValueMapped.class);
assertThat(source.getProperty("testenum.value")).isEqualTo(EnumItem.TWO);
}
@Test
public void enumValueNotMapped() throws Exception {
AnnotationsPropertySource source = new AnnotationsPropertySource(
EnumValueNotMapped.class);
assertThat(source.containsProperty("testenum.value")).isFalse();
}
static class NoAnnotation {
}
@@ -382,4 +396,32 @@ public class AnnotationsPropertySourceTests {
}
@EnumAnnotation(EnumItem.TWO)
static class EnumValueMapped {
}
@EnumAnnotation(EnumItem.DEFAULT)
static class EnumValueNotMapped {
}
@Retention(RetentionPolicy.RUNTIME)
@PropertyMapping("testenum")
static @interface EnumAnnotation {
EnumItem value();
}
enum EnumItem {
@UnmappedPropertyValue DEFAULT,
ONE,
TWO
}
}