如何使用robospock对带有EventBus的Retrofit 2.0 api调用进行单元测试?

时间:2016-03-24 10:15:10

标签: android unit-testing retrofit greenrobot-eventbus robospock

任何人都可以帮助我使用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)

        }
    })

0 个答案:

没有答案