当前位置: 首页>>代码示例>>Java>>正文


Java CreationException类代码示例

本文整理汇总了Java中com.google.inject.CreationException的典型用法代码示例。如果您正苦于以下问题:Java CreationException类的具体用法?Java CreationException怎么用?Java CreationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CreationException类属于com.google.inject包,在下文中一共展示了CreationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: missingLanguageThrowsExceptionByBootstrap

import com.google.inject.CreationException; //导入依赖的package包/类
@Test
public void missingLanguageThrowsExceptionByBootstrap() throws Exception {
    // bad configuration file will throw exception during ninja bootstrap
    NinjaVertx standalone = new NinjaVertx()
            .externalConfigurationPath("conf/vertx.missinglang.conf")
            .port(randomPort);

    try {
        standalone.start();
        fail("start() should have thrown exception");
    } catch (CreationException e) {
        assertThat(e.getMessage(), containsString("not retrieve application languages from ninjaProperties"));
    } finally {
        standalone.shutdown();
    }
}
 
开发者ID:kuangcao,项目名称:ninja-vertx-standalone,代码行数:17,代码来源:NinjaVertxTest.java

示例2: testFailOnConstructor

import com.google.inject.CreationException; //导入依赖的package包/类
@Test(expected = CreationException.class)
public void testFailOnConstructor() throws Exception {
    final Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            ScopedProxyBinder.using(binder())
                    .andConstructionStrategy(
                            ConstructionStrategies.FAIL_ON_CONSTRUCTOR)
                    .bind(ConcreteSampleClassWithCtor.class)
                    .to(ConcreteSampleClassWithCtor.class);
        }
    });

    injector.getInstance(ConcreteSampleClassWithCtor.class);
}
 
开发者ID:skuzzle,项目名称:guice-scoped-proxy-extension,代码行数:17,代码来源:ScopedProxyBinderTest.java

示例3: testIllegalMethods

import com.google.inject.CreationException; //导入依赖的package包/类
@Test
public void testIllegalMethods()
        throws Exception
{
    try {
        Guice.createInjector(
                Stage.PRODUCTION,
                new Module()
                {
                    @Override
                    public void configure(Binder binder)
                    {
                        binder.bind(IllegalInstance.class).in(Scopes.SINGLETON);
                    }
                },
                new LifeCycleModule());
        Assert.fail();
    }
    catch (CreationException dummy) {
        // correct behavior
    }
}
 
开发者ID:embulk,项目名称:guice-bootstrap,代码行数:23,代码来源:TestLifeCycleManager.java

示例4: shouldThrowGugisExceptionWhenImplementationsNotFound

import com.google.inject.CreationException; //导入依赖的package包/类
@Test
public void shouldThrowGugisExceptionWhenImplementationsNotFound() {

    try {
        // fail fast, Guice injector will not be created at all
        Guice.createInjector(new GugisModule());
        Assert.fail("There should be an exception thrown by Gugis validation");
    } catch (CreationException e) {
        // the following errors should be detected:
        // 1) ReportServiceComposite does not have any implementations at all
        Assert.assertTrue(e.getCause().getMessage().contains("No implementations found for " + ReportServiceComposite.class));
        // 2) AggregatorServiceComposite does not have @Primary implementations
        Assert.assertTrue(e.getCause().getMessage().contains("Composite component " + AggregatorServiceComposite.class + " methods [public void aggregate()] marked with @Propagate(propagation = Propagation.PRIMARY) but no primary implementations found"));
        // 3) SplitterServiceComposite does not have @Secondary implementations
        Assert.assertTrue(e.getCause().getMessage().contains("Composite component " + SplitterServiceComposite.class + " methods [public void split()] marked with @Propagate(propagation = Propagation.SECONDARY) but no secondary implementations found"));
    } catch (Throwable t) {
        Assert.fail("CreationException expected but got " + t.getClass());
    }

}
 
开发者ID:lukaszbudnik,项目名称:gugis,代码行数:21,代码来源:ValidationTest.java

示例5: main

import com.google.inject.CreationException; //导入依赖的package包/类
public static void main(String... args) {
  WSFRealtimeMain m = new WSFRealtimeMain();

  ArgumentParser parser = ArgumentParsers.newArgumentParser("wsf-gtfsrealtime");
  parser.description("Produces a GTFS-realtime feed from the Washington State Ferries API");
  parser.addArgument("--" + ARG_CONFIG_FILE).type(File.class).help("configuration file path");
  Namespace parsedArgs;

  try {
    parsedArgs = parser.parseArgs(args);
    File configFile = parsedArgs.get(ARG_CONFIG_FILE);
    m.run(configFile);
  } catch (CreationException | ConfigurationException | ProvisionException e) {
    _log.error("Error in startup:", e);
    System.exit(-1);
  } catch (ArgumentParserException ex) {
    parser.handleError(ex);
  }
}
 
开发者ID:kurtraschke,项目名称:wsf-gtfsrealtime,代码行数:20,代码来源:WSFRealtimeMain.java

示例6: foundGbeForTheFirstTime

import com.google.inject.CreationException; //导入依赖的package包/类
private void foundGbeForTheFirstTime(final Class<? extends Module> gbeClass) {
  Injector result = BOGUS_INJECTOR;
  try {
    Module gbeInstance = createGbeInstanceFromClass(gbeClass);
    Injector injector = Guice.createInjector(gbeInstance);
    ensureBasicBindingsExist(injector, gbeClass);
    // Get a members injector for the test class first so that we fail fast if there are missing
    // bindings instead of running the main
    getMembersInjectorForTest(gbeClass, injector);
    callGbeMainIfBound(injector);
    // We don't actually use the test wrapper here, but we make sure we can
    // get an instance (i.e. we fail fast).
    buildTestWrapperInstance(injector);
    result = injector;
  } catch (CreationException e) {
    if (e.getMessage().contains("No scope is bound to " + TestScoped.class.getName())) {
      throwAppropriateExceptionOnMissingRequiredBindings(gbeClass);
    } else {
      throw e;
    }
  } finally {
    // This is in the finally block to ensure that BOGUS_INJECTOR
    // is put in the map if things go bad.
    universe.gbeClassToInjectorMap.put(gbeClass, result);
  }
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:27,代码来源:GuiceBerryUniverse.java

示例7: testCannotInterceptBareBinding

import com.google.inject.CreationException; //导入依赖的package包/类
public void testCannotInterceptBareBinding() {
  Module module = new AbstractModule() {
    @Override
    protected void configure() {
      bind(ArrayList.class);
    }
  };

  Module built = new InterceptingBindingsBuilder()
      .intercept(ArrayList.class)
      .install(module)
      .build();

  try {
    Guice.createInjector(built);
    fail();
  } catch(CreationException expected) {
  }
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:20,代码来源:InterceptingBindingsBuilderTest.java

示例8: testAllInterceptedKeysMustBeBound

import com.google.inject.CreationException; //导入依赖的package包/类
public void testAllInterceptedKeysMustBeBound() {
  Module module = new AbstractModule() {
    @Override
    protected void configure() {
      bind(ProvisionInterceptor.class).toInstance(failingInterceptor);
    }
  };

  Module built = new InterceptingBindingsBuilder()
      .intercept(ArrayList.class)
      .install(module)
      .build();

  try {
    Guice.createInjector(built);
    fail();
  } catch(CreationException expected) {
  }
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:20,代码来源:InterceptingBindingsBuilderTest.java

示例9: testFailsInjectionBeforeRunningGuiceBerryEnvMain_MissingWrapperBinding

import com.google.inject.CreationException; //导入依赖的package包/类
/**
 * Like {@link #testFailsInjectionBeforeRunningGuiceBerryEnvMain_MissingTestBinding()}
 * except for bindings that are missing in the test wrapper.
 */
@Test public void testFailsInjectionBeforeRunningGuiceBerryEnvMain_MissingWrapperBinding() {
  GuiceBerryEnvSelector guiceBerryEnvSelector = 
    DefaultEnvSelector.of(MyGuiceBerryEnvWithGuiceBerryEnvMainThatThrowsAndWithATestWrapperWithAMissingBinding.class);
  TestDescription testDescription = new TestDescription(new MyTest(), "some test case");
  GuiceBerryUniverse.TestCaseScaffolding testCaseScaffolding = 
    new GuiceBerryUniverse.TestCaseScaffolding(testDescription, guiceBerryEnvSelector, universe);
    
  try {
    testCaseScaffolding.runBeforeTest();
    Assert.fail("The test has an unsatisfied injection, and the GuiceBerryEnvMain "
        + "throws an Exception. Either of these reasons should have prevented the "
        + "test from having gotten here.");
  } catch (MyGuiceBerryEnvWithGuiceBerryEnvMainThatThrows.GuiceBerryEnvMainWasExecutedException toThrow) {
    throw toThrow;
  } catch (CreationException expected) {}
    
  testCaseScaffolding.runAfterTest();
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:23,代码来源:GuiceBerryUniverseTest.java

示例10: addMessageIfInformative

import com.google.inject.CreationException; //导入依赖的package包/类
private void addMessageIfInformative(LinkedList<String> messages, Throwable cause) {
    if (cause instanceof ProvisionException) { // This technical exception is hidden. Only its causes should be shown.
        return;
    }
    if (cause instanceof ConfigurationException) { // A missing setting in settings.properties can cause this exception.
        ConfigurationException configurationException = (ConfigurationException) cause;
        addClearifiedErrorMessages(messages, configurationException.getErrorMessages());
        return;
    }
    if (cause instanceof CreationException) { // A missing setting in settings.properties can cause this exception.
        CreationException creationException = (CreationException) cause;
        addClearifiedErrorMessages(messages, creationException.getErrorMessages());
        return;
    }
    messages.add(cause.getMessage());
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:17,代码来源:MessagePrintingExceptionHandler.java

示例11: testFailingScanner

import com.google.inject.CreationException; //导入依赖的package包/类
public void testFailingScanner() {
  try {
    Guice.createInjector(new SomeModule(), FailingScanner.module());
    fail();
  } catch (CreationException expected) {
    Message m = Iterables.getOnlyElement(expected.getErrorMessages());
    assertEquals(
        "An exception was caught and reported. Message: Failing in the scanner.", m.getMessage());
    assertEquals(IllegalStateException.class, m.getCause().getClass());
    ElementSource source = (ElementSource) Iterables.getOnlyElement(m.getSources());
    assertEquals(
        SomeModule.class.getName(), Iterables.getOnlyElement(source.getModuleClassNames()));
    assertEquals(
        String.class.getName() + " " + SomeModule.class.getName() + ".aString()",
        source.toString());
  }
}
 
开发者ID:google,项目名称:guice,代码行数:18,代码来源:ModuleAnnotatedMethodScannerTest.java

示例12: testMultipleBindingAnnotations

import com.google.inject.CreationException; //导入依赖的package包/类
public void testMultipleBindingAnnotations() {
  try {
    Guice.createInjector(new AbstractModule() {
      @Override protected void configure() {}

      @Provides @Named("A") @Blue
      public String provideString() {
        return "a";
      }
    });
    fail();
  } catch (CreationException expected) {
    assertContains(expected.getMessage(),
        "more than one annotation annotated with @BindingAnnotation:", "Named", "Blue",
        "at " + getClass().getName(), ".provideString(ProviderMethodsTest.java:");
  }

}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:19,代码来源:ProviderMethodsTest.java

示例13: testTypeNotBoundByDefault

import com.google.inject.CreationException; //导入依赖的package包/类
public void testTypeNotBoundByDefault() {
  Module module =
      new AbstractModule() {
        @Override
        protected void configure() {
          OptionalBinder.newOptionalBinder(binder(), String.class);
          requireBinding(new Key<Optional<String>>() {}); // the above specifies this.
          requireBinding(String.class); // but it doesn't specify this.
          binder().requireExplicitBindings(); // need to do this, otherwise String will JIT

          if (HAS_JAVA_OPTIONAL) {
            requireBinding(Key.get(javaOptionalOfString));
          }
        }
      };

  try {
    Guice.createInjector(module);
    fail();
  } catch (CreationException ce) {
    assertContains(
        ce.getMessage(),
        "1) Explicit bindings are required and java.lang.String is not explicitly bound.");
    assertEquals(1, ce.getErrorMessages().size());
  }
}
 
开发者ID:google,项目名称:guice,代码行数:27,代码来源:OptionalBinderTest.java

示例14: testImplicitForwardingAssistedBindingFailsWithInterface

import com.google.inject.CreationException; //导入依赖的package包/类
public void testImplicitForwardingAssistedBindingFailsWithInterface() {
  try {
    Guice.createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        bind(Car.class).to(Golf.class);
        install(new FactoryModuleBuilder().build(ColoredCarFactory.class));
      }
    });
    fail();
  } catch (CreationException ce) {
    assertContains(
        ce.getMessage(), "1) " + Car.class.getName() + " is an interface, not a concrete class.",
        "Unable to create AssistedInject factory.",
        "while locating " + Car.class.getName(),
        "at " + ColoredCarFactory.class.getName() + ".create(");
    assertEquals(1, ce.getErrorMessages().size());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:20,代码来源:FactoryModuleBuilderTest.java

示例15: testOneMethodThatIsntGet

import com.google.inject.CreationException; //导入依赖的package包/类
public void testOneMethodThatIsntGet() {
  try {
    Guice.createInjector(new AbstractModule() {
      protected void configure() {
        install(ThrowingProviderBinder.forModule(this));
      }
      
      @SuppressWarnings("unused")
      @CheckedProvides(OneNoneGetMethod.class)
      String foo() {
          return null;
      }
    });
    fail();
  } catch(CreationException ce) {
    assertEquals(OneNoneGetMethod.class.getName() 
        + " may not declare any new methods, but declared " + Classes.toString(OneNoneGetMethod.class.getDeclaredMethods()[0]),
        Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:21,代码来源:ThrowingProviderTest.java


注:本文中的com.google.inject.CreationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。