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


Java Asserts类代码示例

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


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

示例1: testTooManyMatchingConstructors

import com.google.inject.Asserts; //导入依赖的package包/类
public void testTooManyMatchingConstructors() {
  try {
    Guice.createInjector(
        new AbstractModule() {
          @Override
          protected void configure() {
            install(
                new FactoryModuleBuilder()
                    .implement(Foo.class, TooManyMatches.class)
                    .build(SimpleFactory2.class));
          }
        });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(
        expected.getMessage(),
        "1) "
            + TooManyMatches.class.getName()
            + " has more than one constructor annotated with @AssistedInject that "
            + "matches the parameters in method "
            + SimpleFactory2.class.getName());
  }
}
 
开发者ID:google,项目名称:guice,代码行数:24,代码来源:ManyConstructorsTest.java

示例2: testNoMatchingConstructorsBecauseTooManyParams

import com.google.inject.Asserts; //导入依赖的package包/类
public void testNoMatchingConstructorsBecauseTooManyParams() {
  try {
    Guice.createInjector(
        new AbstractModule() {
          @Override
          protected void configure() {
            install(new FactoryModuleBuilder().build(ComplexFactory.class));
          }
        });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(
        expected.getMessage(),
        "1) "
            + Foo.class.getName()
            + " has @AssistedInject constructors, but none of them match the parameters in method "
            + ComplexFactory.class.getName());
  }
}
 
开发者ID:google,项目名称:guice,代码行数:20,代码来源:ManyConstructorsTest.java

示例3: testNoMatchingConstrucotsBecauseTooLittleParams

import com.google.inject.Asserts; //导入依赖的package包/类
public void testNoMatchingConstrucotsBecauseTooLittleParams() {
  try {
    Guice.createInjector(
        new AbstractModule() {
          @Override
          protected void configure() {
            install(new FactoryModuleBuilder().build(NullFactory.class));
          }
        });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(
        expected.getMessage(),
        "1) "
            + Foo.class.getName()
            + " has @AssistedInject constructors, but none of them match the parameters in method "
            + NullFactory.class.getName());
  }
}
 
开发者ID:google,项目名称:guice,代码行数:20,代码来源:ManyConstructorsTest.java

示例4: testToolStageWarnsOfMissingObjectGraph

import com.google.inject.Asserts; //导入依赖的package包/类
public void testToolStageWarnsOfMissingObjectGraph() {
  final Bar bar = new Bar();
  try {
    Guice.createInjector(
        Stage.TOOL,
        new AbstractModule() {
          @Override
          protected void configure() {
            requestStaticInjection(Bar.class);
            requestInjection(bar);
          }
        });
    fail("expected exception");
  } catch (CreationException expected) {
    Asserts.assertContains(
        expected.toString(),
        "No implementation for java.util.Collection was bound.",
        "No implementation for java.util.Map was bound.",
        "No implementation for java.util.List was bound.",
        "No implementation for java.util.Set was bound.");
  }
}
 
开发者ID:google,项目名称:guice,代码行数:23,代码来源:ToolStageInjectorTest.java

示例5: testTooManyMatchingConstructors

import com.google.inject.Asserts; //导入依赖的package包/类
public void testTooManyMatchingConstructors() {
  try {
    Guice.createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        install(new FactoryModuleBuilder()
          .implement(Foo.class, TooManyMatches.class)
          .build(SimpleFactory2.class));
      }
    });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(expected.getMessage(), "1) " + TooManyMatches.class.getName()
        + " has more than one constructor annotated with @AssistedInject that "
        + "matches the parameters in method " + SimpleFactory2.class.getName());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:18,代码来源:ManyConstructorsTest.java

示例6: testToolStageWarnsOfMissingObjectGraph

import com.google.inject.Asserts; //导入依赖的package包/类
public void testToolStageWarnsOfMissingObjectGraph() {
  final Bar bar = new Bar();
  try {
    Guice.createInjector(Stage.TOOL, new AbstractModule() {
      @Override
      protected void configure() {
        requestStaticInjection(Bar.class);
        requestInjection(bar);
      }
    });
    fail("expected exception");
  } catch(CreationException expected) {
    Asserts.assertContains(expected.toString(), "No implementation for java.util.Collection was bound.",
        "No implementation for java.util.Map was bound.",
        "No implementation for java.util.List was bound.",
        "No implementation for java.util.Set was bound.");
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:19,代码来源:ToolStageInjectorTest.java

示例7: testResultExceptionSerializes

import com.google.inject.Asserts; //导入依赖的package包/类
public void testResultExceptionSerializes() throws Exception {
  Result result = Result.forException(new Exception("boo"));
  result = Asserts.reserialize(result);
  try {
    result.getOrThrow();
    fail();
  } catch (Exception ex) {
    assertEquals("boo", ex.getMessage());
  }
}
 
开发者ID:google,项目名称:guice,代码行数:11,代码来源:CheckedProviderTest.java

示例8: testWeakKeySet_integration_mapbinder

import com.google.inject.Asserts; //导入依赖的package包/类
public void testWeakKeySet_integration_mapbinder() {
  Key<Map<String, String>> mapKey = Key.get(new TypeLiteral<Map<String, String>>() {});

  Injector parentInjector =
      Guice.createInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              bind(String.class).toInstance("hi");
            }
          });
  WeakKeySetUtils.assertNotBlacklisted(parentInjector, mapKey);

  Injector childInjector =
      parentInjector.createChildInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              MapBinder<String, String> binder =
                  MapBinder.newMapBinder(binder(), String.class, String.class);
              binder.addBinding("bar").toInstance("foo");
            }
          });
  WeakReference<Injector> weakRef = new WeakReference<>(childInjector);
  WeakKeySetUtils.assertBlacklisted(parentInjector, mapKey);

  // Clear the ref, GC, and ensure that we are no longer blacklisting.
  childInjector = null;

  Asserts.awaitClear(weakRef);
  WeakKeySetUtils.assertNotBlacklisted(parentInjector, mapKey);
}
 
开发者ID:google,项目名称:guice,代码行数:33,代码来源:MapBinderTest.java

示例9: testWeakKeySet_integration

import com.google.inject.Asserts; //导入依赖的package包/类
public void testWeakKeySet_integration() {
  Injector parentInjector =
      Guice.createInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              bind(String.class).toInstance("hi");
            }
          });
  WeakKeySetUtils.assertNotBlacklisted(parentInjector, Key.get(Integer.class));

  Injector childInjector =
      parentInjector.createChildInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              OptionalBinder.newOptionalBinder(binder(), Integer.class)
                  .setDefault()
                  .toInstance(4);
            }
          });
  WeakReference<Injector> weakRef = new WeakReference<>(childInjector);
  WeakKeySetUtils.assertBlacklisted(parentInjector, Key.get(Integer.class));

  // Clear the ref, GC, and ensure that we are no longer blacklisting.
  childInjector = null;

  Asserts.awaitClear(weakRef);
  WeakKeySetUtils.assertNotBlacklisted(parentInjector, Key.get(Integer.class));
}
 
开发者ID:google,项目名称:guice,代码行数:31,代码来源:OptionalBinderTest.java

示例10: testNoMatchingConstructorsBecauseTooManyParams

import com.google.inject.Asserts; //导入依赖的package包/类
public void testNoMatchingConstructorsBecauseTooManyParams() {
  try {
    Guice.createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        install(new FactoryModuleBuilder().build(ComplexFactory.class));
      }
    });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(expected.getMessage(), "1) " + Foo.class.getName()
        + " has @AssistedInject constructors, but none of them match the parameters in method "
        + ComplexFactory.class.getName());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:16,代码来源:ManyConstructorsTest.java

示例11: testNoMatchingConstrucotsBecauseTooLittleParams

import com.google.inject.Asserts; //导入依赖的package包/类
public void testNoMatchingConstrucotsBecauseTooLittleParams() {
  try {
    Guice.createInjector(new AbstractModule() {
      @Override
      protected void configure() {
        install(new FactoryModuleBuilder().build(NullFactory.class));
      }
    });
    fail("should have failed");
  } catch (CreationException expected) {
    Asserts.assertContains(expected.getMessage(), "1) " + Foo.class.getName()
        + " has @AssistedInject constructors, but none of them match the parameters in method "
        + NullFactory.class.getName());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:16,代码来源:ManyConstructorsTest.java

示例12: testResultExceptionSerializes

import com.google.inject.Asserts; //导入依赖的package包/类
public void testResultExceptionSerializes() throws Exception {
  Result result = Result.forException(new Exception("boo"));
  result = Asserts.reserialize(result);
  try {
    result.getOrThrow();
    fail();
  } catch(Exception ex) {
    assertEquals("boo", ex.getMessage());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:11,代码来源:CheckedProviderTest.java

示例13: testResultSerializes

import com.google.inject.Asserts; //导入依赖的package包/类
public void testResultSerializes() throws Exception {
  Result result = Result.forValue("foo");
  result = Asserts.reserialize(result);
  assertEquals("foo", result.getOrThrow());
}
 
开发者ID:google,项目名称:guice,代码行数:6,代码来源:CheckedProviderTest.java


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