0

Currently, i'm trying to add ParentModule to SubModule but the problem is I got some unused @Provider methods even I use it.

Here's my code

public class DaggerTest extends TestCase {

    @Inject
    Random random;

    public void testInjectRandomNotNull() {
        ObjectGraph moduleGraph = ObjectGraph.create(new ParentModule());
        ObjectGraph subModuleGraph = moduleGraph.plus(new SubModule());
        subModuleGraph.inject(this);

        assertNotNull(random);
    }

    @Module()
    public class ParentModule {

        @Provides
        @Singleton
        public Random provideRandom() {
            return new Random();
        }
    }

    @Module(addsTo = ParentModule.class, injects = {DaggerTest.class})
    public class SubModule {

    }
}

1 Answers1

0

The @Module for ParentModule does not specify what it is injecting. It should be:

@Module(injects = DaggerTest.class)

Emmanuel
  • 13,083
  • 4
  • 39
  • 53