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 fba5842bde01e265053565ef8675fdc7a5679bcf Author: Andrus Adamchik <[email protected]> AuthorDate: Thu May 14 10:40:24 2026 -0400 tests cleanup - unwinding DI --- .../cayenne/unit/di/runtime/CayenneTestsEnv.java | 9 ++++- .../unit/di/runtime/FlavoredDBHelperProvider.java | 47 ---------------------- .../cayenne/unit/di/runtime/RuntimeCaseModule.java | 2 - 3 files changed, 8 insertions(+), 50 deletions(-) diff --git a/cayenne/src/test/java/org/apache/cayenne/unit/di/runtime/CayenneTestsEnv.java b/cayenne/src/test/java/org/apache/cayenne/unit/di/runtime/CayenneTestsEnv.java index ba8c14145..a19a6972e 100644 --- a/cayenne/src/test/java/org/apache/cayenne/unit/di/runtime/CayenneTestsEnv.java +++ b/cayenne/src/test/java/org/apache/cayenne/unit/di/runtime/CayenneTestsEnv.java @@ -128,7 +128,14 @@ public class CayenneTestsEnv implements BeforeEachCallback, AfterEachCallback { this.runtime = INJECTOR.getInstance(CayenneRuntime.class); this.context = (DataContext) runtime.newContext(); - this.dbHelper = INJECTOR.getInstance(DbHelper.class); + + DataNode node = runtime.getDataDomain().getDataNodes().iterator().next(); + DataMap firstMap = context.getEntityResolver().getDataMaps().iterator().next(); + this.dbHelper = new FlavoredDbHelper( + INJECTOR.getInstance(RuntimeCaseDataSourceFactory.class).getSharedDataSource(), + node.getAdapter().getQuotingStrategy(), + firstMap); + this.dbCleaner = new DbCleaner( SCHEMA_MANAGER, dbHelper, diff --git a/cayenne/src/test/java/org/apache/cayenne/unit/di/runtime/FlavoredDBHelperProvider.java b/cayenne/src/test/java/org/apache/cayenne/unit/di/runtime/FlavoredDBHelperProvider.java deleted file mode 100644 index 4ee294820..000000000 --- a/cayenne/src/test/java/org/apache/cayenne/unit/di/runtime/FlavoredDBHelperProvider.java +++ /dev/null @@ -1,47 +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.di.runtime; - -import org.apache.cayenne.ConfigurationException; -import org.apache.cayenne.DataChannel; -import org.apache.cayenne.dba.DbAdapter; -import org.apache.cayenne.di.Inject; -import org.apache.cayenne.di.Provider; -import org.apache.cayenne.map.DataMap; -import org.apache.cayenne.runtime.CayenneRuntime; -import org.apache.cayenne.test.jdbc.DbHelper; - -public class FlavoredDBHelperProvider implements Provider<DbHelper> { - - @Inject - protected RuntimeCaseDataSourceFactory dataSourceFactory; - - @Inject - // injecting provider to make this provider independent of scoping of CayenneRuntime - protected Provider<CayenneRuntime> runtimeProvider; - - @Inject - protected DbAdapter adapter; - - public DbHelper get() throws ConfigurationException { - DataChannel channel = runtimeProvider.get().getChannel(); - DataMap firstMap = channel.getEntityResolver().getDataMaps().iterator().next(); - return new FlavoredDbHelper(dataSourceFactory.getSharedDataSource(), adapter.getQuotingStrategy(), firstMap); - } -} diff --git a/cayenne/src/test/java/org/apache/cayenne/unit/di/runtime/RuntimeCaseModule.java b/cayenne/src/test/java/org/apache/cayenne/unit/di/runtime/RuntimeCaseModule.java index a72e31168..c7708fe33 100644 --- a/cayenne/src/test/java/org/apache/cayenne/unit/di/runtime/RuntimeCaseModule.java +++ b/cayenne/src/test/java/org/apache/cayenne/unit/di/runtime/RuntimeCaseModule.java @@ -84,7 +84,6 @@ import org.apache.cayenne.reflect.generic.ValueComparisonStrategyFactory; import org.apache.cayenne.resource.ClassLoaderResourceLocator; import org.apache.cayenne.resource.ResourceLocator; import org.apache.cayenne.runtime.CayenneRuntime; -import org.apache.cayenne.test.jdbc.DbHelper; import org.apache.cayenne.unit.DB2UnitDbAdapter; import org.apache.cayenne.unit.DerbyUnitDbAdapter; import org.apache.cayenne.unit.FirebirdUnitDbAdapter; @@ -251,7 +250,6 @@ public class RuntimeCaseModule implements Module { binder.bind(RuntimeCaseProperties.class).to(RuntimeCaseProperties.class).in(testScope); binder.bind(RuntimeCaseExtraModules.class).to(RuntimeCaseExtraModules.class).in(testScope); binder.bind(CayenneRuntime.class).toProvider(CayenneRuntimeProvider.class).in(testScope); - binder.bind(DbHelper.class).toProvider(FlavoredDBHelperProvider.class).in(testScope); } // this class exists so that ToolsModule can call "initAllExtensions()" that is protected in CoreModuleExtender.
