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

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit b5b29840967899c6071b04a002b56060bd4d4a19
Author: Andrus Adamchik <[email protected]>
AuthorDate: Fri May 15 19:14:07 2026 -0400

    tests cleanup
    
    further unwinding weird tests injection
---
 .../cayenne/access/DataContextSQLTemplateIT.java   | 11 +--
 .../org/apache/cayenne/unit/CayenneTestsEnv.java   |  2 +-
 .../cayenne/unit/runtime/RuntimeCaseModule.java    |  2 -
 .../runtime/SQLTemplateCustomizerProvider.java     | 83 ----------------------
 .../cayenne/unit/util/SQLTemplateCustomizer.java   | 61 +++++++++++++---
 5 files changed, 54 insertions(+), 105 deletions(-)

diff --git 
a/cayenne/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateIT.java 
b/cayenne/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateIT.java
index 9fbc30aff..91454eedb 100644
--- 
a/cayenne/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateIT.java
+++ 
b/cayenne/src/test/java/org/apache/cayenne/access/DataContextSQLTemplateIT.java
@@ -28,31 +28,27 @@ import org.apache.cayenne.map.EntityResult;
 import org.apache.cayenne.map.SQLResult;
 import org.apache.cayenne.query.CapsStrategy;
 import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.runtime.CayenneRuntime;
 import org.apache.cayenne.test.jdbc.TableHelper;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.runtime.CayenneProjects;
 import org.apache.cayenne.unit.CayenneTestsEnv;
-import org.junit.jupiter.api.extension.RegisterExtension;
+import org.apache.cayenne.unit.runtime.CayenneProjects;
 import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import java.sql.Types;
 import java.util.Collections;
 import java.util.List;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
 
 public class DataContextSQLTemplateIT {
 
        @RegisterExtension
        static final CayenneTestsEnv env = 
CayenneTestsEnv.forProject(CayenneProjects.TESTMAP_PROJECT);
 
-       private CayenneRuntime runtime;
        protected DataContext context;
        protected SQLTemplateCustomizer sqlTemplateCustomizer;
 
@@ -62,7 +58,6 @@ public class DataContextSQLTemplateIT {
        
        @BeforeEach
        public void setUp() throws Exception {
-               runtime = env.runtime();
                context = env.context();
                sqlTemplateCustomizer = env.sqlTemplateCustomizer();
                tArtist = env.table("ARTIST", "ARTIST_ID", "ARTIST_NAME");
diff --git a/cayenne/src/test/java/org/apache/cayenne/unit/CayenneTestsEnv.java 
b/cayenne/src/test/java/org/apache/cayenne/unit/CayenneTestsEnv.java
index 6f2e05ef2..edc224aaf 100644
--- a/cayenne/src/test/java/org/apache/cayenne/unit/CayenneTestsEnv.java
+++ b/cayenne/src/test/java/org/apache/cayenne/unit/CayenneTestsEnv.java
@@ -278,6 +278,6 @@ public class CayenneTestsEnv implements BeforeEachCallback, 
AfterEachCallback {
     }
 
     public SQLTemplateCustomizer sqlTemplateCustomizer() {
-        return INJECTOR.getInstance(SQLTemplateCustomizer.class);
+        return SQLTemplateCustomizer.of(dataNode().getAdapter());
     }
 }
diff --git 
a/cayenne/src/test/java/org/apache/cayenne/unit/runtime/RuntimeCaseModule.java 
b/cayenne/src/test/java/org/apache/cayenne/unit/runtime/RuntimeCaseModule.java
index 8f564ce84..11b8dce4d 100644
--- 
a/cayenne/src/test/java/org/apache/cayenne/unit/runtime/RuntimeCaseModule.java
+++ 
b/cayenne/src/test/java/org/apache/cayenne/unit/runtime/RuntimeCaseModule.java
@@ -85,7 +85,6 @@ import 
org.apache.cayenne.unit.testcontainers.OracleContainerProvider;
 import org.apache.cayenne.unit.testcontainers.PostgresContainerProvider;
 import org.apache.cayenne.unit.testcontainers.SqlServerContainerProvider;
 import org.apache.cayenne.unit.testcontainers.TestContainerProvider;
-import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
 import org.xml.sax.XMLReader;
 
 import java.util.Calendar;
@@ -175,7 +174,6 @@ public class RuntimeCaseModule implements Module {
         // server runtime... BatchQueryBuilderFactory is hardcoded and 
whatever is placed
         // in the CoreModule is ignored
         
binder.bind(BatchTranslatorFactory.class).toProvider(RuntimeCaseBatchQueryBuilderFactoryProvider.class);
-        
binder.bind(SQLTemplateCustomizer.class).toProvider(SQLTemplateCustomizerProvider.class);
         
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
         
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
         
binder.bind(ResourceLocator.class).to(ClassLoaderResourceLocator.class);
diff --git 
a/cayenne/src/test/java/org/apache/cayenne/unit/runtime/SQLTemplateCustomizerProvider.java
 
b/cayenne/src/test/java/org/apache/cayenne/unit/runtime/SQLTemplateCustomizerProvider.java
deleted file mode 100644
index f0c7d9db7..000000000
--- 
a/cayenne/src/test/java/org/apache/cayenne/unit/runtime/SQLTemplateCustomizerProvider.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    https://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.unit.runtime;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.cayenne.ConfigurationException;
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.di.Provider;
-import org.apache.cayenne.unit.util.SQLTemplateCustomizer;
-
-public class SQLTemplateCustomizerProvider implements 
Provider<SQLTemplateCustomizer> {
-
-    @Inject
-    private DbAdapter dbAdapter;
-
-    public SQLTemplateCustomizer get() throws ConfigurationException {
-        Map<String, Map<String, String>> map = new HashMap<>();
-
-        Map<String, String> q1 = new HashMap<>();
-        q1.put(
-                "org.apache.cayenne.dba.postgres.PostgresAdapter",
-                "SELECT #result('ARTIST_ID'), RTRIM(#result('ARTIST_NAME')), "
-                        + "#result('DATE_OF_BIRTH') FROM ARTIST ORDER BY 
ARTIST_ID");
-        q1.put(
-                "org.apache.cayenne.dba.ingres.IngresAdapter",
-                "SELECT #result('ARTIST_ID'), TRIM(#result('ARTIST_NAME')), "
-                        + "#result('DATE_OF_BIRTH') FROM ARTIST ORDER BY 
ARTIST_ID");
-        q1.put(
-                "org.apache.cayenne.dba.openbase.OpenBaseAdapter",
-                "SELECT #result('ARTIST_ID'), #result('ARTIST_NAME'), "
-                        + "#result('DATE_OF_BIRTH') FROM ARTIST ORDER BY 
ARTIST_ID");
-
-        Map<String, String> q2 = new HashMap<>();
-        q2.put(
-                "org.apache.cayenne.dba.postgres.PostgresAdapter",
-                "SELECT #result('ARTIST_ID'), RTRIM(#result('ARTIST_NAME')), 
#result('DATE_OF_BIRTH') "
-                        + "FROM ARTIST WHERE ARTIST_ID = #bind($id)");
-        q2.put(
-                "org.apache.cayenne.dba.ingres.IngresAdapter",
-                "SELECT #result('ARTIST_ID'), TRIM(#result('ARTIST_NAME')), 
#result('DATE_OF_BIRTH') "
-                        + "FROM ARTIST WHERE ARTIST_ID = #bind($id)");
-        q2.put(
-                "org.apache.cayenne.dba.openbase.OpenBaseAdapter",
-                "SELECT #result('ARTIST_ID'), #result('ARTIST_NAME'), 
#result('DATE_OF_BIRTH') "
-                        + "FROM ARTIST WHERE ARTIST_ID = #bind($id)");
-
-        Map<String, String> q3 = new HashMap<>();
-        q3
-                .put(
-                        "org.apache.cayenne.dba.oracle.OracleAdapter",
-                        "UPDATE ARTIST SET ARTIST_NAME = #bind($newName) WHERE 
RTRIM(ARTIST_NAME) = #bind($oldName)");
-        q3
-                .put(
-                        "org.apache.cayenne.dba.oracle.Oracle8Adapter",
-                        "UPDATE ARTIST SET ARTIST_NAME = #bind($newName) WHERE 
RTRIM(ARTIST_NAME) = #bind($oldName)");
-
-        map.put("SELECT * FROM ARTIST ORDER BY ARTIST_ID", q1);
-        map.put("SELECT * FROM ARTIST WHERE ARTIST_ID = #bind($id)", q2);
-        map.put("UPDATE ARTIST SET ARTIST_NAME = #bind($newName) "
-                + "WHERE ARTIST_NAME = #bind($oldName)", q3);
-
-        return new SQLTemplateCustomizer(map, dbAdapter);
-    }
-}
diff --git 
a/cayenne/src/test/java/org/apache/cayenne/unit/util/SQLTemplateCustomizer.java 
b/cayenne/src/test/java/org/apache/cayenne/unit/util/SQLTemplateCustomizer.java
index 97f4b6dd1..9233be165 100644
--- 
a/cayenne/src/test/java/org/apache/cayenne/unit/util/SQLTemplateCustomizer.java
+++ 
b/cayenne/src/test/java/org/apache/cayenne/unit/util/SQLTemplateCustomizer.java
@@ -19,32 +19,72 @@
 
 package org.apache.cayenne.unit.util;
 
-import java.util.Map;
-
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.query.SQLTemplate;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * Helper class to customize SQLTemplate queries used in test cases per 
adapter.
  */
 public class SQLTemplateCustomizer {
 
-    protected DbAdapter adapter;
-    protected Map<String, Map<String, String>> sqlMap;
+    private static final Map<String, Map<String, String>> map = new 
HashMap<>();
+
+    static {
+        Map<String, String> q1 = new HashMap<>();
+        q1.put("org.apache.cayenne.dba.postgres.PostgresAdapter",
+                "SELECT #result('ARTIST_ID'), RTRIM(#result('ARTIST_NAME')), "
+                        + "#result('DATE_OF_BIRTH') FROM ARTIST ORDER BY 
ARTIST_ID");
+        q1.put("org.apache.cayenne.dba.ingres.IngresAdapter",
+                "SELECT #result('ARTIST_ID'), TRIM(#result('ARTIST_NAME')), "
+                        + "#result('DATE_OF_BIRTH') FROM ARTIST ORDER BY 
ARTIST_ID");
+        q1.put("org.apache.cayenne.dba.openbase.OpenBaseAdapter",
+                "SELECT #result('ARTIST_ID'), #result('ARTIST_NAME'), "
+                        + "#result('DATE_OF_BIRTH') FROM ARTIST ORDER BY 
ARTIST_ID");
+
+        Map<String, String> q2 = new HashMap<>();
+        q2.put("org.apache.cayenne.dba.postgres.PostgresAdapter",
+                "SELECT #result('ARTIST_ID'), RTRIM(#result('ARTIST_NAME')), 
#result('DATE_OF_BIRTH') "
+                        + "FROM ARTIST WHERE ARTIST_ID = #bind($id)");
+        q2.put("org.apache.cayenne.dba.ingres.IngresAdapter",
+                "SELECT #result('ARTIST_ID'), TRIM(#result('ARTIST_NAME')), 
#result('DATE_OF_BIRTH') "
+                        + "FROM ARTIST WHERE ARTIST_ID = #bind($id)");
+        q2.put("org.apache.cayenne.dba.openbase.OpenBaseAdapter",
+                "SELECT #result('ARTIST_ID'), #result('ARTIST_NAME'), 
#result('DATE_OF_BIRTH') "
+                        + "FROM ARTIST WHERE ARTIST_ID = #bind($id)");
+
+        Map<String, String> q3 = new HashMap<>();
+        q3.put(
+                "org.apache.cayenne.dba.oracle.OracleAdapter",
+                "UPDATE ARTIST SET ARTIST_NAME = #bind($newName) WHERE 
RTRIM(ARTIST_NAME) = #bind($oldName)");
+        q3.put(
+                "org.apache.cayenne.dba.oracle.Oracle8Adapter",
+                "UPDATE ARTIST SET ARTIST_NAME = #bind($newName) WHERE 
RTRIM(ARTIST_NAME) = #bind($oldName)");
 
-    public SQLTemplateCustomizer(Map<String, Map<String, String>> sqlMap,
-            DbAdapter adapter) {
+        map.put("SELECT * FROM ARTIST ORDER BY ARTIST_ID", q1);
+        map.put("SELECT * FROM ARTIST WHERE ARTIST_ID = #bind($id)", q2);
+        map.put("UPDATE ARTIST SET ARTIST_NAME = #bind($newName) "
+                + "WHERE ARTIST_NAME = #bind($oldName)", q3);
+    }
+
+    public static SQLTemplateCustomizer of(DbAdapter dbAdapter) {
+        return new SQLTemplateCustomizer(map, dbAdapter);
+    }
+
+    private final DbAdapter adapter;
+    private final Map<String, Map<String, String>> sqlMap;
+
+    private SQLTemplateCustomizer(Map<String, Map<String, String>> sqlMap, 
DbAdapter adapter) {
         this.sqlMap = sqlMap;
         this.adapter = adapter;
     }
 
-    /**
-     * Customizes SQLTemplate, injecting the template for the current adapter.
-     */
     public void updateSQLTemplate(SQLTemplate query) {
         Map<String, String> customSQL = sqlMap.get(query.getDefaultTemplate());
         if (customSQL != null) {
-            String key = adapter.getClass().getName();
+            String key = adapter.unwrap().getClass().getName();
             String template = customSQL.get(key);
             if (template != null) {
                 query.setTemplate(key, template);
@@ -57,5 +97,4 @@ public class SQLTemplateCustomizer {
         updateSQLTemplate(template);
         return template;
     }
-
 }

Reply via email to