Polishing.

Reduce test element visibility, remove unused constant.

See #2472
This commit is contained in:
Mark Paluch
2021-10-19 14:30:57 +02:00
parent 7c1886201c
commit 69397a11b2
2 changed files with 44 additions and 45 deletions

View File

@@ -47,7 +47,6 @@ public class PropertyPath implements Streamable<PropertyPath> {
private static final String PARSE_DEPTH_EXCEEDED = "Trying to parse a path with depth greater than 1000! This has been disabled for security reasons to prevent parsing overflows.";
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 static final Pattern SPLITTER_FOR_QUOTED = Pattern.compile("(?:[%s]?([%s]*?[^%s]+))".replaceAll("%s", "\\."));
private static final Pattern NESTED_PROPERTY_PATTERN = Pattern.compile("\\p{Lu}[\\p{Ll}\\p{Nd}]*$");

View File

@@ -36,10 +36,10 @@ import org.springframework.data.util.TypeInformation;
* @author Mark Paluch
*/
@SuppressWarnings("unused")
public class PropertyPathUnitTests {
class PropertyPathUnitTests {
@Test
public void parsesSimplePropertyCorrectly() throws Exception {
void parsesSimplePropertyCorrectly() {
PropertyPath reference = PropertyPath.from("userName", Foo.class);
@@ -49,7 +49,7 @@ public class PropertyPathUnitTests {
}
@Test
public void parsesPathPropertyCorrectly() throws Exception {
void parsesPathPropertyCorrectly() {
PropertyPath reference = PropertyPath.from("userName", Bar.class);
assertThat(reference.hasNext()).isTrue();
@@ -58,7 +58,7 @@ public class PropertyPathUnitTests {
}
@Test
public void prefersLongerMatches() throws Exception {
void prefersLongerMatches() {
PropertyPath reference = PropertyPath.from("userName", Sample.class);
assertThat(reference.hasNext()).isFalse();
@@ -66,7 +66,7 @@ public class PropertyPathUnitTests {
}
@Test
public void testname() throws Exception {
void testname() {
PropertyPath reference = PropertyPath.from("userName", Sample2.class);
assertThat(reference.getSegment()).isEqualTo("user");
@@ -75,7 +75,7 @@ public class PropertyPathUnitTests {
}
@Test
public void prefersExplicitPaths() throws Exception {
void prefersExplicitPaths() {
PropertyPath reference = PropertyPath.from("user_name", Sample.class);
assertThat(reference.getSegment()).isEqualTo("user");
@@ -84,7 +84,7 @@ public class PropertyPathUnitTests {
}
@Test
public void handlesGenericsCorrectly() throws Exception {
void handlesGenericsCorrectly() {
PropertyPath reference = PropertyPath.from("usersName", Bar.class);
assertThat(reference.getSegment()).isEqualTo("users");
@@ -94,7 +94,7 @@ public class PropertyPathUnitTests {
}
@Test
public void handlesMapCorrectly() throws Exception {
void handlesMapCorrectly() {
PropertyPath reference = PropertyPath.from("userMapName", Bar.class);
assertThat(reference.getSegment()).isEqualTo("userMap");
@@ -104,7 +104,7 @@ public class PropertyPathUnitTests {
}
@Test
public void handlesArrayCorrectly() throws Exception {
void handlesArrayCorrectly() {
PropertyPath reference = PropertyPath.from("userArrayName", Bar.class);
assertThat(reference.getSegment()).isEqualTo("userArray");
@@ -114,7 +114,7 @@ public class PropertyPathUnitTests {
}
@Test
public void handlesInvalidCollectionCompountTypeProperl() {
void handlesInvalidCollectionCompountTypeProperl() {
try {
PropertyPath.from("usersMame", Bar.class);
@@ -126,7 +126,7 @@ public class PropertyPathUnitTests {
}
@Test
public void handlesInvalidMapValueTypeProperly() {
void handlesInvalidMapValueTypeProperly() {
assertThatExceptionOfType(PropertyReferenceException.class)//
.isThrownBy(() -> PropertyPath.from("userMapMame", Bar.class))//
@@ -135,7 +135,7 @@ public class PropertyPathUnitTests {
}
@Test
public void findsNested() {
void findsNested() {
PropertyPath from = PropertyPath.from("barUserName", Sample.class);
@@ -144,7 +144,7 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-45
public void handlesEmptyUnderscoresCorrectly() {
void handlesEmptyUnderscoresCorrectly() {
PropertyPath propertyPath = PropertyPath.from("_foo", Sample2.class);
assertThat(propertyPath.getSegment()).isEqualTo("_foo");
@@ -155,7 +155,7 @@ public class PropertyPathUnitTests {
}
@Test
public void supportsDotNotationAsWell() {
void supportsDotNotationAsWell() {
PropertyPath propertyPath = PropertyPath.from("bar.userMap.name", Sample.class);
@@ -165,7 +165,7 @@ public class PropertyPathUnitTests {
}
@Test
public void returnsCorrectIteratorForSingleElement() {
void returnsCorrectIteratorForSingleElement() {
PropertyPath propertyPath = PropertyPath.from("userName", Foo.class);
@@ -176,7 +176,7 @@ public class PropertyPathUnitTests {
}
@Test
public void returnsCorrectIteratorForMultipleElement() {
void returnsCorrectIteratorForMultipleElement() {
PropertyPath propertyPath = PropertyPath.from("user.name", Bar.class);
@@ -189,7 +189,7 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-139
public void rejectsInvalidPropertyWithLeadingUnderscore() {
void rejectsInvalidPropertyWithLeadingUnderscore() {
assertThatExceptionOfType(PropertyReferenceException.class)//
.isThrownBy(() -> PropertyPath.from("_id", Foo.class))//
@@ -197,7 +197,7 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-139
public void rejectsNestedInvalidPropertyWithLeadingUnderscore() {
void rejectsNestedInvalidPropertyWithLeadingUnderscore() {
assertThatExceptionOfType(PropertyReferenceException.class)//
.isThrownBy(() -> PropertyPath.from("_foo_id", Sample2.class))//
@@ -205,7 +205,7 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-139
public void rejectsNestedInvalidPropertyExplictlySplitWithLeadingUnderscore() {
void rejectsNestedInvalidPropertyExplictlySplitWithLeadingUnderscore() {
assertThatExceptionOfType(PropertyReferenceException.class)//
.isThrownBy(() -> PropertyPath.from("_foo__id", Sample2.class))//
@@ -213,19 +213,19 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS 158
public void rejectsInvalidPathsContainingDigits() {
void rejectsInvalidPathsContainingDigits() {
assertThatExceptionOfType(PropertyReferenceException.class)
.isThrownBy(() -> from("PropertyThatWillFail4Sure", Foo.class));
}
@Test // GH-2472
public void acceptsValidPathWithDigits() {
void acceptsValidPathWithDigits() {
assertThat(from("bar1", Sample.class)).isNotNull();
assertThat(from("bar1foo", Sample.class)).isNotNull();
}
@Test // GH-2472
public void acceptsValidNestedPathWithDigits() {
void acceptsValidNestedPathWithDigits() {
assertThat(from("sample.bar1", SampleHolder.class)).isNotNull();
assertThat(from("sample.bar1foo", SampleHolder.class)).isNotNull();
assertThat(from("sampleBar1", SampleHolder.class)).isNotNull();
@@ -233,7 +233,7 @@ public class PropertyPathUnitTests {
}
@Test
public void rejectsInvalidProperty() {
void rejectsInvalidProperty() {
assertThatExceptionOfType(PropertyReferenceException.class)//
.isThrownBy(() -> from("_foo_id", Sample2.class))//
@@ -241,7 +241,7 @@ public class PropertyPathUnitTests {
}
@Test
public void samePathsEqual() {
void samePathsEqual() {
PropertyPath left = PropertyPath.from("user.name", Bar.class);
PropertyPath right = PropertyPath.from("user.name", Bar.class);
@@ -257,7 +257,7 @@ public class PropertyPathUnitTests {
}
@Test
public void hashCodeTests() {
void hashCodeTests() {
PropertyPath left = PropertyPath.from("user.name", Bar.class);
PropertyPath right = PropertyPath.from("user.name", Bar.class);
@@ -269,7 +269,7 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-257
public void findsAllUppercaseProperty() {
void findsAllUppercaseProperty() {
PropertyPath path = PropertyPath.from("UUID", Foo.class);
@@ -278,7 +278,7 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-257
public void findsNestedAllUppercaseProperty() {
void findsNestedAllUppercaseProperty() {
PropertyPath path = PropertyPath.from("_fooUUID", Sample2.class);
@@ -289,7 +289,7 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-381
public void exposesPreviouslyReferencedPathInExceptionMessage() {
void exposesPreviouslyReferencedPathInExceptionMessage() {
assertThatExceptionOfType(PropertyReferenceException.class).isThrownBy(() -> from("userNameBar", Bar.class)) //
.withMessageContaining("bar") // missing variable
@@ -298,34 +298,34 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-387
public void rejectsNullSource() {
void rejectsNullSource() {
assertThatIllegalArgumentException().isThrownBy(() -> from(null, Foo.class));
}
@Test // DATACMNS-387
public void rejectsEmptySource() {
void rejectsEmptySource() {
assertThatIllegalArgumentException().isThrownBy(() -> from("", Foo.class));
}
@Test // DATACMNS-387
public void rejectsNullClass() {
void rejectsNullClass() {
assertThatIllegalArgumentException().isThrownBy(() -> from("foo", (Class<?>) null));
}
@Test // DATACMNS-387
public void rejectsNullTypeInformation() {
void rejectsNullTypeInformation() {
assertThatIllegalArgumentException().isThrownBy(() -> from("foo", (TypeInformation<?>) null));
}
@Test // DATACMNS-546
public void returnsCompletePathIfResolutionFailedCompletely() {
void returnsCompletePathIfResolutionFailedCompletely() {
assertThatExceptionOfType(PropertyReferenceException.class) //
.isThrownBy(() -> from("somethingDifferent", Foo.class)).withMessageContaining("somethingDifferent");
}
@Test // DATACMNS-546
public void includesResolvedPathInExceptionMessage() {
void includesResolvedPathInExceptionMessage() {
assertThatExceptionOfType(PropertyReferenceException.class) //
.isThrownBy(() -> from("userFooName", Bar.class)) //
@@ -335,14 +335,14 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-703
public void includesPropertyHintsOnTypos() {
void includesPropertyHintsOnTypos() {
assertThatExceptionOfType(PropertyReferenceException.class) //
.isThrownBy(() -> from("userAme", Foo.class)).withMessageContaining("userName");
}
@Test // DATACMNS-867
public void preservesUnderscoresForQuotedNames() {
void preservesUnderscoresForQuotedNames() {
PropertyPath path = from(Pattern.quote("var_name_with_underscore"), Foo.class);
@@ -352,22 +352,22 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-1120
public void cachesPropertyPathsByPathAndType() {
void cachesPropertyPathsByPathAndType() {
assertThat(from("userName", Foo.class)).isSameAs(from("userName", Foo.class));
}
@Test // DATACMNS-1198
public void exposesLeafPropertyType() {
void exposesLeafPropertyType() {
assertThat(from("user.name", Bar.class).getLeafType()).isEqualTo(String.class);
}
@Test // DATACMNS-1199
public void createsNestedPropertyPath() {
void createsNestedPropertyPath() {
assertThat(from("user", Bar.class).nested("name")).isEqualTo(from("user.name", Bar.class));
}
@Test // DATACMNS-1199
public void rejectsNonExistentNestedPath() {
void rejectsNonExistentNestedPath() {
assertThatExceptionOfType(PropertyReferenceException.class) //
.isThrownBy(() -> from("user", Bar.class).nested("nonexistant")) //
@@ -376,7 +376,7 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-1285
public void rejectsTooLongPath() {
void rejectsTooLongPath() {
String source = "foo.bar";
@@ -393,17 +393,17 @@ public class PropertyPathUnitTests {
}
@Test // DATACMNS-1304
public void resolvesPropertyPathWithSingleUppercaseLetterPropertyEnding() {
void resolvesPropertyPathWithSingleUppercaseLetterPropertyEnding() {
assertThat(from("categoryB", Product.class).toDotPath()).isEqualTo("categoryB");
}
@Test // DATACMNS-1304
public void resolvesPropertyPathWithUppercaseLettersPropertyEnding() {
void resolvesPropertyPathWithUppercaseLettersPropertyEnding() {
assertThat(from("categoryABId", Product.class).toDotPath()).isEqualTo("categoryAB.id");
}
@Test // DATACMNS-1304
public void detectsNestedSingleCharacterProperty() {
void detectsNestedSingleCharacterProperty() {
assertThat(from("category_B", Product.class).toDotPath()).isEqualTo("category.b");
}