com.google.inject.CreationException Java Examples

The following examples show how to use com.google.inject.CreationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CoreIT.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@Test(expected = CreationException.class)
public void loggerInjectionThrowsErrorOnUnexpectedType() {
    try {
        injector.createChildInjector((Module) binder -> binder.bind(BadLoggerHolder.class));
    } catch (CreationException e) {
        Throwable cause = e.getCause();
        assertThat(cause).isInstanceOf(SeedException.class);
        assertThat(((SeedException) cause).getErrorCode()).isEqualTo(CoreErrorCode.BAD_LOGGER_TYPE);
        throw e;
    }
    fail("should have failed");
}
 
Example #2
Source File: InjectorFactory.java    From spoofax with Apache License 2.0 5 votes vote down vote up
public static Injector createChild(Injector parent, Module... modules) throws MetaborgException {
    try {
        return parent.createChildInjector(modules);
    } catch(CreationException e) {
        throw new MetaborgException("Could not create child injector because of dependency injection errors", e);
    }
}
 
Example #3
Source File: InjectorFactory.java    From spoofax with Apache License 2.0 5 votes vote down vote up
public static Injector createChild(Injector parent, Iterable<Module> modules) throws MetaborgException {
    try {
        return parent.createChildInjector(modules);
    } catch(CreationException e) {
        throw new MetaborgException("Could not create child injector because of dependency injection errors", e);
    }
}
 
Example #4
Source File: InjectorFactory.java    From spoofax with Apache License 2.0 5 votes vote down vote up
public static Injector create(Module... modules) throws MetaborgException {
    try {
        return Guice.createInjector(modules);
    } catch(CreationException e) {
        throw new MetaborgException("Could not create injector because of dependency injection errors", e);
    }
}
 
Example #5
Source File: InjectorFactory.java    From spoofax with Apache License 2.0 5 votes vote down vote up
public static Injector create(Iterable<Module> modules) throws MetaborgException {
    try {
        return Guice.createInjector(modules);
    } catch(CreationException e) {
        throw new MetaborgException("Could not create injector because of dependency injection errors", e);
    }
}
 
Example #6
Source File: JoynrInjectorFactoryTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Test
public void applicationLevelDefaultPropertiesCannotOverrideJoynDefaultProperties() {
    creationException.expect(CreationException.class);
    creationException.expectMessage(StringContains.containsString("A binding to java.lang.String annotated with @com.google.inject.name.Named(value=joynr.messaging.bounceproxyurl) was already configured"));

    injectorfactory.createApplication(new TestApplicationModule(applicationCreationProperties, true));
}
 
Example #7
Source File: JoynrInjectorFactoryTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Test
public void applicationCreationPropertiesCannotOverrideJoynFactoryProperties() {
    creationException.expect(CreationException.class);
    creationException.expectMessage(StringContains.containsString("A binding to java.lang.String annotated with @com.google.inject.name.Named(value=joynr.messaging.bounceproxyurl) was already configured"));

    applicationCreationProperties.setProperty(MessagingPropertyKeys.BOUNCE_PROXY_URL,
                                              "http://test-bounce-proxy-url");

    injectorfactory.createApplication(new TestApplicationModule(applicationCreationProperties));
}
 
Example #8
Source File: StaticCapabilitiesProvisioningTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Test(expected = CreationException.class)
public void testIncompleteLegacySettings() throws IOException {
    LegacyCapabilitiesProvisioning.LegacyProvisioningPropertiesHolder properties = createLegacyProvisioningPropertiesHolder();
    properties.capabilitiesDirectoryParticipantId = "";
    Set<DiscoveryEntry> discoveryEntries = createDiscoveryEntries("io.joynr",
                                                                  GlobalCapabilitiesDirectory.INTERFACE_NAME,
                                                                  GlobalDomainAccessController.INTERFACE_NAME);
    final String serializedDiscoveryEntries = objectMapper.writeValueAsString(discoveryEntries);
    createInjectorForJsonValue(serializedDiscoveryEntries, properties);
    fail("Expecting legacy capabilities provisioning to fail fast.");
}
 
Example #9
Source File: GuiceUtilsTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Test(expected = CreationException.class)
public void testNoTrappingNonVoidMethods() {
  Guice.createInjector(new AbstractModule() {
    @Override
    protected void configure() {
      GuiceUtils.bindExceptionTrap(binder(), NonVoid.class);
      fail("Bind should have failed.");
    }
  });
}
 
Example #10
Source File: HiveMQExceptionHandlerBootstrap.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static void handleUncaughtException(final Thread t, final Throwable e) {
    if (e instanceof UnrecoverableException) {
        if (((UnrecoverableException) e).isShowException()) {
            log.error("An unrecoverable Exception occurred. Exiting HiveMQ", t, e);
        }
        System.exit(1);
    } else if (e instanceof CreationException) {
        if (e.getCause() instanceof UnrecoverableException) {
            log.error("An unrecoverable Exception occurred. Exiting HiveMQ");
            System.exit(1);
        }

        final CreationException creationException = (CreationException) e;
        checkGuiceErrorsForUnrecoverable(creationException.getErrorMessages());

    } else if (e instanceof ProvisionException) {
        if (e.getCause() instanceof UnrecoverableException) {
            log.error("An unrecoverable Exception occurred. Exiting HiveMQ");
            System.exit(1);
        }

        final ProvisionException provisionException = (ProvisionException) e;
        checkGuiceErrorsForUnrecoverable(provisionException.getErrorMessages());


    }
    final Throwable rootCause = Throwables.getRootCause(e);
    if (rootCause instanceof UnrecoverableException) {
        final boolean showException = ((UnrecoverableException) rootCause).isShowException();
        if (showException) {
            log.error("Cause: ", e);
        }
    } else {
        log.error("Uncaught Error:", e);
    }
}
 
Example #11
Source File: Testability.java    From testability-explorer with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) {
  try {
    Guice.createInjector(
        new ConfigModule(args, System.out, System.err),
        new TestabilityModule()).
        getInstance(Testability.class).
        run();
  } catch (CreationException e) {
    // ignore, the error is printed in the ConfigModule
  }
}
 
Example #12
Source File: InjectableMethodTest.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void voidReturnType() throws Exception {
    class Woot {
        void foo() {}
    }

    InjectableMethod<?> method = InjectableMethod.forDeclaredMethod(new Woot(), "foo");
    assertThrows(CreationException.class, () ->
        Guice.createInjector(method.bindingModule())
    );
}
 
Example #13
Source File: TransformableBinderTest.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void regularBindingConflictsWithTransformableBinding() throws Exception {
    assertThrows(CreationException.class, () -> {
        Guice.createInjector(binder -> {
            binder.bind(String.class).toInstance("hi");
            new TransformableBinder<>(binder, String.class);
        });
    });
}
 
Example #14
Source File: TransformableBinderTest.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void originalBindingRequired() throws Exception {
    assertThrows(CreationException.class, () -> {
        Guice.createInjector(binder -> {
            new TransformableBinder<>(binder, String.class);
        });
    });
}
 
Example #15
Source File: HiveMQExceptionHandlerBootstrapTest.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
@Test
public void test_creationException() {
    exit.expectSystemExitWithStatus(1);
    final CreationException creationException = new CreationException(Collections.singletonList(new Message("test",
            new UnrecoverableException(false))));

    HiveMQExceptionHandlerBootstrap.handleUncaughtException(Thread.currentThread(), creationException);
}
 
Example #16
Source File: PerTestExpectedIT.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
@Test
@Expected(CreationException.class)
public void injectionShouldNotWork() {
    assertThat(object).isNull();
}
 
Example #17
Source File: AuthenticatedCassandraJamesServerTest.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Test
void startShouldFailOnBadPassword(GuiceJamesServer jamesServer) {
    assertThatThrownBy(jamesServer::start)
        .isInstanceOf(CreationException.class)
        .hasStackTraceContaining("Caused by: com.datastax.driver.core.exceptions.AuthenticationException: Authentication error");
}
 
Example #18
Source File: StaticCapabilitiesProvisioningTest.java    From joynr with Apache License 2.0 4 votes vote down vote up
@Test(expected = CreationException.class)
public void testInvalidJson() throws IOException {
    Injector injector = createInjectorForJsonValue("this is not json");
    injector.getInstance(CapabilitiesProvisioning.class);
}
 
Example #19
Source File: AuthenticatedCassandraJamesServerTest.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Test
void startShouldFailWhenSslUsedAndNotSupportedByServer(GuiceJamesServer jamesServer) {
    assertThatThrownBy(jamesServer::start)
        .isInstanceOf(CreationException.class)
        .hasStackTraceContaining("Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed");
}