I use a helper class TestUtil with the following static method:
public static<T> Provider<T> provide(T val) {
@SuppressWarnings("unchecked")
Provider<T> ret = (Provider<T>) mock(Provider.class);
when(ret.get()).thenReturn(val);
return ret;
}
Using as follows:
Dep dep = mock(Dep.class);
ClassUnderTest uit = new ClassUnderTest(TestUtil.provide(dep));
use of Injector in unit test: not good
Peter
On Sat, Apr 9, 2011 at 9:20 AM, Ido Ran <[email protected]> wrote:
> Hi,
> I am wondering how to unit test a class which has dependency on Provider<T>?
> I rather not use Injector in the unit test so does it means I have to mock
> Provider<T> ? or it there other way?
> Also does the use of Injector is good or not so good in a unit test?
> Thank you,
> Ido.
>
> --
> 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.
>
--
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.