You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2022/11/14 12:19:28 UTC
[cayenne] branch master updated: Add test for the circularly-dependent Modules
This is an automated email from the ASF dual-hosted git repository.
ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
The following commit(s) were added to refs/heads/master by this push:
new 25a45472c Add test for the circularly-dependent Modules
25a45472c is described below
commit 25a45472c4b305f6366888a0074d4a5701c4227c
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Mon Nov 14 15:19:22 2022 +0300
Add test for the circularly-dependent Modules
---
.../cayenne/di/spi/CircularModuleProvider.java | 4 ++
.../apache/cayenne/di/spi/ModuleLoaderTest.java | 56 ++++++++++++++++++++++
...rg.apache.cayenne.di.spi.CircularModuleProvider | 21 ++++++++
3 files changed, 81 insertions(+)
diff --git a/cayenne-di/src/test/java/org/apache/cayenne/di/spi/CircularModuleProvider.java b/cayenne-di/src/test/java/org/apache/cayenne/di/spi/CircularModuleProvider.java
new file mode 100644
index 000000000..1841c3821
--- /dev/null
+++ b/cayenne-di/src/test/java/org/apache/cayenne/di/spi/CircularModuleProvider.java
@@ -0,0 +1,4 @@
+package org.apache.cayenne.di.spi;
+
+public interface CircularModuleProvider extends ModuleProvider {
+}
diff --git a/cayenne-di/src/test/java/org/apache/cayenne/di/spi/ModuleLoaderTest.java b/cayenne-di/src/test/java/org/apache/cayenne/di/spi/ModuleLoaderTest.java
index e87dfd20b..91a554727 100644
--- a/cayenne-di/src/test/java/org/apache/cayenne/di/spi/ModuleLoaderTest.java
+++ b/cayenne-di/src/test/java/org/apache/cayenne/di/spi/ModuleLoaderTest.java
@@ -20,6 +20,7 @@ package org.apache.cayenne.di.spi;
import org.apache.cayenne.di.Binder;
import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.DIRuntimeException;
import org.apache.cayenne.di.Injector;
import org.apache.cayenne.di.Module;
import org.junit.Test;
@@ -59,6 +60,11 @@ public class ModuleLoaderTest {
assertEquals(Integer.valueOf(66), i.getInstance(Integer.class));
}
+ @Test(expected = DIRuntimeException.class)
+ public void testLoadCircularModules() {
+ new ModuleLoader().load(CircularModuleProvider.class);
+ }
+
public static class Module1 implements Module {
@Override
@@ -105,6 +111,20 @@ public class ModuleLoaderTest {
}
}
+ public static class Module7 implements Module {
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(Integer.class).toInstance(77);
+ }
+ }
+
+ public static class Module8 implements Module {
+ @Override
+ public void configure(Binder binder) {
+ binder.bind(Integer.class).toInstance(88);
+ }
+ }
+
public static class ModuleProvider1 implements ModuleProvider {
@Override
@@ -212,4 +232,40 @@ public class ModuleLoaderTest {
return Collections.singletonList(Module5.class);
}
}
+
+ public static class ModuleProvider7 implements CircularModuleProvider {
+
+ @Override
+ public Module module() {
+ return new Module7();
+ }
+
+ @Override
+ public Class<? extends Module> moduleType() {
+ return Module7.class;
+ }
+
+ @Override
+ public Collection<Class<? extends Module>> overrides() {
+ return Collections.singletonList(Module8.class);
+ }
+ }
+
+ public static class ModuleProvider8 implements CircularModuleProvider {
+
+ @Override
+ public Module module() {
+ return new Module8();
+ }
+
+ @Override
+ public Class<? extends Module> moduleType() {
+ return Module8.class;
+ }
+
+ @Override
+ public Collection<Class<? extends Module>> overrides() {
+ return Collections.singletonList(Module7.class);
+ }
+ }
}
diff --git a/cayenne-di/src/test/resources/META-INF/services/org.apache.cayenne.di.spi.CircularModuleProvider b/cayenne-di/src/test/resources/META-INF/services/org.apache.cayenne.di.spi.CircularModuleProvider
new file mode 100644
index 000000000..c6d832fb2
--- /dev/null
+++ b/cayenne-di/src/test/resources/META-INF/services/org.apache.cayenne.di.spi.CircularModuleProvider
@@ -0,0 +1,21 @@
+##################################################################
+# 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.
+##################################################################
+
+org.apache.cayenne.di.spi.ModuleLoaderTest$ModuleProvider7
+org.apache.cayenne.di.spi.ModuleLoaderTest$ModuleProvider8
\ No newline at end of file