I use constructor injection and the injected objects are mockito objects.

To help things a little with using @Mock attributes I have a simple base
test class:

public class MockedTester {
    public MockedTester() {
        MockitoAnnotations.initMocks(this);
    }
}

public class DomainBlackListTest extends MockedTester {
   @Mock public EventBus eb;
   @Mock public EventBusSingleton eventBus;

   @Before public void initMocks() {
       when(eventBus.getEventBus())
           .thenReturn(eb);
   }

   @Test public void simple() {
      DomainBlackList d = new DomainBlackList(eventBus);
      .....

   }

}


On Mon, Nov 4, 2013 at 9:15 AM, Stephan Classen <[email protected]> wrote:

> see: https://groups.google.com/forum/#!topic/google-guice/NEkahqnpY4k
>
>
>
>
> On 11/04/2013 05:09 PM, Ari King wrote:
>
>> How can I mock injected dependencies in JUnit tests? Thanks.
>> --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> 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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to