Skip to content

Commit

Permalink
DATACMNS-257 - PropertyPath can now handle all-uppercase fields.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odrotbohm committed Nov 29, 2012
1 parent 5664554 commit 3fd47ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -281,10 +281,37 @@ public void hashCodeTests() {
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 {
Expand Down

0 comments on commit 3fd47ee

Please sign in to comment.