Sergei Buvaka
Sergei Buvaka

Reputation: 621

How I can test arguments in Observable RxJava

I have some method:

repository.get(arg1, arg2, arg3)

Method return Single<List<SomeObject>>

I need testing that Single was called onSubscribe() with specific arguments.

repository.get(arg1, arg2, arg3)
            .test()
            .assertSubscribed()

This method ignores arguments which I put in method repository.get().

How I can test that subscribe called with certain arguments?

Upvotes: 0

Views: 53

Answers (1)

Mohsen
Mohsen

Reputation: 1389

use Schedulers.trampoline() to make the subscription occur on the current thread. then you can assert the required args

@Before
    fun setup() {
        RxJavaPlugins.setIoSchedulerHandler { Schedulers.trampoline() }
        RxJavaPlugins.setComputationSchedulerHandler { Schedulers.trampoline() }
    }

this makes the code run on the current thread. then you can assert the args

repository.get(arg1, arg2, arg3)
            .test()
            .subscribe {
                 // do the assertions here
             }

Upvotes: 1

Related Questions