1

Can anyone help me unit testing api calls using retrofit 2.0 and eventBus for managing the response from the api, Specifically using 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 Answers0