Search in sources :

Example 26 with Injector

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

the class TestScopedBinds method thatInjectingAnInjectionScopedInstanceIntoAppScopedInstanceThrowsAnException.

@Test(expected = UnstableDependency.class)
public void thatInjectingAnInjectionScopedInstanceIntoAppScopedInstanceThrowsAnException() {
    Injector injector = Bootstrap.injector(ScopedBindsModule.class);
    Foo foo = injector.resolve(dependency(Foo.class));
    fail("It should not be possible to create a foo but got one: " + foo);
}
Also used : Injector(se.jbee.inject.Injector) Test(org.junit.Test)

Example 27 with Injector

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

the class TestSpecificImplementationBinds method thatImplementationIsPickedAsSpecified.

@Test
public void thatImplementationIsPickedAsSpecified() {
    Injector injector = Bootstrap.injector(SpecificImplementationBindsModule.class);
    Receiver r = injector.resolve(dependency(Receiver.class));
    assertEquals(ActionA.class, r.a.getClass());
    assertEquals(GenericAction.class, r.b.getClass());
    assertEquals(GenericAction.class, r.c.getClass());
    assertEquals("this is b", r.b.doIt());
    assertEquals("and this is c", r.c.doIt());
}
Also used : Injector(se.jbee.inject.Injector) Test(org.junit.Test)

Example 28 with Injector

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

the class TestActionBinds method actionsDecoupleConcreteMethods.

@Test
public void actionsDecoupleConcreteMethods() {
    Injector injector = Bootstrap.injector(ActionBindsModule.class);
    Dependency<Action<Integer, Integer>> p1 = actionDependency(raw(Integer.class), raw(Integer.class));
    Action<Integer, Integer> mul2 = injector.resolve(p1);
    assertNotNull(mul2);
    assertEquals(9, mul2.exec(3).intValue());
    Dependency<Action<Number, Integer>> p2 = actionDependency(raw(Number.class), raw(Integer.class));
    Action<Number, Integer> negate = injector.resolve(p2);
    assertNotNull(mul2);
    assertEquals(-3, negate.exec(3).intValue());
    assertEquals(11, mul2.exec(4).intValue());
}
Also used : Injector(se.jbee.inject.Injector) Test(org.junit.Test)

Example 29 with Injector

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

the class TestStateDependentBinds method assertConfigNumberResolvedToStringEnding.

private static void assertConfigNumberResolvedToStringEnding(Integer actualValue, String ending) {
    Injector injector = Bootstrap.injector(StateDependentBindsModule3.class);
    StatefulObject state = injector.resolve(dependency(StatefulObject.class));
    state.setNumber(actualValue);
    String v = injector.resolve(dependency(String.class));
    assertTrue(v.endsWith(ending));
}
Also used : Injector(se.jbee.inject.Injector)

Example 30 with Injector

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

the class TestSupplierBinds method test.

@Test
public void test() {
    Injector injector = Bootstrap.injector(SupplierBindsModule.class);
    String value = injector.resolve(dependency(String.class));
    assertEquals("foobar", value);
}
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