0

Is possible to test "() -> Unit?" with junit test?

I have the following NetworkUtils class

    class NetworkUtils : NetworkContract{

        /**
         *Return success if the Internet connection is enought to make an request
         */
        override fun isConnectedFast(onSuccess: () -> Unit?, onError: () -> Unit?) {
        }
    }

That is the interface

interface NetworkContract {

    fun isConnectedFast(onSuccess: (() -> Unit?), onError: (() -> Unit?))

}

Here is my presenter where I wanna to check internet connection and do some requests

class Presenter(){

//some declarations

override fun onContinue(){
  super.updateUserProfile({
        super.updateImage({
                //request success
        },{
                 //request failed
        })
  },{
  //some error received
  })
}
}

And here is my Handler which is an interface

interface Hndler{

fun updateUserProfile(){
         service.getProfile(id,token!!)
                .subscribe({ response ->
                    onSuccess?.invoke()
                }, { error ->
                    onError?.invoke()
                })
         }
}

I wanna to mock that somehow. Is that possible or not? If yes, please can you give me an example?

azsoftco
  • 812
  • 1
  • 8
  • 20
  • i am not allowed to open that link – azsoftco Jun 04 '18 at 13:21
  • *EDIT* Sorry, I copy the wrong link. You may want to check the answer given to this other [question](https://stackoverflow.com/questions/41462913/mockito-verify-that-a-specific-lambda-has-been-passed-as-an-argument-in-mocks-m). The basic is that you want to use an `ArgumentCaptor` from Mockito to get an instance of your lambda and then call the methods on it – Nicolás Carrasco-Stevenson Jun 05 '18 at 05:25
  • Can you take a look to the update? – azsoftco Jun 05 '18 at 11:12

0 Answers0