Skip to content

(Purposefully failing) Add more tests for multi-scope #798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion blackbox-multi-scope/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
<version>1.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.12.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.multi.crosscut;

import org.multi.moda.BeanInModA;
import org.multi.modb.BeanInModB;
import org.multi.modc.modb.BeanInModC;
import org.multi.modc.BeanInModC;
import org.multi.scope.CrossCutScope;

@CrossCutScope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.multi.crosscut;

import org.multi.modc.modb.COther;
import org.multi.modc.COther;
import org.multi.scope.CrossCutScope;

@CrossCutScope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.multi.main;

import io.avaje.inject.BeanScope;
import org.multi.crosscut.BeanCross;
import org.multi.crosscut.BeanCross2;
import org.multi.crosscut.BeanCross3;
Expand All @@ -9,7 +8,9 @@
import org.multi.moda.ModAModule;
import org.multi.modb.BeanInModB;
import org.multi.modb.ModBModule;
import org.multi.modc.modb.ModCModule;
import org.multi.modc.ModCModule;

import io.avaje.inject.BeanScope;

public class CrossCutMain {

Expand Down
20 changes: 20 additions & 0 deletions blackbox-multi-scope/src/main/java/org/multi/many/BeanInMany.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.multi.many;

import org.multi.moda.BeanInModA;
import org.multi.modc.COther;
import org.multi.mode.BeanInModE;
import org.multi.scope.ManyScope;

@ManyScope
public class BeanInMany {

private final BeanInModE beanInModE;
private final COther cOther;
private final BeanInModA modA;

public BeanInMany(final BeanInModE beanInModE, final COther cOther, final BeanInModA modA) {
this.beanInModE = beanInModE;
this.cOther = cOther;
this.modA = modA;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.multi.modb;

import org.multi.modc.modb.COther;
import org.multi.modc.COther;
import org.multi.scope.ModBScope;

@ModBScope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.multi.modc.modb;
package org.multi.modc;

import org.multi.scope.ModCScope;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.multi.modc.modb;
package org.multi.modc;

import org.multi.scope.ModCScope;

Expand Down
14 changes: 14 additions & 0 deletions blackbox-multi-scope/src/main/java/org/multi/modd/BeanInModD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.multi.modd;

import org.multi.moda.BeanInModA;
import org.multi.scope.ModDScope;

@ModDScope
public class BeanInModD {

private final BeanInModA beanA;

public BeanInModD(final BeanInModA beanInModA){
this.beanA = beanInModA;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.multi.mode;

import org.multi.scope.ModEScope;

@ModEScope
public class BeanInModE {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.avaje.inject.InjectModule;
import jakarta.inject.Scope;
import org.multi.modb.BeanInModB;

@Scope
@InjectModule(requires = {ModAScope.class, ModBScope.class}, strictWiring = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.multi.scope;

import io.avaje.inject.InjectModule;
import jakarta.inject.Scope;

@Scope
@InjectModule(requires = {ModDScope.class, CrossCutScope.class, ModEScope.class}, strictWiring = true)
public @interface ManyScope {
}
10 changes: 10 additions & 0 deletions blackbox-multi-scope/src/main/java/org/multi/scope/ModDScope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.multi.scope;

import io.avaje.inject.InjectModule;
import jakarta.inject.Scope;

@Scope
@InjectModule(requires = {ModAScope.class}, strictWiring = true)
public @interface ModDScope {

}
10 changes: 10 additions & 0 deletions blackbox-multi-scope/src/main/java/org/multi/scope/ModEScope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.multi.scope;

import io.avaje.inject.InjectModule;
import jakarta.inject.Scope;

@Scope
@InjectModule(requires = {}, strictWiring = true)
public @interface ModEScope {

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,97 @@
package org.multi.crosscut;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertTrue;

import io.avaje.inject.BeanScope;
import org.junit.jupiter.api.Test;
import java.util.stream.Stream;

import org.junit.jupiter.api.Named;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.multi.many.BeanInMany;
import org.multi.many.ManyModule;
import org.multi.moda.BeanInModA;
import org.multi.moda.ModAModule;
import org.multi.modb.BOther;
import org.multi.modb.BeanInModB;
import org.multi.modb.ModBModule;
import org.multi.modc.BeanInModC;
import org.multi.modc.COther;
import org.multi.modc.ModCModule;
import org.multi.modd.BeanInModD;
import org.multi.modd.ModDModule;
import org.multi.mode.BeanInModE;
import org.multi.mode.ModEModule;

import static org.assertj.core.api.Assertions.assertThat;
import io.avaje.inject.BeanScope;
import io.avaje.inject.spi.AvajeModule;

class BeanCrossTest {

@Test
void bootstrap() {
private static Stream<Arguments> allModulesDefined() {
return Stream.of(
Arguments.of(Named.of("In working order A", new AvajeModule[]{
new ModAModule(),
new ModCModule(),
new ModBModule(),
new CrossCutModule(),
new ModDModule(),
new ModEModule(),
new ManyModule(),
})),
Arguments.of(Named.of("In alphabetical order", new AvajeModule[]{
new CrossCutModule(),
new ManyModule(),
new ModAModule(),
new ModBModule(),
new ModCModule(),
new ModDModule(),
new ModEModule(),
})),
Arguments.of(Named.of("In reverse alphabetical order", new AvajeModule[]{
new ModEModule(),
new ModDModule(),
new ModCModule(),
new ModBModule(),
new ModAModule(),
new ManyModule(),
new CrossCutModule(),
})),
Arguments.of(Named.of("In shuffled order", new AvajeModule[]{
new ModEModule(),
new ModBModule(),
new ModDModule(),
new ManyModule(),
new ModCModule(),
new ModAModule(),
new CrossCutModule(),
}))
);
}

try (BeanScope beanScope = BeanScope.builder()
// .modules(new CrossCutModule())
.build()) {
private static final Class[] CHECKABLE = {
BeanCross.class,
BeanCross2.class,
BeanCross3.class,
BeanInMany.class,
BeanInModA.class,
BeanInModB.class,
BOther.class,
BeanInModC.class,
COther.class,
BeanInModD.class,
BeanInModE.class
};

// var beanInModB = beanScope.get(BeanInModB.class);
// assertThat(beanInModB).isNotNull();
}
@ParameterizedTest(name = "Multi Scope Test: {1}")
@MethodSource("allModulesDefined")
void bootstrap(AvajeModule... modules) {

try (BeanScope beanScope = assertDoesNotThrow(() -> BeanScope.builder().modules(modules).build())) {
for (final Class<?> clazz : CHECKABLE) {
assertTrue(beanScope.getOptional(clazz).isPresent(), "Bean not found: " + clazz.getSimpleName());
}
}
}
}