Search in sources :

Example 11 with Injector

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

the class TestMockingBinds method methodsOfMocksByDefaultReturnMocksIfPossible.

@Test
public void methodsOfMocksByDefaultReturnMocksIfPossible() {
    Injector injector = Bootstrap.injector(TestMockingBindsModule.class);
    Shape shape = injector.resolve(dependency(Shape.class));
    PathIterator iter = shape.getPathIterator(null);
    assertNotNull(iter);
    assertTrue(isProxyClass(iter.getClass()));
    assertFalse(iter.isDone());
}
Also used : Shape(java.awt.Shape) PathIterator(java.awt.geom.PathIterator) Injector(se.jbee.inject.Injector) Test(org.junit.Test)

Example 12 with Injector

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

the class TestMockingBinds method bindsCanBeUsedToMockReturnValuesOfMockMethods.

@Test
public void bindsCanBeUsedToMockReturnValuesOfMockMethods() {
    Injector injector = Bootstrap.injector(TestMockingBindsModule.class);
    Shape shape = injector.resolve(dependency(Shape.class));
    Rectangle bounds = shape.getBounds();
    assertNotNull(bounds);
    assertTrue(shape instanceof Mock);
    Mock mock = (Mock) shape;
    assertEquals(1, mock.timesInvoked());
}
Also used : Shape(java.awt.Shape) Injector(se.jbee.inject.Injector) Rectangle(java.awt.Rectangle) Test(org.junit.Test)

Example 13 with Injector

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

the class TestMockingBinds method moreSpecificUpperBoundTypesAreMorePrecise.

@Test
public void moreSpecificUpperBoundTypesAreMorePrecise() {
    Injector injector = Bootstrap.injector(TestMockingBindsModule.class);
    MouseListener mock = injector.resolve(dependency(MouseListener.class));
    assertTrue(isProxyClass(mock.getClass()));
    assertEquals(EventListener.class.getCanonicalName(), mock.toString());
}
Also used : MouseListener(java.awt.event.MouseListener) Injector(se.jbee.inject.Injector) EventListener(java.util.EventListener) Test(org.junit.Test)

Example 14 with Injector

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

the class TestServiceBinds method servicesAreResolvable.

@Test
public void servicesAreResolvable() {
    Injector injector = Bootstrap.injector(ServiceBindsModule.class);
    @SuppressWarnings({ "rawtypes" }) Dependency<Service> dependency = dependency(raw(Service.class).parametized(Integer.class, Long.class));
    @SuppressWarnings("unchecked") Service<Integer, Long> square = injector.resolve(dependency);
    assertEquals(4L, square.calc(2).longValue());
}
Also used : Injector(se.jbee.inject.Injector) Test(org.junit.Test)

Example 15 with Injector

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

the class TestBootstrapper method thatCustomInspectorIsUsedToPickConstructor.

@Test
public void thatCustomInspectorIsUsedToPickConstructor() {
    Injector injector = Bootstrap.injector(CustomInspectedBundle.class);
    assertEquals("will be passed to D", injector.resolve(dependency(D.class)).s);
}
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