Status: New
Owner: ----

New issue 629 by [email protected]: createChildInjector injects wrong injector
http://code.google.com/p/google-guice/issues/detail?id=629

After createChildInjector binded class using interface fails to inject right injector.

Test case, where last two test cases fails:

package com.google.inject;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class CreateChildInjectorTest {

        private Injector parentI;
        private Injector childI;

        @Before
        public void setUp() {
                parentI = Guice.createInjector(Stage.PRODUCTION);
                childI = parentI.createChildInjector(new AbstractModule() {
                        @Override
                        protected void configure() {
                                bind(String.class).toInstance("fooBar");
                                bind(BImpl.class);
                                bind(A.class).to(AImpl.class);
                        }
                });
        };

        @Test
        public void testChildInjectorB() {
                A a = childI.getInstance(BImpl.class);
                Assert.assertEquals(childI, a.getInjector());
                Assert.assertEquals(parentI, a.getInjector().getParent());
                Assert.assertEquals("fooBar", 
a.getInjector().getInstance(String.class));
        }

        @Test
        public void testChildInjectorA1() {
                A a = childI.getInstance(A.class);
                Assert.assertEquals(childI, a.getInjector());
                Assert.assertEquals(parentI, a.getInjector().getParent());
                Assert.assertEquals("fooBar", 
a.getInjector().getInstance(String.class));
        }

        @Test(expected = Throwable.class)
        public void testChildInjectorA2() {
                A a = childI.getInstance(A.class);
                Assert.assertEquals(parentI, a.getInjector());
        }

        public static interface A {
                Injector getInjector();
        }

        static class AImpl implements A {
                private Injector inj;

                @Inject
                public AImpl(Injector inj) {
                        this.inj = inj;
                }

                @Override
                public Injector getInjector() {
                        return inj;
                }
        }

        static class BImpl extends AImpl {
                @Inject
                public BImpl(Injector inj, String val) {
                        super(inj);
                }
        }
}


--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to