Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Reduce test element visibility, remove unused constant.

See #2472
  • Loading branch information
mp911de committed Oct 19, 2021
1 parent 7c18862 commit 69397a1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}]*$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
* @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);

Expand All @@ -49,7 +49,7 @@ public void parsesSimplePropertyCorrectly() throws Exception {
}

@Test
public void parsesPathPropertyCorrectly() throws Exception {
void parsesPathPropertyCorrectly() {

PropertyPath reference = PropertyPath.from("userName", Bar.class);
assertThat(reference.hasNext()).isTrue();
Expand All @@ -58,15 +58,15 @@ public void parsesPathPropertyCorrectly() throws Exception {
}

@Test
public void prefersLongerMatches() throws Exception {
void prefersLongerMatches() {

PropertyPath reference = PropertyPath.from("userName", Sample.class);
assertThat(reference.hasNext()).isFalse();
assertThat(reference.toDotPath()).isEqualTo("userName");
}

@Test
public void testname() throws Exception {
void testname() {

PropertyPath reference = PropertyPath.from("userName", Sample2.class);
assertThat(reference.getSegment()).isEqualTo("user");
Expand All @@ -75,7 +75,7 @@ public void testname() throws Exception {
}

@Test
public void prefersExplicitPaths() throws Exception {
void prefersExplicitPaths() {

PropertyPath reference = PropertyPath.from("user_name", Sample.class);
assertThat(reference.getSegment()).isEqualTo("user");
Expand All @@ -84,7 +84,7 @@ public void prefersExplicitPaths() throws Exception {
}

@Test
public void handlesGenericsCorrectly() throws Exception {
void handlesGenericsCorrectly() {

PropertyPath reference = PropertyPath.from("usersName", Bar.class);
assertThat(reference.getSegment()).isEqualTo("users");
Expand All @@ -94,7 +94,7 @@ public void handlesGenericsCorrectly() throws Exception {
}

@Test
public void handlesMapCorrectly() throws Exception {
void handlesMapCorrectly() {

PropertyPath reference = PropertyPath.from("userMapName", Bar.class);
assertThat(reference.getSegment()).isEqualTo("userMap");
Expand All @@ -104,7 +104,7 @@ public void handlesMapCorrectly() throws Exception {
}

@Test
public void handlesArrayCorrectly() throws Exception {
void handlesArrayCorrectly() {

PropertyPath reference = PropertyPath.from("userArrayName", Bar.class);
assertThat(reference.getSegment()).isEqualTo("userArray");
Expand All @@ -114,7 +114,7 @@ public void handlesArrayCorrectly() throws Exception {
}

@Test
public void handlesInvalidCollectionCompountTypeProperl() {
void handlesInvalidCollectionCompountTypeProperl() {

try {
PropertyPath.from("usersMame", Bar.class);
Expand All @@ -126,7 +126,7 @@ public void handlesInvalidCollectionCompountTypeProperl() {
}

@Test
public void handlesInvalidMapValueTypeProperly() {
void handlesInvalidMapValueTypeProperly() {

assertThatExceptionOfType(PropertyReferenceException.class)//
.isThrownBy(() -> PropertyPath.from("userMapMame", Bar.class))//
Expand All @@ -135,7 +135,7 @@ public void handlesInvalidMapValueTypeProperly() {
}

@Test
public void findsNested() {
void findsNested() {

PropertyPath from = PropertyPath.from("barUserName", Sample.class);

Expand All @@ -144,7 +144,7 @@ public void findsNested() {
}

@Test // DATACMNS-45
public void handlesEmptyUnderscoresCorrectly() {
void handlesEmptyUnderscoresCorrectly() {

PropertyPath propertyPath = PropertyPath.from("_foo", Sample2.class);
assertThat(propertyPath.getSegment()).isEqualTo("_foo");
Expand All @@ -155,7 +155,7 @@ public void handlesEmptyUnderscoresCorrectly() {
}

@Test
public void supportsDotNotationAsWell() {
void supportsDotNotationAsWell() {

PropertyPath propertyPath = PropertyPath.from("bar.userMap.name", Sample.class);

Expand All @@ -165,7 +165,7 @@ public void supportsDotNotationAsWell() {
}

@Test
public void returnsCorrectIteratorForSingleElement() {
void returnsCorrectIteratorForSingleElement() {

PropertyPath propertyPath = PropertyPath.from("userName", Foo.class);

Expand All @@ -176,7 +176,7 @@ public void returnsCorrectIteratorForSingleElement() {
}

@Test
public void returnsCorrectIteratorForMultipleElement() {
void returnsCorrectIteratorForMultipleElement() {

PropertyPath propertyPath = PropertyPath.from("user.name", Bar.class);

Expand All @@ -189,59 +189,59 @@ public void returnsCorrectIteratorForMultipleElement() {
}

@Test // DATACMNS-139
public void rejectsInvalidPropertyWithLeadingUnderscore() {
void rejectsInvalidPropertyWithLeadingUnderscore() {

assertThatExceptionOfType(PropertyReferenceException.class)//
.isThrownBy(() -> PropertyPath.from("_id", Foo.class))//
.withMessageContaining("property _id");
}

@Test // DATACMNS-139
public void rejectsNestedInvalidPropertyWithLeadingUnderscore() {
void rejectsNestedInvalidPropertyWithLeadingUnderscore() {

assertThatExceptionOfType(PropertyReferenceException.class)//
.isThrownBy(() -> PropertyPath.from("_foo_id", Sample2.class))//
.withMessageContaining("property id");
}

@Test // DATACMNS-139
public void rejectsNestedInvalidPropertyExplictlySplitWithLeadingUnderscore() {
void rejectsNestedInvalidPropertyExplictlySplitWithLeadingUnderscore() {

assertThatExceptionOfType(PropertyReferenceException.class)//
.isThrownBy(() -> PropertyPath.from("_foo__id", Sample2.class))//
.withMessageContaining("property _id");
}

@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();
assertThat(from("sampleBar1foo", SampleHolder.class)).isNotNull();
}

@Test
public void rejectsInvalidProperty() {
void rejectsInvalidProperty() {

assertThatExceptionOfType(PropertyReferenceException.class)//
.isThrownBy(() -> from("_foo_id", Sample2.class))//
.matches(e -> e.getBaseProperty().getSegment().equals("_foo"));
}

@Test
public void samePathsEqual() {
void samePathsEqual() {

PropertyPath left = PropertyPath.from("user.name", Bar.class);
PropertyPath right = PropertyPath.from("user.name", Bar.class);
Expand All @@ -257,7 +257,7 @@ public void samePathsEqual() {
}

@Test
public void hashCodeTests() {
void hashCodeTests() {

PropertyPath left = PropertyPath.from("user.name", Bar.class);
PropertyPath right = PropertyPath.from("user.name", Bar.class);
Expand All @@ -269,7 +269,7 @@ public void hashCodeTests() {
}

@Test // DATACMNS-257
public void findsAllUppercaseProperty() {
void findsAllUppercaseProperty() {

PropertyPath path = PropertyPath.from("UUID", Foo.class);

Expand All @@ -278,7 +278,7 @@ public void findsAllUppercaseProperty() {
}

@Test // DATACMNS-257
public void findsNestedAllUppercaseProperty() {
void findsNestedAllUppercaseProperty() {

PropertyPath path = PropertyPath.from("_fooUUID", Sample2.class);

Expand All @@ -289,7 +289,7 @@ public void findsNestedAllUppercaseProperty() {
}

@Test // DATACMNS-381
public void exposesPreviouslyReferencedPathInExceptionMessage() {
void exposesPreviouslyReferencedPathInExceptionMessage() {

assertThatExceptionOfType(PropertyReferenceException.class).isThrownBy(() -> from("userNameBar", Bar.class)) //
.withMessageContaining("bar") // missing variable
Expand All @@ -298,34 +298,34 @@ public void exposesPreviouslyReferencedPathInExceptionMessage() {
}

@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)) //
Expand All @@ -335,14 +335,14 @@ public void includesResolvedPathInExceptionMessage() {
}

@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);

Expand All @@ -352,22 +352,22 @@ public void preservesUnderscoresForQuotedNames() {
}

@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")) //
Expand All @@ -376,7 +376,7 @@ public void rejectsNonExistentNestedPath() {
}

@Test // DATACMNS-1285
public void rejectsTooLongPath() {
void rejectsTooLongPath() {

String source = "foo.bar";

Expand All @@ -393,17 +393,17 @@ public void rejectsTooLongPath() {
}

@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");
}

Expand Down

0 comments on commit 69397a1

Please sign in to comment.