Search in sources :

Example 56 with CreationException

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

the class ProvidesIntoTest method testMapKeyMissingValueMethod.

public void testMapKeyMissingValueMethod() {
    Module m = new AbstractModule() {

        @Override
        protected void configure() {
        }

        @ProvidesIntoMap
        @MissingValueMethod
        String provideFoo() {
            return "foo";
        }
    };
    try {
        Guice.createInjector(MultibindingsScanner.asModule(), m);
        fail();
    } catch (CreationException ce) {
        assertEquals(1, ce.getErrorMessages().size());
        assertContains(ce.getMessage(), "No 'value' method in MapKey with unwrapValue=true: " + MissingValueMethod.class.getName());
    }
}
Also used : CreationException(com.google.inject.CreationException) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule) AbstractModule(com.google.inject.AbstractModule)

Example 57 with CreationException

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

the class ProvidesIntoTest method testMoreThanOneMapKeyAnnotation.

public void testMoreThanOneMapKeyAnnotation() {
    Module m = new AbstractModule() {

        @Override
        protected void configure() {
        }

        @ProvidesIntoMap
        @TestEnumKey(TestEnum.A)
        @TestEnumKey2(TestEnum.B)
        String provideFoo() {
            return "foo";
        }
    };
    try {
        Guice.createInjector(MultibindingsScanner.asModule(), m);
        fail();
    } catch (CreationException ce) {
        assertEquals(1, ce.getErrorMessages().size());
        assertContains(ce.getMessage(), "Found more than one MapKey annotations on " + m.getClass().getName() + ".provideFoo");
    }
}
Also used : CreationException(com.google.inject.CreationException) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule) AbstractModule(com.google.inject.AbstractModule)

Example 58 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 59 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 60 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)

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