I am using Dagger 2 and have a few issues with generate singleton providers in the module when implementing tests for my class.
class SomeContentProvider extends ContentProvider {
    // this should be normal foo if run by application, 
    // or mocked foo if run by tests
    @Inject Foo foo;
    public Provider() {
        Component.getComponent().inject(this);
    }
}
@Module
class ProviderModule {
    @Singleton
    @Provides
    Foo providesFoo() {
        returns new Foo();
    }
}
@Module
class ProviderTestModule {
    @Singleton
    @Provides
    Foo providesFoo() {
        returns Mockito.mock(Foo.class);
    }
}
public class SomeContentProviderTests extends InstrumentationTestCase {
    @Inject Foo foo; // this should be mocked Foo
    @Override
    public void setUp() throws Exception {
        super.setUp();
        MockitoAnnotations.initMocks(this);
        Component.getTestComponent().inject(this);
    }
    public void test1() {
        // needs new instance of Foo when test1 is run from SomeContentProvider
    }
    public void test2() {
        // needs another new instance of Foo when test2 is run from SomeContentProvider
    }
}
So I have 2 questions.
- I cannot use constructor injection as - ContentProviderhas a default constructor. How does- SomeContentProviderget the Foo from the the test module?
- In - test1and- test2, how do I ensure that a new instance of- Foois created when each test is being run?
Thanks!
 
    