类com.google.inject.CreationException源码实例Demo

下面列出了怎么用com.google.inject.CreationException的API类实例代码及写法,或者点击链接到github查看源代码。

@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);
    }
}
 
@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);
}
 
源代码3 项目: ProjectAres   文件: TransformableBinderTest.java
@Test
public void originalBindingRequired() throws Exception {
    assertThrows(CreationException.class, () -> {
        Guice.createInjector(binder -> {
            new TransformableBinder<>(binder, String.class);
        });
    });
}
 
源代码4 项目: ProjectAres   文件: TransformableBinderTest.java
@Test
public void regularBindingConflictsWithTransformableBinding() throws Exception {
    assertThrows(CreationException.class, () -> {
        Guice.createInjector(binder -> {
            binder.bind(String.class).toInstance("hi");
            new TransformableBinder<>(binder, String.class);
        });
    });
}
 
源代码5 项目: ProjectAres   文件: InjectableMethodTest.java
@Test
public void voidReturnType() throws Exception {
    class Woot {
        void foo() {}
    }

    InjectableMethod<?> method = InjectableMethod.forDeclaredMethod(new Woot(), "foo");
    assertThrows(CreationException.class, () ->
        Guice.createInjector(method.bindingModule())
    );
}
 
源代码6 项目: testability-explorer   文件: Testability.java
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
  }
}
 
源代码7 项目: seed   文件: CoreIT.java
@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");
}
 
源代码8 项目: attic-aurora   文件: GuiceUtilsTest.java
@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.");
    }
  });
}
 
@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.");
}
 
源代码10 项目: joynr   文件: JoynrInjectorFactoryTest.java
@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));
}
 
源代码11 项目: joynr   文件: JoynrInjectorFactoryTest.java
@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));
}
 
源代码12 项目: spoofax   文件: InjectorFactory.java
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);
    }
}
 
源代码13 项目: spoofax   文件: InjectorFactory.java
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);
    }
}
 
源代码14 项目: spoofax   文件: InjectorFactory.java
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);
    }
}
 
源代码15 项目: spoofax   文件: InjectorFactory.java
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);
    }
}
 
@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");
}
 
@Test
void startShouldFailOnBadPassword(GuiceJamesServer jamesServer) {
    assertThatThrownBy(jamesServer::start)
        .isInstanceOf(CreationException.class)
        .hasStackTraceContaining("Caused by: com.datastax.driver.core.exceptions.AuthenticationException: Authentication error");
}
 
源代码18 项目: seed   文件: PerTestExpectedIT.java
@Test
@Expected(CreationException.class)
public void injectionShouldNotWork() {
    assertThat(object).isNull();
}
 
源代码19 项目: joynr   文件: StaticCapabilitiesProvisioningTest.java
@Test(expected = CreationException.class)
public void testInvalidJson() throws IOException {
    Injector injector = createInjectorForJsonValue("this is not json");
    injector.getInstance(CapabilitiesProvisioning.class);
}
 
 类所在包
 类方法
 同包方法