Skip to content

Commit 81ae0c9

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 a33b9e3 commit 81ae0c9

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
@@ -367,6 +367,21 @@ public void rejectsTooLongPath() {
367367
.isThrownBy(() -> PropertyPath.from(path, Left.class));
368368
}
369369

370+
@Test // DATACMNS-1304
371+
public void resolvesPropertyPathWithSingleUppercaseLetterPropertyEnding() {
372+
assertThat(from("categoryB", Product.class).toDotPath()).isEqualTo("categoryB");
373+
}
374+
375+
@Test // DATACMNS-1304
376+
public void resolvesPropertyPathWithUppercaseLettersPropertyEnding() {
377+
assertThat(from("categoryABId", Product.class).toDotPath()).isEqualTo("categoryAB.id");
378+
}
379+
380+
@Test // DATACMNS-1304
381+
public void detectsNestedSingleCharacterProperty() {
382+
assertThat(from("category_B", Product.class).toDotPath()).isEqualTo("category.b");
383+
}
384+
370385
private class Foo {
371386

372387
String userName;
@@ -411,4 +426,18 @@ private class Left {
411426
private class Right {
412427
Left bar;
413428
}
429+
430+
// DATACMNS-1304
431+
private class Product {
432+
Category category;
433+
Category categoryB;
434+
Category categoryAB;
435+
}
436+
437+
private class Category {
438+
B b;
439+
String id;
440+
}
441+
442+
private class B {}
414443
}

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)