DATACMNS-257 - PropertyPath can now handle all-uppercase fields.

So far, PropertyPath inevitably uncapitalized the property names it was created for. We now check, whether the source name is all uppercase and prevent uncapitalization in this case.
This commit is contained in:
Oliver Gierke
2012-11-29 12:22:24 +01:00
parent d0111d8118
commit 0c4ed8a86a
2 changed files with 30 additions and 2 deletions

View File

@@ -35,6 +35,7 @@ import org.springframework.util.StringUtils;
public class PropertyPath implements Iterable<PropertyPath> {
private static final String DELIMITERS = "_\\.";
private static final String ALL_UPPERCASE = "[A-Z0-9._$]+";
private static final Pattern SPLITTER = Pattern.compile("(?:[%s]?([%s]*?[^%s]+))".replaceAll("%s", DELIMITERS));
private final TypeInformation<?> owningType;
@@ -67,7 +68,7 @@ public class PropertyPath implements Iterable<PropertyPath> {
Assert.hasText(name);
Assert.notNull(owningType);
String propertyName = StringUtils.uncapitalize(name);
String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name);
TypeInformation<?> type = owningType.getProperty(propertyName);
if (type == null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-2012 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.
@@ -281,10 +281,37 @@ public class PropertyPathUnitTests {
assertThat(left.hashCode(), is(not(shortPath.hashCode())));
}
/**
* @see DATACMNS-257
*/
@Test
public void findsAllUppercaseProperty() {
PropertyPath path = PropertyPath.from("UUID", Foo.class);
assertThat(path, is(notNullValue()));
assertThat(path.getSegment(), is("UUID"));
}
/**
* @see DATACMNS-257
*/
@Test
public void findsNestedAllUppercaseProperty() {
PropertyPath path = PropertyPath.from("_fooUUID", Sample2.class);
assertThat(path, is(notNullValue()));
assertThat(path.getSegment(), is("_foo"));
assertThat(path.hasNext(), is(true));
assertThat(path.next().getSegment(), is("UUID"));
}
private class Foo {
String userName;
String _email;
String UUID;
}
private class Bar {