Search in sources :

Example 71 with CreationException

use of com.google.inject.CreationException in project roboguice by roboguice.

the class MapBinderTest method testSourceLinesInMapBindings.

public void testSourceLinesInMapBindings() {
    try {
        Guice.createInjector(new AbstractModule() {

            @Override
            protected void configure() {
                MapBinder.newMapBinder(binder(), String.class, Integer.class).addBinding("one");
            }
        });
        fail();
    } catch (CreationException expected) {
        assertContains(expected.getMessage(), "1) No implementation for java.lang.Integer", "at " + getClass().getName());
    }
}
Also used : CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule)

Example 72 with CreationException

use of com.google.inject.CreationException in project roboguice by roboguice.

the class OptionalBinderTest method testDifferentBindingsFail_actual.

public void testDifferentBindingsFail_actual() {
    Module module = new AbstractModule() {

        @Override
        protected void configure() {
            OptionalBinder.newOptionalBinder(binder(), String.class).setBinding().toInstance("a");
            OptionalBinder.newOptionalBinder(binder(), String.class).setBinding().toInstance("b");
        }
    };
    try {
        Guice.createInjector(module);
        fail();
    } catch (CreationException ce) {
        assertEquals(ce.getMessage(), 1, ce.getErrorMessages().size());
        assertContains(ce.getMessage(), "1) A binding to java.lang.String annotated with @" + Actual.class.getName() + " was already configured at " + module.getClass().getName() + ".configure(", "at " + module.getClass().getName() + ".configure(");
    }
}
Also used : CreationException(com.google.inject.CreationException) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule) AbstractModule(com.google.inject.AbstractModule)

Example 73 with CreationException

use of com.google.inject.CreationException in project roboguice by roboguice.

the class OptionalBinderTest method testDifferentBindingsFail_both.

public void testDifferentBindingsFail_both() {
    Module module = new AbstractModule() {

        @Override
        protected void configure() {
            OptionalBinder.newOptionalBinder(binder(), String.class).setDefault().toInstance("a");
            OptionalBinder.newOptionalBinder(binder(), String.class).setDefault().toInstance("b");
            OptionalBinder.newOptionalBinder(binder(), String.class).setBinding().toInstance("b");
            OptionalBinder.newOptionalBinder(binder(), String.class).setBinding().toInstance("c");
        }
    };
    try {
        Guice.createInjector(module);
        fail();
    } catch (CreationException ce) {
        assertEquals(ce.getMessage(), 2, ce.getErrorMessages().size());
        assertContains(ce.getMessage(), "1) A binding to java.lang.String annotated with @" + Default.class.getName() + " was already configured at " + module.getClass().getName() + ".configure(", "at " + module.getClass().getName() + ".configure(", "2) A binding to java.lang.String annotated with @" + Actual.class.getName() + " was already configured at " + module.getClass().getName() + ".configure(", "at " + module.getClass().getName() + ".configure(");
    }
}
Also used : CreationException(com.google.inject.CreationException) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule) AbstractModule(com.google.inject.AbstractModule)

Example 74 with CreationException

use of com.google.inject.CreationException in project roboguice by roboguice.

the class FactoryProviderTest method testFactoryFailsWithMissingBinding.

public void testFactoryFailsWithMissingBinding() {
    try {
        Guice.createInjector(new AbstractModule() {

            @Override
            protected void configure() {
                bind(ColoredCarFactory.class).toProvider(FactoryProvider.newFactory(ColoredCarFactory.class, Mustang.class));
            }
        });
        fail();
    } catch (CreationException expected) {
        assertContains(expected.getMessage(), "1) Parameter of type 'double' is not injectable or annotated with @Assisted");
    }
}
Also used : CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule)

Example 75 with CreationException

use of com.google.inject.CreationException in project roboguice by roboguice.

the class ManyConstructorsTest method testTooManyMatchingConstructors.

public void testTooManyMatchingConstructors() {
    try {
        Guice.createInjector(new AbstractModule() {

            @Override
            protected void configure() {
                install(new FactoryModuleBuilder().implement(Foo.class, TooManyMatches.class).build(SimpleFactory2.class));
            }
        });
        fail("should have failed");
    } catch (CreationException expected) {
        Asserts.assertContains(expected.getMessage(), "1) " + TooManyMatches.class.getName() + " has more than one constructor annotated with @AssistedInject that " + "matches the parameters in method " + SimpleFactory2.class.getName());
    }
}
Also used : CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule)

Aggregations

CreationException (com.google.inject.CreationException)169 AbstractModule (com.google.inject.AbstractModule)163 Module (com.google.inject.Module)26 RemoteException (java.rmi.RemoteException)18 BindException (java.net.BindException)12 IOException (java.io.IOException)9 List (java.util.List)8 ImmutableList (com.google.common.collect.ImmutableList)7 PrivateModule (com.google.inject.PrivateModule)7 TooManyListenersException (java.util.TooManyListenersException)6 Provider (com.google.inject.Provider)5 Message (com.google.inject.spi.Message)5 ArrayList (java.util.ArrayList)5 Injector (com.google.inject.Injector)4 Provides (com.google.inject.Provides)4 AccessException (java.rmi.AccessException)4 Key (com.google.inject.Key)3 TypeLiteral (com.google.inject.TypeLiteral)3 JCommander (com.beust.jcommander.JCommander)2 Console (com.beust.jcommander.internal.Console)2