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:53 UTC

(grails-core) 12/40: test(h7): expand HibernateGormStaticApi coverage to 61 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 103c88bf68c9d1939a04ee297e7b72c12c02c9c3
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Tue Apr 7 15:14:14 2026 -0500

    test(h7): expand HibernateGormStaticApi coverage to 61 tests
    
    Added 12 new tests covering:
    - null-id guard branches: get, read, load, proxy, exists all return null/false
    - first/last on empty table returns null
    - findWhere/findAllWhere with empty map returns null/empty
    - list with max parameter returns HibernatePagedResultList
    - convertIdentifier non-parseable String -> null
    - getQualifier returns explicit qualifier set in constructor
    
    Co-authored-by: Copilot <22...@users.noreply.github.com>
---
 JACOCO_COVERAGE_VIOLATIONS.md                      |   2 +-
 .../hibernate/HibernateGormStaticApiSpec.groovy    | 101 +++++++++++++++++++++
 2 files changed, 102 insertions(+), 1 deletion(-)

diff --git a/JACOCO_COVERAGE_VIOLATIONS.md b/JACOCO_COVERAGE_VIOLATIONS.md
index 44cf07bac2..38500544a1 100644
--- a/JACOCO_COVERAGE_VIOLATIONS.md
+++ b/JACOCO_COVERAGE_VIOLATIONS.md
@@ -33,7 +33,7 @@ Generated on: 2026-04-06 16:49:20
 | org.grails.orm.hibernate.HibernateDatastore.ChildHibernateDatastore | 86.36% | X |
 | X org.grails.orm.hibernate.proxy.GrailsProxyFactoryFactory | 86.67% |
 | X org.grails.orm.hibernate.cfg.domainbinding.hibernate.HibernateToManyProperty | 86.77% |
-| org.grails.orm.hibernate.HibernateGormStaticApi | 86.87% |
+| X org.grails.orm.hibernate.HibernateGormStaticApi | 86.87% |
 | org.grails.orm.hibernate.cfg.domainbinding.util.CascadeBehaviorFetcher | 86.96% | X
 | X org.grails.orm.hibernate.cfg.PropertyDefinitionDelegate | 87.60% |
 | X org.grails.orm.hibernate.cfg.IdentityEnumType.BidiEnumMap | 87.62% |
diff --git a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
index 116b59943b..a793f00fc7 100644
--- a/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
+++ b/grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/HibernateGormStaticApiSpec.groovy
@@ -710,6 +710,107 @@ class HibernateGormStaticApiSpec extends HibernateGormDatastoreSpec {
         c.name == 'Manchester United'
     }
 
+    // -------------------------------------------------------------------------
+    // null-id guard branches
+    // -------------------------------------------------------------------------
+
+    void "get returns null for null id"() {
+        expect:
+        Club.get(null) == null
+    }
+
+    void "read returns null for null id"() {
+        expect:
+        Club.read(null) == null
+    }
+
+    void "load returns null for non-convertible id"() {
+        expect: "String that can't be converted to Long makes convertIdentifier return null"
+        Club.load("not-a-long") == null
+    }
+
+    void "proxy returns null for null id"() {
+        expect:
+        Club.proxy(null) == null
+    }
+
+    void "exists returns false for non-convertible id"() {
+        expect:
+        !Club.exists("not-a-long")
+    }
+
+    // -------------------------------------------------------------------------
+    // first / last on empty table
+    // -------------------------------------------------------------------------
+
+    void "first returns null when table is empty"() {
+        expect:
+        Club.first() == null
+    }
+
+    void "last returns null when table is empty"() {
+        expect:
+        Club.last() == null
+    }
+
+    // -------------------------------------------------------------------------
+    // findWhere / findAllWhere with empty map
+    // -------------------------------------------------------------------------
+
+    void "findWhere with empty queryMap returns null"() {
+        expect:
+        Club.findWhere([:]) == null
+    }
+
+    void "findAllWhere with empty queryMap returns null"() {
+        expect:
+        Club.findAllWhere([:]) == null
+    }
+
+    // -------------------------------------------------------------------------
+    // list with max — returns HibernatePagedResultList
+    // -------------------------------------------------------------------------
+
+    void "list with max parameter returns a HibernatePagedResultList"() {
+        given:
+        setupTestData()
+
+        when:
+        def result = Club.list(max: 2)
+
+        then:
+        result instanceof org.grails.orm.hibernate.query.HibernatePagedResultList
+        result.size() <= 2
+    }
+
+    // -------------------------------------------------------------------------
+    // convertIdentifier — convert throws (non-parseable String → Long)
+    // -------------------------------------------------------------------------
+
+    void "get with non-parseable String id returns null via convertIdentifier"() {
+        expect: "conversion from 'notALong' to Long throws internally, returns null"
+        Club.get("notALong") == null
+    }
+
+    // -------------------------------------------------------------------------
+    // getQualifier — field set explicitly
+    // -------------------------------------------------------------------------
+
+    void "getQualifier returns the explicit qualifier when set in constructor"() {
+        when:
+        def api = new HibernateGormStaticApi<Club>(
+                Club,
+                manager.hibernateDatastore,
+                [],
+                Thread.currentThread().contextClassLoader,
+                null,
+                "secondary"
+        )
+
+        then:
+        api.getQualifier() == "secondary"
+    }
+
     protected void setupTestData() {
         new Club(name: "Barcelona").save()
         new Club(name: "Arsenal").save()