Search in sources :

Example 31 with Injector

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

the class TestMultipleOptionChoicesBinds method thatMultipleOptionChoicesArePossible.

@Test
public void thatMultipleOptionChoicesArePossible() {
    Options options = Options.STANDARD.chosen(Choices.A, Choices.D);
    Globals globals = Globals.STANDARD.options(options);
    Injector injector = Bootstrap.injector(RootBundle.class, globals);
    assertEqualSets(new String[] { "A", "D" }, injector.resolve(dependency(String[].class)));
}
Also used : Globals(se.jbee.inject.config.Globals) Options(se.jbee.inject.config.Options) Injector(se.jbee.inject.Injector) Test(org.junit.Test)

Example 32 with Injector

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

the class TestOptionBinds method assertOptionResolvedToValue.

private static void assertOptionResolvedToValue(Machine actualOption, String expected) {
    Options options = Options.STANDARD.chosen(actualOption);
    Injector injector = Bootstrap.injector(ModularBindsBundle.class, Globals.STANDARD.options(options));
    String[] actual = injector.resolve(dependency(String[].class));
    assertArrayEquals(new String[] { expected }, actual);
}
Also used : Options(se.jbee.inject.config.Options) Injector(se.jbee.inject.Injector)

Example 33 with Injector

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

the class TestRequiredProvidedBinds method thatUnusedProvidedBindIsNotAddedToInjectorContext.

@Test
public void thatUnusedProvidedBindIsNotAddedToInjectorContext() {
    Injector injector = Bootstrap.injector(RequiredProvidedBindsBundle.class);
    try {
        injector.resolve(dependency(UnusedImpl.class));
        fail("Should not be bound and therefore throw below exception");
    } catch (NoResourceForDependency e) {
    // expected this
    } catch (Throwable e) {
        fail("Expected another exception but got: " + e);
    }
}
Also used : NoResourceForDependency(se.jbee.inject.UnresolvableDependency.NoResourceForDependency) Injector(se.jbee.inject.Injector) Test(org.junit.Test)

Example 34 with Injector

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

the class TestStateDependentBinds method thatStateChangeIsResolvedToAnotherImplementation.

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

Example 35 with Injector

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

the class TestStateDependentBinds method thatStateChangeIsProvidedToAnotherImplementation.

@Test
public void thatStateChangeIsProvidedToAnotherImplementation() {
    Injector injector = Bootstrap.injector(StateDependentBindsBundle.class);
    StatefulObject config = injector.resolve(dependency(StatefulObject.class));
    Provider<Validator> v = injector.resolve(dependency(providerTypeOf(Validator.class)));
    String input = "input";
    assertTrue(v.provide().valid(input));
    config.setValidationStrength(ValidationStrength.STRICT);
    assertFalse(v.provide().valid(input));
    config.setValidationStrength(ValidationStrength.PERMISSIVE);
    assertTrue(v.provide().valid(input));
}
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