Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Inject generic mock doesn't overrides Module #438

Open
mazoni opened this issue Sep 13, 2014 · 1 comment
Open

Inject generic mock doesn't overrides Module #438

mazoni opened this issue Sep 13, 2014 · 1 comment

Comments

@mazoni
Copy link

mazoni commented Sep 13, 2014

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

@f2prateek
Copy link

Can you post the full stack trace?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants