Tests for required dependencies?

27 views
Skip to first unread message

Kevin Burton

unread,
Oct 16, 2014, 2:00:30 PM10/16/14
to google...@googlegroups.com
Is there an easy way to require that your dependencies are met without actually having to call getInstance or have an instance of an object?

This should be easy since I can build a graph of the connections between Classes.

Some of my instances require complex init and external dependencies like Cassandra and ActiveMQ... I don't to have to require these in my unit tests because they are hefty.

I'd like to inject Session which is a Cassandra object bound to a given connection... but of course I would have to create that object manually.

Is there a cleaner way to do this?

This way I could have some basic tests for production bindings to make sure the bindings are complete and all dependencies met.

Sam Berlin

unread,
Oct 16, 2014, 2:03:36 PM10/16/14
to google...@googlegroups.com
If you don't inject the injector anyway, wouldn't creating the injector (in Stage.TOOL if you want to prevent creating anything) cover this?

sam

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/1e68a134-5614-446f-9463-6a500c8f7ca2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kevin Burton

unread,
Oct 16, 2014, 3:31:03 PM10/16/14
to google...@googlegroups.com
I don't follow.. I can't parse your sentence.  

Sam Berlin

unread,
Oct 16, 2014, 3:35:17 PM10/16/14
to google...@googlegroups.com
So long as you have no code that has @Inject Injector (and then later calls .getInstance(Something.class), because Guice can't statically detect that), then calling Guice.createInjector(MyModule(), Stage.TOOL) should fail if you're missing dependencies.

sam

Kevin Burton

unread,
Oct 16, 2014, 5:34:35 PM10/16/14
to google...@googlegroups.com
AH!! Gotcha.  OK.  That rocks.. I'll look into that now.
Reply all
Reply to author
Forward
0 new messages