dagger
dagger copied to clipboard
Inject generic mock doesn't overrides Module
Hello everyone, so basically I have this provide method in my module:
@Provides
Dao<Occasion, Long> provideOccasionDao() {
DatabaseHelper helper = DatabaseHelper.getHelper(RachadorApplication.getInstance());
return helper.getOccasionDao();
}
Then on my tests (running robolectric) I override this module with this:
@Module(
includes = {
RachadorModule.class
},
injects = {
ActivityTest.class,
BalanceTest.class,
CashSettlementUtilsTest.class,
NewOccasionDialogTest.class
},
overrides = true
)
public class TestModule {
Dao<Occasion,Long> occasionDao = mock(Dao.class);
@Provides
Context providesAppContext() {
return Robolectric.application;
}
@Provides
Dao<Occasion, Long> provideOccasionDao() {
return occasionDao;
}
}
but whenever I try to do a verify(occasionDao.something) I get a not a mock exception. I've assumed that my method is not overriding the module correctly and did this to find out:
public class TestModule {
Dao<Occasion,Long> occasionDao = null;
@Provides
Context providesAppContext() {
return Robolectric.application;
}
@Provides
Dao<Occasion, Long> provideOccasionDao() {
return occasionDao;
}
}
Then I start getting a NPE, which confirmed me that the module is overriding correctly. Why can't I inject the mock? I've done that in other project and it worked fine. This is the first time with inkecting a mocked generic tough.
Thank you for your attention. Regards
Can you post the full stack trace?