Search in sources :

Example 11 with Env

use of se.jbee.inject.Env in project silk by jbee.

the class TestFeatureConnectorBinds method interfacesApplyDynamicLinkingToAssignableTypes.

@Test
void interfacesApplyDynamicLinkingToAssignableTypes() {
    Env env = Bootstrap.DEFAULT_ENV.with(Connector.class, (i, as, m) -> {
    });
    Injector context = Bootstrap.injector(env, TestFeatureConnectorBindsModule.class);
    assertTrue(context.resolve("marked", Bean.class).cleaned, "clean was not called for marked bean");
    assertTrue(context.resolve("unmarked", Bean.class).cleaned, "clean was not called for unmarked bean");
}
Also used : Injector(se.jbee.inject.Injector) Env(se.jbee.inject.Env) Test(org.junit.jupiter.api.Test)

Example 12 with Env

use of se.jbee.inject.Env in project silk by jbee.

the class TestFeatureConnectorBinds method injectingIntoCanBeUsedToLimitTheSetOfAffectedInstances.

@Test
void injectingIntoCanBeUsedToLimitTheSetOfAffectedInstances() {
    List<Object> acceptedInstances = new ArrayList<>();
    List<Method> acceptedMethods = new ArrayList<>();
    Connector verifier = (instance, as, method) -> {
        acceptedInstances.add(instance);
        acceptedMethods.add(method);
    };
    Env env = Bootstrap.DEFAULT_ENV.with(Connector.class, verifier);
    Injector context = Bootstrap.injector(env, TestFeatureConnectorBindsModule.class);
    Bean expected = context.resolve("marked", Bean.class);
    assertEquals("marked", expected.name);
    assertEquals("unmarked", context.resolve("unmarked", Bean.class).name);
    assertEquals(singletonList(expected), acceptedInstances);
    assertEquals(1, acceptedMethods.size());
    assertEquals("myMethod", acceptedMethods.get(0).getName());
}
Also used : Injector(se.jbee.inject.Injector) Hint(se.jbee.inject.Hint) Connector(se.jbee.inject.config.Connector) Target(java.lang.annotation.Target) RUNTIME(java.lang.annotation.RetentionPolicy.RUNTIME) Env(se.jbee.inject.Env) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Test(org.junit.jupiter.api.Test) METHOD(java.lang.annotation.ElementType.METHOD) Bootstrap(se.jbee.inject.bootstrap.Bootstrap) List(java.util.List) BinderModuleWith(se.jbee.inject.binder.BinderModuleWith) ProducesBy(se.jbee.inject.config.ProducesBy) Assertions(org.junit.jupiter.api.Assertions) Method(java.lang.reflect.Method) Name.named(se.jbee.inject.Name.named) Connector(se.jbee.inject.config.Connector) Injector(se.jbee.inject.Injector) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Env(se.jbee.inject.Env) Test(org.junit.jupiter.api.Test)

Example 13 with Env

use of se.jbee.inject.Env in project silk by jbee.

the class TestFeatureEditionPackageBinds method editionsCanBeUsedToInstallBundlesPackageDependent.

@Test
void editionsCanBeUsedToInstallBundlesPackageDependent() {
    // no edition
    Injector injector = Bootstrap.injector(TestFeatureEditionPackageBindsModule.class);
    assertEquals(42, injector.resolve(int.class).intValue());
    // an edition without the module in this test
    Env env = Bootstrap.DEFAULT_ENV.with(Edition.class, Edition.includes(// 
    subPackagesOf(TestFeatureEditionPackageBinds.class).and(packageOf(DefaultsBundle.class).and(packageOf(Bootstrap.class)))));
    Injector context = Bootstrap.injector(env, TestFeatureEditionPackageBindsModule.class);
    assertThrows(UnresolvableDependency.ResourceResolutionFailed.class, () -> context.resolve(int.class), "Should have thrown exception since EditionPackageBindsModule should not have been installed");
    // an edition including the module in this test
    env = Bootstrap.DEFAULT_ENV.with(Edition.class, Edition.includes(// 
    packageAndSubPackagesOf(TestFeatureEditionPackageBinds.class).and(packageOf(DefaultsBundle.class)).and(packageOf(Bootstrap.class))));
    injector = Bootstrap.injector(env, TestFeatureEditionPackageBindsModule.class);
    assertEquals(42, injector.resolve(int.class).intValue());
}
Also used : UnresolvableDependency(se.jbee.inject.UnresolvableDependency) Injector(se.jbee.inject.Injector) DefaultsBundle(se.jbee.inject.defaults.DefaultsBundle) Env(se.jbee.inject.Env) Edition(se.jbee.inject.config.Edition) Test(org.junit.jupiter.api.Test)

Aggregations

Env (se.jbee.inject.Env)13 Injector (se.jbee.inject.Injector)11 Test (org.junit.jupiter.api.Test)10 METHOD (java.lang.annotation.ElementType.METHOD)1 Retention (java.lang.annotation.Retention)1 RUNTIME (java.lang.annotation.RetentionPolicy.RUNTIME)1 Target (java.lang.annotation.Target)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Properties (java.util.Properties)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Assertions (org.junit.jupiter.api.Assertions)1 Hint (se.jbee.inject.Hint)1 Name.named (se.jbee.inject.Name.named)1 UnresolvableDependency (se.jbee.inject.UnresolvableDependency)1 BinderModuleWith (se.jbee.inject.binder.BinderModuleWith)1 Bootstrap (se.jbee.inject.bootstrap.Bootstrap)1 Connector (se.jbee.inject.config.Connector)1