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


Java Guice类代码示例

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


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

示例1: getInjector

import org.testng.annotations.Guice; //导入依赖的package包/类
@Override
public Injector getInjector(IClass iClass) {
  Annotation annotation = AnnotationHelper.findAnnotationSuperClasses(Guice.class, iClass.getRealClass());
  if (annotation == null) return null;
  if (iClass instanceof TestClass) {
    iClass = ((TestClass)iClass).getIClass();
  }
  if (!(iClass instanceof ClassImpl)) return null;
  Injector parentInjector = ((ClassImpl)iClass).getParentInjector();

  Guice guice = (Guice) annotation;
  List<Module> moduleInstances = Lists.newArrayList(getModules(guice, parentInjector, iClass.getRealClass()));

  // Reuse the previous injector, if any
  Injector injector = getInjector(moduleInstances);
  if (injector == null) {
    injector = parentInjector.createChildInjector(moduleInstances);
    addInjector(moduleInstances, injector);
  }
  return injector;
}
 
开发者ID:qmetry,项目名称:qaf,代码行数:22,代码来源:TestRunner.java

示例2: mightBeATestClass

import org.testng.annotations.Guice; //导入依赖的package包/类
/** Guessing whether or not a class is a test class is an imperfect art form. */
private boolean mightBeATestClass(Class<?> klass) {
  int klassModifiers = klass.getModifiers();
  // Test classes must be public, non-abstract, non-interface
  if (!Modifier.isPublic(klassModifiers)
      || Modifier.isInterface(klassModifiers)
      || Modifier.isAbstract(klassModifiers)) {
    return false;
  }
  // Test classes must either have a public, no-arg constructor, or have a constructor that
  // initializes using dependency injection, via the org.testng.annotations.Guice annotation on
  // the class and the com.google.inject.Inject or javax.inject.Inject annotation on the
  // constructor.
  boolean foundPublicNoArgConstructor = false;
  boolean foundInjectedConstructor = false;
  boolean hasGuiceAnnotation = klass.getAnnotationsByType(Guice.class).length > 0;
  for (Constructor<?> c : klass.getConstructors()) {
    if (Modifier.isPublic(c.getModifiers())) {
      if (c.getParameterCount() == 0) {
        foundPublicNoArgConstructor = true;
      }
      if (hasGuiceAnnotation
          && (c.getAnnotationsByType(com.google.inject.Inject.class).length > 0
              || c.getAnnotationsByType(javax.inject.Inject.class).length > 0)) {
        foundInjectedConstructor = true;
      }
    }
  }
  if (!foundPublicNoArgConstructor && !foundInjectedConstructor) {
    return false;
  }
  // Test classes must have at least one public test method (or something that generates tests)
  boolean hasAtLeastOneTestMethod = false;
  for (Method m : klass.getMethods()) {
    if (Modifier.isPublic(m.getModifiers()) && m.getAnnotation(Test.class) != null) {
      hasAtLeastOneTestMethod = true;
    }
    if (Modifier.isPublic(m.getModifiers()) && m.getAnnotation(Factory.class) != null) {
      hasAtLeastOneTestMethod = true; // technically, not *quite* true, but close enough
    }
  }
  return hasAtLeastOneTestMethod;
}
 
开发者ID:facebook,项目名称:buck,代码行数:44,代码来源:TestNGRunner.java


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