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()); } }
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()); } }
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()); } }
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."); } }
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()); } }
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."); } }
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()); } }
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); }
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)); }
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()); } }
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()); } }
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()); } }
public void testResultSerializes() throws Exception { Result result = Result.forValue("foo"); result = Asserts.reserialize(result); assertEquals("foo", result.getOrThrow()); }