任何人都可以帮助我使用retrofit 2.0和eventBus来测试api调用来管理来自api的响应,特别是使用Robospock
public boolean login(String username,String password){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(EndpointInterface.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
EndpointInterface EndpointInterface = retrofit.create(EndpointInterface.class)
LoginData loginData = new LoginData(username, password)
Call<AunthenticatedUser> call = EndpointInterface.doLogin(loginData)
call.enqueue(new Callback<AunthenticatedUser>() {
@Override
void onResponse(Call<AunthenticatedUser> callAsync, Response<AunthenticatedUser> response) {
SuccessfulLoginEvent event = null
AunthenticatedUser user = response.body()
if (response.isSuccess()) {
Log.d("Body", "" + user)
if (user != null) {
}
}
event = new SuccessfulLoginEvent(user)
bus.postSticky(event)
}
@Override
void onFailure(Call<AunthenticatedUser> callAsync, Throwable t) {
Log.d("Error :", t.getMessage())
UnsuccessfulLoginEvent event = new UnsuccessfulLoginEvent(t.getMessage())
bus.post(event)
}
})