-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error invoking setter with parameter class on ObjectWrapper getSetterMethod #77
Comments
Hi, can you try to add a method to component builder with the |
Hi I was able to get around the problem by using the customizeBuilder example... However I am finding that the mocks are not being used and the actual repository object is being called.. Below is my code let me know what I am doing wrong Custom Dagger Mock Rule
} My APP Module
..........
} ActivityBuilderModule @module
} and my APPComponent @singleton
} |
Now it should work, ho do you define the repository in your test? Do you use it in your activity or in a Presenter/ViewModel? |
Thanks for your help... I am using Dagger 2 and MVVM. The below is code for one of my tests.
} |
Where do you define the |
No I have defined travelrepository in the App Module class.. which is then defined in the dagger test rule private static CardControlApp getApp() { |
Can you try to add some breakpoints to try the error? Are you sure to use the DaggerMock component in your application? Can you check stacktrace of the repository constructor invocation to check if it contains some DaggerMock methods? |
Hi
I followed the example on to create a custom DaggerMock Rule and I am getting error
I/TestRunner: java.lang.RuntimeException: Error invoking setter with parameter class com.visa.cardcontrols.di.AppModule on object com.visa.cardcontrols.di.DaggerAppComponent$Builder@ba12a92
at it.cosenonjaviste.daggermock.ObjectWrapper.invokeBuilderSetter(ObjectWrapper.java:134)
at it.cosenonjaviste.daggermock.DaggerMockRule.initComponent(DaggerMockRule.java:206)
at it.cosenonjaviste.daggermock.DaggerMockRule.access$300(DaggerMockRule.java:35)
at it.cosenonjaviste.daggermock.DaggerMockRule$1.evaluate(DaggerMockRule.java:105)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)
Caused by: java.lang.NoSuchMethodException: AppModule [class com.visa.cardcontrols.di.AppModule]
at java.lang.Class.getMethod(Class.java:1981)
at java.lang.Class.getMethod(Class.java:1637)
at it.cosenonjaviste.daggermock.ObjectWrapper.getSetterMethod(ObjectWrapper.java:144)
at it.cosenonjaviste.daggermock.ObjectWrapper.invokeBuilderSetter(ObjectWrapper.java:131)
at it.cosenonjaviste.daggermock.DaggerMockRule.initComponent(DaggerMockRule.java:206)
at it.cosenonjaviste.daggermock.DaggerMockRule.access$300(DaggerMockRule.java:35)
at it.cosenonjaviste.daggermock.DaggerMockRule$1.evaluate(DaggerMockRule.java:105)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1932)
----- end exception -----
I debugged it and seems the error occurs on objectwrapper.java class get SetterMethod
String moduleName = moduleClass.getSimpleName();
String setterName = ReflectUtils.toCamelCase(moduleName);
return builder.getClass().getMethod(setterName, moduleClass);
The code for the custom rule is below
public class CardControlAndroidTestDaggerRule extends DaggerMockRule {
public CardControlAndroidTestDaggerRule() {
super(AppComponent.class, new AppModule());
providesMock(TravelRepository.class);
set(component -> getApp().setComponent(component));
}
and my appcomponent class is
package com.visa.cardcontrols.di;
import android.app.Application;
import android.content.Context;
import com.visa.cardcontrols.CardControlApp;
import javax.inject.Singleton;
import dagger.BindsInstance;
import dagger.Component;
import dagger.android.AndroidInjectionModule;
import dagger.android.support.AndroidSupportInjectionModule;
@singleton
@component(modules = {
AndroidInjectionModule.class,
AppModule.class,
ActivityBuilderModule.class})
public interface AppComponent {
}
The text was updated successfully, but these errors were encountered: