You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/04/09 14:52:59 UTC
(grails-core) 18/40: test(h7): expand HibernateProxyHandler coverage to 28 tests
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch 8.0.x-hibernate7-dev
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 217e1e372cf0ae724d507510dc8995a3781909de
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Tue Apr 7 17:13:50 2026 -0500
test(h7): expand HibernateProxyHandler coverage to 28 tests
- EntityProxy branches: isInitialized, unwrap (getTarget), getIdentifier (getProxyKey), initialize
- GroovyProxy branch: initialize calls proxyMc.getProxyTarget
- GroovyProxy branch: getIdentifier returns id via GroovyProxyInterceptorLogic
- getAssociationProxy catch(RuntimeException) → returns null
Co-authored-by: Copilot <22...@users.noreply.github.com>
---
.../proxy/HibernateProxyHandler7Spec.groovy | 92 ++++++++++++++++++++++
1 file changed, 92 insertions(+)
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler7Spec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler7Spec.groovy
index 9b37eb8710..e42057daa1 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler7Spec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler7Spec.groovy
@@ -382,4 +382,96 @@ class HibernateProxyHandler7Spec extends HibernateGormDatastoreSpec {
expect:
proxyHandler.getIdentifier(location) == null
}
+
+ void "test isInitialized delegates to EntityProxy"() {
+ given:
+ def ep = Mock(org.grails.datastore.mapping.proxy.EntityProxy) {
+ isInitialized() >> true
+ }
+
+ expect:
+ proxyHandler.isInitialized(ep)
+ }
+
+ void "test unwrap delegates to EntityProxy.getTarget"() {
+ given:
+ Location target = new Location(name: "Target")
+ def ep = Mock(org.grails.datastore.mapping.proxy.EntityProxy) {
+ getTarget() >> target
+ }
+
+ expect:
+ proxyHandler.unwrap(ep).is(target)
+ }
+
+ void "test getIdentifier delegates to EntityProxy.getProxyKey"() {
+ given:
+ def ep = Mock(org.grails.datastore.mapping.proxy.EntityProxy) {
+ getProxyKey() >> 42L
+ }
+
+ expect:
+ proxyHandler.getIdentifier(ep) == 42L
+ }
+
+ void "test initialize delegates to EntityProxy.initialize"() {
+ given:
+ def ep = Mock(org.grails.datastore.mapping.proxy.EntityProxy)
+
+ when:
+ proxyHandler.initialize(ep)
+
+ then:
+ 1 * ep.initialize()
+ }
+
+ void "test initialize on Groovy proxy calls proxyTarget"() {
+ given:
+ def originalFactory = manager.session.mappingContext.proxyFactory
+ manager.session.mappingContext.proxyFactory = new GroovyProxyFactory()
+ Location location = new Location(name: "Init Test").save(flush: true)
+ manager.session.clear()
+ manager.hibernateSession.clear()
+
+ Location proxyLocation = Location.proxy(location.id)
+
+ expect:
+ !proxyHandler.isInitialized(proxyLocation)
+
+ when:
+ proxyHandler.initialize(proxyLocation)
+
+ then:
+ proxyHandler.isInitialized(proxyLocation)
+
+ cleanup:
+ manager.session.mappingContext.proxyFactory = originalFactory
+ }
+
+ void "test getAssociationProxy returns null on RuntimeException"() {
+ expect:
+ proxyHandler.getAssociationProxy(new ProxyHandlerThrowingObj(), "anything") == null
+ }
+
+ void "test getIdentifier for Groovy proxy returns id via GroovyProxyInterceptorLogic"() {
+ given:
+ def originalFactory = manager.session.mappingContext.proxyFactory
+ manager.session.mappingContext.proxyFactory = new GroovyProxyFactory()
+ Location location = new Location(name: "Id Test").save(flush: true)
+ Long locationId = location.id
+ manager.session.clear()
+ manager.hibernateSession.clear()
+
+ Location proxyLocation = Location.proxy(locationId)
+
+ expect:
+ proxyHandler.getIdentifier(proxyLocation) == locationId
+
+ cleanup:
+ manager.session.mappingContext.proxyFactory = originalFactory
+ }
+}
+
+class ProxyHandlerThrowingObj {
+ def getAnything() { throw new RuntimeException("deliberate failure") }
}