Skip to content

Commit

Permalink
improve format of error messages relating to getters/setters
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Feb 3, 2024
1 parent 1f6564d commit dc9a997
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ public static Method findGetterMethod(Class containerClass, String propertyName)
throw new PropertyNotFoundException(
String.format(
Locale.ROOT,
"Could not locate getter method for property [%s#%s]",
containerClass.getName(),
propertyName
"Could not locate getter method for property '%s' of class '%s'",
propertyName,
containerClass.getName()
)
);
}
Expand Down Expand Up @@ -608,12 +608,11 @@ public static void checkGetAndIsVariants(
throw new MappingException(
String.format(
Locale.ROOT,
"In trying to locate getter for property [%s], Class [%s] defined " +
"both a `get` [%s] and `is` [%s] variant",
propertyName,
"Class '%s' declares both 'get' [%s] and 'is' [%s] variants of getter for property '%s'",
containerClass.getName(),
getMethod.toString(),
isMethod.toString()
getMethod,
isMethod,
propertyName
)
);
}
Expand Down Expand Up @@ -731,9 +730,9 @@ public static Method findSetterMethod(final Class containerClass, final String p
throw new PropertyNotFoundException(
String.format(
Locale.ROOT,
"Could not locate setter method for property [%s#%s]",
containerClass.getName(),
propertyName
"Could not locate setter method for property '%s' of class '%s'",
propertyName,
containerClass.getName()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,11 @@ private static void checkIsMethodVariant(
throw new MappingException(
String.format(
Locale.ROOT,
"In trying to locate getter for property [%s], Class [%s] defined " +
"both a `get` [%s] and `is` [%s] variant",
propertyName,
"Class '%s' declares both 'get' [%s] and 'is' [%s] variants of getter for property '%s'",
containerClass.getName(),
method.toString(),
isMethodVariant.toString()
isMethodVariant,
propertyName
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.BeforeClass;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void testHbmXml() {
fail( "Expecting a failure" );
}
catch (MappingException e) {
assertThat( e.getMessage(), startsWith( "In trying to locate getter for property [id]" ) );
assertThat( e.getMessage(), endsWith( "variants of getter for property 'id'" ) );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.service.ServiceRegistry;
Expand Down Expand Up @@ -64,7 +63,8 @@ public void testEnhancedClassMissesSetterForProperty() {
}
catch (MappingException e) {
assertEquals(
"Could not locate setter method for property [" + EntityWithMissingSetter.class.getName() + "#name]",
"Could not locate setter method for property 'name' of class '"
+ EntityWithMissingSetter.class.getName() + "'",
e.getMessage()
);
}
Expand Down

0 comments on commit dc9a997

Please sign in to comment.