DATACMNS-867 - Preserve underscores when resolving PropertyPath for PersistentProperties.
Preserve underscores in variable names (eg. String foo_bar) when resolving the actual type information for the property via PropertyPath by quoting (Pattern#quote) the property name.
This commit is contained in:
committed by
Oliver Gierke
parent
2da5acc553
commit
47e2e61ff5
@@ -21,6 +21,7 @@ import static org.springframework.data.mapping.PropertyPath.*;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -32,6 +33,7 @@ import org.springframework.data.util.TypeInformation;
|
||||
* Unit tests for {@link PropertyPath}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PropertyPathUnitTests {
|
||||
@@ -333,11 +335,22 @@ public class PropertyPathUnitTests {
|
||||
from("userAme", Foo.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-867
|
||||
public void preservesUnderscoresForQuotedNames() {
|
||||
|
||||
PropertyPath path = from(Pattern.quote("var_name_with_underscore"), Foo.class);
|
||||
|
||||
assertThat(path).isNotNull();
|
||||
assertThat(path.getSegment()).isEqualTo("var_name_with_underscore");
|
||||
assertThat(path.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
private class Foo {
|
||||
|
||||
String userName;
|
||||
String _email;
|
||||
String UUID;
|
||||
String var_name_with_underscore;
|
||||
}
|
||||
|
||||
private class Bar {
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
* Unit tests for {@link AbstractPersistentProperty}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class AbstractPersistentPropertyUnitTests {
|
||||
|
||||
@@ -192,6 +193,13 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
assertThat(property.isEntity()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-867
|
||||
public void resolvesFieldNameWithUnderscoresCorrectly() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(TestClassComplex.class, "var_name_with_underscores");
|
||||
assertThat(property.getName()).isEqualTo("var_name_with_underscores");
|
||||
}
|
||||
|
||||
private <T> BasicPersistentEntity<T, SamplePersistentProperty> getEntity(Class<T> type) {
|
||||
return new BasicPersistentEntity<>(ClassTypeInformation.from(type));
|
||||
}
|
||||
@@ -244,6 +252,7 @@ public class AbstractPersistentPropertyUnitTests {
|
||||
Map map;
|
||||
Collection collection;
|
||||
transient Object transientField;
|
||||
String var_name_with_underscores;
|
||||
}
|
||||
|
||||
class AccessorTestClass {
|
||||
|
||||
Reference in New Issue
Block a user