You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by jd...@apache.org on 2026/09/30 16:24:47 UTC

(grails-core) 05/06: Close ProxyInstanceMetaClass patch coverage gaps flagged by Codecov

This is an automated email from the ASF dual-hosted git repository.

jdaugherty pushed a commit to branch chore/lint-proxy-package
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit a407d282c6d3227c3246ce90366c9c7f0085e1e5
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Sat Aug 15 19:50:30 2026 -0500

    Close ProxyInstanceMetaClass patch coverage gaps flagged by Codecov
    
    Cover the previously-untested target property/attribute cases in
    getProperty/getAttribute, the already-initiated branch of the
    class/domainClass ternary, and the remaining argument-shape branches
    of the setMetaClass special case in invokeMethod/setProperty. File is
    now fully line- and branch-covered.
    
    Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
 .../gorm/proxy/ProxyInstanceMetaClassSpec.groovy   | 89 ++++++++++++++++++++++
 1 file changed, 89 insertions(+)

diff --git a/grails-datamapping-core/src/test/groovy/org/grails/datastore/gorm/proxy/ProxyInstanceMetaClassSpec.groovy b/grails-datamapping-core/src/test/groovy/org/grails/datastore/gorm/proxy/ProxyInstanceMetaClassSpec.groovy
index f3129010eb..7ac384afe1 100644
--- a/grails-datamapping-core/src/test/groovy/org/grails/datastore/gorm/proxy/ProxyInstanceMetaClassSpec.groovy
+++ b/grails-datamapping-core/src/test/groovy/org/grails/datastore/gorm/proxy/ProxyInstanceMetaClassSpec.groovy
@@ -159,6 +159,42 @@ class ProxyInstanceMetaClassSpec extends Specification {
         0 * session.retrieve(_, _)
     }
 
+    void "invokeMethod resolves the target for setMetaClass calls with a non-MetaClass argument"() {
+        given:
+        ProxyInstanceMetaClass metaClass = newMetaClass()
+        delegate.invokeMethod(target, 'setMetaClass', ['not-a-metaclass'] as Object[]) >> null
+
+        when:
+        metaClass.invokeMethod(proxy, 'setMetaClass', ['not-a-metaclass'] as Object[])
+
+        then:
+        1 * session.retrieve(ProxyInstanceTestTarget, 11L) >> target
+    }
+
+    void "invokeMethod resolves the target for setMetaClass calls with an unexpected argument count"() {
+        given:
+        ProxyInstanceMetaClass metaClass = newMetaClass()
+        delegate.invokeMethod(target, 'setMetaClass', [] as Object[]) >> null
+
+        when:
+        metaClass.invokeMethod(proxy, 'setMetaClass', [] as Object[])
+
+        then:
+        1 * session.retrieve(ProxyInstanceTestTarget, 11L) >> target
+    }
+
+    void "invokeMethod does not resolve the target for setMetaClass with a null argument"() {
+        given:
+        ProxyInstanceMetaClass metaClass = newMetaClass()
+        delegate.invokeMethod(proxy, 'setMetaClass', [null] as Object[]) >> null
+
+        when:
+        metaClass.invokeMethod(proxy, 'setMetaClass', [null] as Object[])
+
+        then:
+        0 * session.retrieve(_, _)
+    }
+
     void "getProperty exposes proxy metadata without resolving the target"() {
         given:
         ProxyInstanceMetaClass metaClass = newMetaClass()
@@ -193,6 +229,26 @@ class ProxyInstanceMetaClassSpec extends Specification {
         propertyName << ['class', 'domainClass']
     }
 
+    void "getProperty resolves the target for the target property"() {
+        given:
+        ProxyInstanceMetaClass metaClass = newMetaClass()
+        session.retrieve(ProxyInstanceTestTarget, 11L) >> target
+
+        expect:
+        metaClass.getProperty(proxy, 'target').is(target)
+    }
+
+    void "getProperty for class/domainClass resolves the target once already initiated"() {
+        given:
+        ProxyInstanceMetaClass metaClass = newMetaClass()
+        session.retrieve(ProxyInstanceTestTarget, 11L) >> target
+        metaClass.getProxyTarget()
+        delegate.getProperty(target, 'class') >> ProxyInstanceTestTarget
+
+        expect:
+        metaClass.getProperty(proxy, 'class') == ProxyInstanceTestTarget
+    }
+
     void "getProperty resolves the target for regular properties"() {
         given:
         ProxyInstanceMetaClass metaClass = newMetaClass()
@@ -216,6 +272,30 @@ class ProxyInstanceMetaClassSpec extends Specification {
         0 * session.retrieve(_, _)
     }
 
+    void "setProperty does not resolve the target when clearing the metaClass"() {
+        given:
+        ProxyInstanceMetaClass metaClass = newMetaClass()
+
+        when:
+        metaClass.setProperty(proxy, 'metaClass', null)
+
+        then:
+        1 * delegate.setProperty(proxy, 'metaClass', null)
+        0 * session.retrieve(_, _)
+    }
+
+    void "setProperty resolves the target when setting metaClass to a non-MetaClass value"() {
+        given:
+        ProxyInstanceMetaClass metaClass = newMetaClass()
+
+        when:
+        metaClass.setProperty(proxy, 'metaClass', 'not-a-metaclass')
+
+        then:
+        1 * session.retrieve(ProxyInstanceTestTarget, 11L) >> target
+        1 * delegate.setProperty(target, 'metaClass', 'not-a-metaclass')
+    }
+
     void "setProperty resolves the target for regular properties"() {
         given:
         ProxyInstanceMetaClass metaClass = newMetaClass()
@@ -242,6 +322,15 @@ class ProxyInstanceMetaClassSpec extends Specification {
         0 * session.retrieve(_, _)
     }
 
+    void "getAttribute resolves the target for the target attribute"() {
+        given:
+        ProxyInstanceMetaClass metaClass = newMetaClass()
+        session.retrieve(ProxyInstanceTestTarget, 11L) >> target
+
+        expect:
+        metaClass.getAttribute(proxy, 'target').is(target)
+    }
+
     void "getAttribute resolves the target for other attributes"() {
         given:
         ProxyInstanceMetaClass metaClass = newMetaClass()