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");
}
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());
}
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());
}
Aggregations