I am using Retrofit and injecting RestAdapter
and WebService
class/interface through Dagger2
In the tests, I am mocking my WebService
class with MockWebService implements WebService
and I am getting this exception from Retrofit
java.lang.IllegalArgumentException: Only interface endpoint definitions are supported.
at retrofit.Utils.validateServiceClass(Utils.java:102)
at retrofit.RestAdapter.create(RestAdapter.java:193)
Here is the interface class for WebService
public interface WebService {
@FormUrlEncoded
@POST("/loginByEmail")
void loginByEmail (@Field("emailaddress") String email,
@Field("password") String password,
@Field("checksum") String checksum,
Callback<ServiceModel<User>> callback);
}
And, here is my MockWebService
class
public class MockWebService200 implements WebService {
@Override
public void loginByEmail (@Field("emailaddress") String email,
@Field("password") String password,
@Field("checksum") String checksum,
Callback<ServiceModel<User>> callback) {
ServiceModel<User> userModel = getServiceModel( getUser() );
callback.success( userModel, null );
}
@Override public <T> ServiceModel<T> getServiceModel (T model) {
// Skipped
}
@Override public User getUser () {
// Skipped
}
}
getUser()
and getServiceModel()
are skipped here.
Questions:
1- How to fix this?
2- Is my approach correct to mock web services through polymorphism and what alternatives I can use here?
Aucun commentaire:
Enregistrer un commentaire