Search in sources :

Example 41 with Injector

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

the class TestBootstrapper method thatBindingsAreReplacedByMorePreciseOnes.

/**
	 * In the example {@link Number} is {@link DeclarationType#AUTO} bound for {@link Integer} and
	 * {@link Float} but an {@link DeclarationType#EXPLICIT} bind done overrides these automatic
	 * binds. They are removed and no {@link Injectron} is created for them.
	 */
@Test
public void thatBindingsAreReplacedByMorePreciseOnes() {
    Injector injector = Bootstrap.injector(ReplacingBindsModule.class);
    assertEquals(6, injector.resolve(dependency(Number.class)));
    Injectron<?>[] injectrons = injector.resolve(dependency(Injectron[].class));
    // 3x Comparable, Float, Double, Integer and Number (3x Serializable has been nullified)
    assertEquals(7, injectrons.length);
    Injectron<Number>[] numberInjectrons = injector.resolve(dependency(injectronsTypeOf(Number.class)));
    assertEquals(1, numberInjectrons.length);
    @SuppressWarnings("rawtypes") Injectron<Comparable>[] compareableInjectrons = injector.resolve(dependency(injectronsTypeOf(Comparable.class)));
    assertEquals(3, compareableInjectrons.length);
}
Also used : Injector(se.jbee.inject.Injector) Injectron(se.jbee.inject.Injectron) Test(org.junit.Test)

Example 42 with Injector

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

the class TestExample1Binds method constructorArgumentsCanBeResolvedUsingNamedInstances.

@Test
public void constructorArgumentsCanBeResolvedUsingNamedInstances() {
    Injector injector = Bootstrap.injector(Example1Module2.class);
    MyClass obj = injector.resolve(Dependency.dependency(MyClass.class));
    assertEquals(12, obj.twelve);
    assertEquals("abc", obj.abc);
}
Also used : Injector(se.jbee.inject.Injector) Test(org.junit.Test)

Example 43 with Injector

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

the class TestMacroBinds method thatBindingsCanJustBeCounted.

@Test
public void thatBindingsCanJustBeCounted() {
    CountMacro count = new CountMacro();
    Injector injector = injectorWithMacro(MacroBindsModule.class, count);
    assertEquals(6, count.expands);
    assertEquals(0, injector.resolve(Dependency.dependency(Injectron[].class)).length);
}
Also used : Injector(se.jbee.inject.Injector) Test(org.junit.Test)

Example 44 with Injector

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

the class TestStateDependentBinds method thatStateChangeIsResolvedToAnotherImplementation2.

@Test
public void thatStateChangeIsResolvedToAnotherImplementation2() {
    Injector injector = Bootstrap.injector(StateDependentBindsModule2.class);
    assertStateChangeIsResolvedToAnotherImplementation(injector);
}
Also used : Injector(se.jbee.inject.Injector) Test(org.junit.Test)

Aggregations

Injector (se.jbee.inject.Injector)44 Test (org.junit.Test)41 Shape (java.awt.Shape)3 Globals (se.jbee.inject.config.Globals)2 Options (se.jbee.inject.config.Options)2 Rectangle (java.awt.Rectangle)1 MouseListener (java.awt.event.MouseListener)1 PathIterator (java.awt.geom.PathIterator)1 Serializable (java.io.Serializable)1 EventListener (java.util.EventListener)1 Properties (java.util.Properties)1 Injectron (se.jbee.inject.Injectron)1 NoResourceForDependency (se.jbee.inject.UnresolvableDependency.NoResourceForDependency)1 Presets (se.jbee.inject.config.Presets)1