Skip to content

Commit 5f87c67

Browse files
committed
DATACMNS-1304 - Polishing.
Moved test cases into PropertyPathUnit test so that they're closer to the implementation. Switched to Introspector.decapitalize(…) to follow the Java Beans Specification regarding the handling of all-uppercase properties. Original pull request: #289.
1 parent 1da969d commit 5f87c67

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

src/main/java/org/springframework/data/mapping/PropertyPath.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import lombok.Getter;
2020
import lombok.Value;
2121

22+
import java.beans.Introspector;
2223
import java.util.ArrayList;
2324
import java.util.Collections;
2425
import java.util.Iterator;
@@ -86,7 +87,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
8687
Assert.notNull(owningType, "Owning type must not be null!");
8788
Assert.notNull(base, "Perviously found properties must not be null!");
8889

89-
String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name);
90+
String propertyName = Introspector.decapitalize(name);
9091
TypeInformation<?> propertyType = owningType.getProperty(propertyName);
9192

9293
if (propertyType == null) {

src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,21 @@ public void rejectsTooLongPath() {
386386
.isThrownBy(() -> PropertyPath.from(path, Left.class));
387387
}
388388

389+
@Test // DATACMNS-1304
390+
public void resolvesPropertyPathWithSingleUppercaseLetterPropertyEnding() {
391+
assertThat(from("categoryB", Product.class).toDotPath()).isEqualTo("categoryB");
392+
}
393+
394+
@Test // DATACMNS-1304
395+
public void resolvesPropertyPathWithUppercaseLettersPropertyEnding() {
396+
assertThat(from("categoryABId", Product.class).toDotPath()).isEqualTo("categoryAB.id");
397+
}
398+
399+
@Test // DATACMNS-1304
400+
public void detectsNestedSingleCharacterProperty() {
401+
assertThat(from("category_B", Product.class).toDotPath()).isEqualTo("category.b");
402+
}
403+
389404
private class Foo {
390405

391406
String userName;
@@ -430,4 +445,18 @@ private class Left {
430445
private class Right {
431446
Left bar;
432447
}
448+
449+
// DATACMNS-1304
450+
private class Product {
451+
Category category;
452+
Category categoryB;
453+
Category categoryAB;
454+
}
455+
456+
private class Category {
457+
B b;
458+
String id;
459+
}
460+
461+
private class B {}
433462
}

src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -601,16 +601,6 @@ public void emptyTreeDoesNotContainParts() {
601601
assertThat(tree.hasPredicate()).isFalse();
602602
}
603603

604-
@Test // DATACMNS-1304
605-
public void resolvesPropertyPathWithSingleUppercaseLetterPropertyEnding() {
606-
assertThat(new PartTree("findByCategoryBId", Product.class)).isNotNull();
607-
}
608-
609-
@Test // DATACMNS-1304
610-
public void resolvesPropertyPathWithUppercaseLettersPropertyEnding() {
611-
assertThat(new PartTree("findByCategoryABId", Product.class)).isNotNull();
612-
}
613-
614604
private static void assertLimiting(String methodName, Class<?> entityType, boolean limiting, Integer maxResults) {
615605
assertLimiting(methodName, entityType, limiting, maxResults, false);
616606
}
@@ -734,10 +724,6 @@ interface Product {
734724
Anders getAnders(); // constains And keyword
735725

736726
Category getCategory();
737-
738-
Category getCategoryB(); // contains single uppercase letter at the end
739-
740-
Category getCategoryAB(); // contains uppercase letters at the end
741727
}
742728

743729
interface Category {

0 commit comments

Comments
 (0)