本文整理汇总了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());
}
}
示例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());
}
}
示例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());
}
}
示例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.");
}
}
示例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());
}
}
示例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.");
}
}
示例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());
}
}
示例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);
}
示例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));
}
示例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());
}
}
示例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());
}
}
示例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());
}
}
示例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());
}