javakotlinmockingokhttpmockwebserver

How to use dispatch of okhttp-MockWebServer? Cannot inherit from final 'okhttp3.Dispatcher'


I want to use the okhttp-MockWebServer not with the normal queue but with the Dispatcher as described in the Readme-section.

The example requires one to inherit from Dispatcher which is not possible because okhttp3.Dispatcher is a final class.

Is this a regression introduced by the Kotlin-rewrite of okhttp? (Kotlin makes classes final by default) Or is there a different and new intended way of setting up something similar to a Dispatcher?

(x-posted as a gh-issue: https://github.com/square/okhttp/issues/8130 )


Solution

  • Use okhttp3.mockwebserver.Dispatcher. okhttp3.Dispatcher is not for MockWebServer.