Search in sources :

Example 16 with CreationException

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

the class BoundFieldModuleTest method testRawProviderCannotBeBound.

public void testRawProviderCannotBeBound() {
    final Integer testValue = 1024;
    Object instance = new Object() {

        @Bind
        private Provider anIntProvider = new Provider() {

            @Override
            public Object get() {
                return testValue;
            }
        };
    };
    BoundFieldModule module = BoundFieldModule.of(instance);
    try {
        Guice.createInjector(module);
        fail();
    } catch (CreationException e) {
        assertContains(e.getMessage(), "Non parameterized Provider fields must have an " + "explicit binding class via @Bind(to = Foo.class)");
    }
}
Also used : CreationException(com.google.inject.CreationException) Provider(com.google.inject.Provider)

Example 17 with CreationException

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

the class FactoryModuleBuilderTest method testImplicitForwardingAssistedBindingFailsWithAbstractClass.

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

            @Override
            protected void configure() {
                bind(AbstractCar.class).to(ArtCar.class);
                install(new FactoryModuleBuilder().build(ColoredAbstractCarFactory.class));
            }
        });
        fail();
    } catch (CreationException ce) {
        assertContains(ce.getMessage(), "1) " + AbstractCar.class.getName() + " is abstract, not a concrete class.", "Unable to create AssistedInject factory.", "while locating " + AbstractCar.class.getName(), "at " + ColoredAbstractCarFactory.class.getName() + ".create(");
        assertEquals(1, ce.getErrorMessages().size());
    }
}
Also used : CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule)

Example 18 with CreationException

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

the class FactoryModuleBuilderTest method testExplicitForwardingAssistedBindingFailsWithAbstractClass.

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

            @Override
            protected void configure() {
                bind(AbstractCar.class).to(ArtCar.class);
                install(new FactoryModuleBuilder().implement(Car.class, AbstractCar.class).build(ColoredCarFactory.class));
            }
        });
        fail();
    } catch (CreationException ce) {
        assertContains(ce.getMessage(), "1) " + AbstractCar.class.getName() + " is abstract, not a concrete class.", "Unable to create AssistedInject factory.", "while locating " + AbstractCar.class.getName(), "while locating " + Car.class.getName(), "at " + ColoredCarFactory.class.getName() + ".create(");
        assertEquals(1, ce.getErrorMessages().size());
    }
}
Also used : CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule)

Example 19 with CreationException

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

the class Jsr330Test method testInjectingFinalFieldsIsForbidden.

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

            protected void configure() {
                bind(L.class);
            }
        });
        fail();
    } catch (CreationException expected) {
        assertContains(expected.getMessage(), "1) Injected field " + L.class.getName() + ".b cannot be final.");
    }
}
Also used : CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule)

Example 20 with CreationException

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

the class Jsr330Test method testInjectingMethodsWithTypeParametersIsForbidden.

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

            protected void configure() {
                bind(N.class);
            }
        });
        fail();
    } catch (CreationException expected) {
        assertContains(expected.getMessage(), "1) Injected method " + N.class.getName() + ".setB() cannot declare type parameters of its own.");
    }
}
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