Are you really expecting an injection of List<InputSourceStringImpl> or are
you expecting an injection of List<InputSourceString>?

On Wed, Mar 31, 2010 at 3:55 PM, cdawg92 <[email protected]> wrote:

> I hope someone can help as I'm starting to pull my hair out. I'm using
> a Guice module in the class I'm testing to return back some instances
> of lists. Guice injects the types in the list. Anyway, here is a
> snippet of the code in the class I'm testing:
>
>                Injector srcInjector = Guice.createInjector(new
> SourcesModule(serverProps));
>                inputSources = srcInjector.getInstance(Key.get(new
> TypeLiteral
> <List<InputSourceStringImpl>>(){}));
>                outputSources = srcInjector.getInstance(Key.get(new
> TypeLiteral
> <List<OutputSourceStringImpl>>(){}));
>
> I need to be able to override the SourcesModule to inject some mock
> sources for proper testing. I've tried the following in my tests but
> the override is not working as the sources are still injected by
> SourcesModule:
>
>  Injector injector = Guice.createInjector( new AbstractModule(){
>                                                @Override
>                                                protected void configure() {
>                                                        bind(new
> TypeLiteral<List<String>>() {}).toInstance(servers);
>
>  bind(ListenerDAO.class).to(MockDAO.class);
>                                                        bind(new
> TypeLiteral<List<ServerProperties>>()
> {}).toInstance(listDefaultServerProperties);
>
>                                                }
>
>                                        }
>                                ,Modules.override(new
> SourcesModule(Arrays.asList(defaultServerProperties))).with(
>                                                new AbstractModule(){
>                                                        @Override
>                                                        protected void
> configure() {
>                                                        }
>
>  @SuppressWarnings("unused")
>                                                        @Provides
>                                                        private
> List<InputSourceStringImpl> provideInputSources(){
>                                                                return
> injectedInputs;
>                                                        }
>
>                                }));
>                ListenerController controller =
> injector.getInstance(ListenerController.class);
>
> injectedInputs is a List of my mock sources.
>
> Am I just going about the override incorrectly or is my implementation
> of Guice with the SourcesModule incompatible with testing? Any help
> would be appreciated.
>
> Thanks,
> Carl.
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-guice%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" 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?hl=en.

Reply via email to