Search in sources :

Example 61 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)

Example 62 with CreationException

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

the class ToolStageInjectorTest method testToolStageWarnsOfMissingObjectGraph.

public void testToolStageWarnsOfMissingObjectGraph() {
    final Bar bar = new Bar();
    try {
        Guice.createInjector(Stage.TOOL, new AbstractModule() {

            @Override
            protected void configure() {
                requestStaticInjection(Bar.class);
                requestInjection(bar);
            }
        });
        fail("expected exception");
    } catch (CreationException expected) {
        Asserts.assertContains(expected.toString(), "No implementation for java.util.Collection was bound.", "No implementation for java.util.Map was bound.", "No implementation for java.util.List was bound.", "No implementation for java.util.Set was bound.");
    }
}
Also used : CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule)

Example 63 with CreationException

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

the class FactoryModuleBuilderTest method testSingletonScopeOnAssistedClassIsIgnored.

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

            @Override
            protected void configure() {
                install(new FactoryModuleBuilder().build(SingletonFactory.class));
            }
        });
        fail();
    } catch (CreationException ce) {
        assertEquals(1, ce.getErrorMessages().size());
        assertEquals("Found scope annotation [" + Singleton.class.getName() + "]" + " on implementation class [" + AssistedSingleton.class.getName() + "]" + " of AssistedInject factory [" + SingletonFactory.class.getName() + "]." + "\nThis is not allowed, please remove the scope annotation.", Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
    }
}
Also used : Singleton(com.google.inject.Singleton) CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule)

Example 64 with CreationException

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

the class FactoryProviderTest method testAssistedInjectConstructorAndAssistedFactoryParameterMustNotMix.

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

            @Override
            protected void configure() {
                bind(Double.class).toInstance(5.0d);
                bind(AssistedParamsFactory.class).toProvider(FactoryProvider.newFactory(AssistedParamsFactory.class, Mustang.class));
            }
        });
        fail();
    } catch (CreationException expected) {
        assertContains(expected.getMessage(), "Factory method " + AssistedParamsFactory.class.getName() + ".create() has an @Assisted parameter, which " + "is incompatible with the deprecated @AssistedInject annotation.");
    }
}
Also used : CreationException(com.google.inject.CreationException) AbstractModule(com.google.inject.AbstractModule)

Example 65 with CreationException

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

the class ProviderMethodsTest method testVoidProviderMethods.

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

            @Override
            protected void configure() {
            }

            @Provides
            void provideFoo() {
            }
        });
        fail();
    } catch (CreationException expected) {
        assertContains(expected.getMessage(), "1) Provider methods must return a value. Do not return void.", getClass().getName(), ".provideFoo(ProviderMethodsTest.java:");
    }
}
Also used : CreationException(com.google.inject.CreationException) Provides(com.google.inject.Provides) 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