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.
This commit is contained in:
@@ -19,6 +19,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Value;
|
||||
|
||||
import java.beans.Introspector;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@@ -86,7 +87,7 @@ public class PropertyPath implements Streamable<PropertyPath> {
|
||||
Assert.notNull(owningType, "Owning type must not be null!");
|
||||
Assert.notNull(base, "Perviously found properties must not be null!");
|
||||
|
||||
String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name);
|
||||
String propertyName = Introspector.decapitalize(name);
|
||||
TypeInformation<?> propertyType = owningType.getProperty(propertyName);
|
||||
|
||||
if (propertyType == null) {
|
||||
|
||||
@@ -367,6 +367,21 @@ public class PropertyPathUnitTests {
|
||||
.isThrownBy(() -> PropertyPath.from(path, Left.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1304
|
||||
public void resolvesPropertyPathWithSingleUppercaseLetterPropertyEnding() {
|
||||
assertThat(from("categoryB", Product.class).toDotPath()).isEqualTo("categoryB");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1304
|
||||
public void resolvesPropertyPathWithUppercaseLettersPropertyEnding() {
|
||||
assertThat(from("categoryABId", Product.class).toDotPath()).isEqualTo("categoryAB.id");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1304
|
||||
public void detectsNestedSingleCharacterProperty() {
|
||||
assertThat(from("category_B", Product.class).toDotPath()).isEqualTo("category.b");
|
||||
}
|
||||
|
||||
private class Foo {
|
||||
|
||||
String userName;
|
||||
@@ -411,4 +426,18 @@ public class PropertyPathUnitTests {
|
||||
private class Right {
|
||||
Left bar;
|
||||
}
|
||||
|
||||
// DATACMNS-1304
|
||||
private class Product {
|
||||
Category category;
|
||||
Category categoryB;
|
||||
Category categoryAB;
|
||||
}
|
||||
|
||||
private class Category {
|
||||
B b;
|
||||
String id;
|
||||
}
|
||||
|
||||
private class B {}
|
||||
}
|
||||
|
||||
@@ -601,16 +601,6 @@ public class PartTreeUnitTests {
|
||||
assertThat(tree.hasPredicate()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1304
|
||||
public void resolvesPropertyPathWithSingleUppercaseLetterPropertyEnding() {
|
||||
assertThat(new PartTree("findByCategoryBId", Product.class)).isNotNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1304
|
||||
public void resolvesPropertyPathWithUppercaseLettersPropertyEnding() {
|
||||
assertThat(new PartTree("findByCategoryABId", Product.class)).isNotNull();
|
||||
}
|
||||
|
||||
private static void assertLimiting(String methodName, Class<?> entityType, boolean limiting, Integer maxResults) {
|
||||
assertLimiting(methodName, entityType, limiting, maxResults, false);
|
||||
}
|
||||
@@ -734,10 +724,6 @@ public class PartTreeUnitTests {
|
||||
Anders getAnders(); // constains And keyword
|
||||
|
||||
Category getCategory();
|
||||
|
||||
Category getCategoryB(); // contains single uppercase letter at the end
|
||||
|
||||
Category getCategoryAB(); // contains uppercase letters at the end
|
||||
}
|
||||
|
||||
interface Category {
|
||||
|
||||
Reference in New Issue
Block a user