Re: creating instance using injector without passing module info again.

2013-10-15 Thread Tim Boudreau
On Tuesday, October 8, 2013 4:56:47 AM UTC-4, kumar santosh wrote:

 1. I have class AModule  where we are binding are the dependencies. 

 2.  In class Test i created Instance of B using Injector. like .
   Injector in = Guice.createInjector(new AModule())
 // getting instance of B  
  in.getInstance(B);

 3. I am in same jvm, In some other class D,  can i get instance of some 
 class C without again  calling Guice.createInjector(new AModule())


Two ways:
 - Create D using the injector, and have B injected into it (this is pretty 
much *the* thing Guice is good for)
 - Pass a reference to the injector from Test to D.

If there is no connection between B and D at all, maybe there is some code 
which instantiates both of them?  I hesitate to say put the injector into 
a static field since that's exactly the pattern Guice exists to eliminate, 
but if it's test code and there's really *no* other way, it would work. 
 But I'd say reconsider your design if that looks like the way you have to 
do it.

-Tim

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.


Re: creating instance using injector without passing module info again.

2013-10-15 Thread Tim Boudreau
On Tuesday, October 8, 2013 12:01:40 PM UTC-4, Nate Bauernfeind wrote:

 I tend to avoid using Guice for most tests as I find it hard to actually 
 get decent tests when Guice is in the mix.

Interesting.  As the author of one Guice-based test framework, I'm curious 
what problems you run into.

For any specific class I want to treat I heavily make use of mockito, and 
 so to even use Guice I would create an override module with the mocks and 
 effectively ends up giving a false sense of security related to any Guice 
 code.

How is the sense of security you get from machine-generated mocks different 
from the sense of security you'd get from hand-written mocks? :-)

-Tim

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.


Re: creating instance using injector without passing module info again.

2013-10-09 Thread kumar santosh
My question is unanswered. i will try to rephrase my question

On Tuesday, 8 October 2013 21:31:40 UTC+5:30, Nate Bauernfeind wrote:

 I tend to avoid using Guice for most tests as I find it hard to actually 
 get decent tests when Guice is in the mix.

 For any specific class I want to treat I heavily make use of mockito, and 
 so to even use Guice I would create an override module with the mocks and 
 effectively ends up giving a false sense of security related to any Guice 
 code.

 Typically speaking you shouldn't have any branching logic in your modules, 
 which luckily reduces the scope of what needs to be tested. To test my 
 Guice modules, I tend to create a test which constructs a single module 
 (usually a scoped portion of my application) and I mix in a second module 
 with mocks bound for any class that is a dependency of the module.

 That helps keep track of accidentally forgetting to bind something 
 somewhere and check-in code that won't technically run. I also require 
 explicit bindings and try to make use of private modules as extensively as 
 possible.

 Have you, or anyone else, found a few use cases where you can get better 
 tests (either more readable code or even different kind of tests) with 
 reusing your Guice modules?

 Nate
 On Oct 8, 2013 4:05 AM, kumar santosh san...@gmail.com javascript: 
 wrote:

 1. I have class AModule  where we are binding are the dependencies. 

 2.  In class Test i created Instance of B using Injector. like .
   Injector in = Guice.createInjector(new AModule())
 // getting instance of B  
  in.getInstance(B);

 3. I am in same jvm, In some other class D,  can i get instance of some 
 class C without again  calling Guice.createInjector(new AModule())
  
 -- 
 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 javascript:.
 To post to this group, send email to google...@googlegroups.comjavascript:
 .
 Visit this group at http://groups.google.com/group/google-guice.
 For more options, visit https://groups.google.com/groups/opt_out.



-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.


Re: creating instance using injector without passing module info again.

2013-10-08 Thread Stephan Classen
When you are using Guice in unit test I recommend you look at a testing 
framework which uses Guice.


https://github.com/ArcBees/Jukito
http://onami.apache.org/test/


On 10/08/2013 10:56 AM, kumar santosh wrote:

1. I have class AModule  where we are binding are the dependencies.

2.  In class Test i created Instance of B using Injector. like .
  Injector in = Guice.createInjector(new AModule())
// getting instance of B
 in.getInstance(B);

3. I am in same jvm, In some other class D,  can i get instance of 
some class C without again  calling Guice.createInjector(new AModule())

--
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+unsubscr...@googlegroups.com.

To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.


--
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+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.


Re: creating instance using injector without passing module info again.

2013-10-08 Thread Cédric Beust ♔
And of course, TestNG:
http://beust.com/weblog/2010/12/10/testng-and-guice-a-marriage-made-in-heaven/

-- 
Cédric



On Tue, Oct 8, 2013 at 2:34 AM, Stephan Classen st.clas...@gmx.ch wrote:

  When you are using Guice in unit test I recommend you look at a testing
 framework which uses Guice.

 https://github.com/ArcBees/Jukito
 http://onami.apache.org/test/



 On 10/08/2013 10:56 AM, kumar santosh wrote:

 1. I have class AModule  where we are binding are the dependencies.

  2.  In class Test i created Instance of B using Injector. like .
   Injector in = Guice.createInjector(new AModule())
 // getting instance of B
  in.getInstance(B);

  3. I am in same jvm, In some other class D,  can i get instance of some
 class C without again  calling Guice.createInjector(new AModule())
  --
 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+unsubscr...@googlegroups.com.
 To post to this group, send email to google-guice@googlegroups.com.
 Visit this group at http://groups.google.com/group/google-guice.
 For more options, visit https://groups.google.com/groups/opt_out.


  --
 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+unsubscr...@googlegroups.com.
 To post to this group, send email to google-guice@googlegroups.com.
 Visit this group at http://groups.google.com/group/google-guice.
 For more options, visit https://groups.google.com/groups/opt_out.


-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.