From e14c870e73f00b0aff842105fa758d8d0d2b4e65 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 25 Jan 2022 14:33:04 +0100 Subject: [PATCH] Refine `PropertyReferenceException` message. Use single-quotes to indicate which elements belong to the underlying type and which are part of the textual message. Closes #2395 --- .../data/mapping/PropertyReferenceException.java | 6 +++--- .../data/mapping/PropertyPathUnitTests.java | 12 ++++++------ .../support/RepositoryFactorySupportUnitTests.java | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/springframework/data/mapping/PropertyReferenceException.java b/src/main/java/org/springframework/data/mapping/PropertyReferenceException.java index 42ef140d7..7f2dc67b0 100644 --- a/src/main/java/org/springframework/data/mapping/PropertyReferenceException.java +++ b/src/main/java/org/springframework/data/mapping/PropertyReferenceException.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,8 @@ import org.springframework.util.StringUtils; public class PropertyReferenceException extends RuntimeException { private static final long serialVersionUID = -5254424051438976570L; - private static final String ERROR_TEMPLATE = "No property %s found for type %s!"; - private static final String HINTS_TEMPLATE = " Did you mean %s?"; + private static final String ERROR_TEMPLATE = "No property '%s' found for type '%s'!"; + private static final String HINTS_TEMPLATE = " Did you mean '%s'?"; private final String propertyName; private final TypeInformation type; diff --git a/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java b/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java index 7e9e94e8a..52fe8c8f4 100755 --- a/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java @@ -188,28 +188,28 @@ class PropertyPathUnitTests { assertThat(iterator.hasNext()).isFalse(); } - @Test // DATACMNS-139 + @Test // DATACMNS-139, GH-2395 void rejectsInvalidPropertyWithLeadingUnderscore() { assertThatExceptionOfType(PropertyReferenceException.class)// .isThrownBy(() -> PropertyPath.from("_id", Foo.class))// - .withMessageContaining("property _id"); + .withMessageContaining("property '_id'"); } - @Test // DATACMNS-139 + @Test // DATACMNS-139, GH-2395 void rejectsNestedInvalidPropertyWithLeadingUnderscore() { assertThatExceptionOfType(PropertyReferenceException.class)// .isThrownBy(() -> PropertyPath.from("_foo_id", Sample2.class))// - .withMessageContaining("property id"); + .withMessageContaining("property 'id'"); } - @Test // DATACMNS-139 + @Test // DATACMNS-139, GH-2395 void rejectsNestedInvalidPropertyExplictlySplitWithLeadingUnderscore() { assertThatExceptionOfType(PropertyReferenceException.class)// .isThrownBy(() -> PropertyPath.from("_foo__id", Sample2.class))// - .withMessageContaining("property _id"); + .withMessageContaining("property '_id'"); } @Test // DATACMNS 158 diff --git a/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java index f4e547805..be9beae0b 100755 --- a/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java @@ -453,7 +453,7 @@ class RepositoryFactorySupportUnitTests { .hasMessageContaining("does not support Reactive Query by Example"); } - @Test // GH-2341 + @Test // GH-2341, GH-2395 void derivedQueryMethodCannotBeImplemented() { DummyRepositoryFactory factory = new DummyRepositoryFactory(backingRepo) { @@ -469,7 +469,7 @@ class RepositoryFactorySupportUnitTests { assertThatThrownBy(() -> factory.getRepository(WithQueryMethodUsingInvalidProperty.class)) .isInstanceOf(QueryCreationException.class).hasMessageContaining("findAllByName") - .hasMessageContaining("No property name found for type Object"); + .hasMessageContaining("No property 'name' found for type 'Object'"); } private ConvertingRepository prepareConvertingRepository(final Object expectedValue) {