Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockWebServer Dispatcher bug #8308

Closed
mikey75 opened this issue Mar 28, 2024 · 1 comment
Closed

MockWebServer Dispatcher bug #8308

mikey75 opened this issue Mar 28, 2024 · 1 comment
Labels
bug Bug in existing code

Comments

@mikey75
Copy link

mikey75 commented Mar 28, 2024

Your documentation [https://github.com/square/okhttp/tree/master/mockwebserver] says that in 4.12.0 you can do:

final Dispatcher dispatcher = new Dispatcher() {

@Override
public MockResponse dispatch (RecordedRequest request) throws InterruptedException {

    switch (request.getPath()) {
        case "/v1/login/auth/":
            return new MockResponse().setResponseCode(200);
        case "/v1/check/version/":
            return new MockResponse().setResponseCode(200).setBody("version=9");
        case "/v1/profile/info":
            return new MockResponse().setResponseCode(200).setBody("{\\\"info\\\":{\\\"name\":\"Lucas Albuquerque\",\"age\":\"21\",\"gender\":\"male\"}}");
    }
    return new MockResponse().setResponseCode(404);
}

};
server.setDispatcher(dispatcher);

Yet it is impossible since Dispatcher class is final in OKHttp 4.12.0

@mikey75 mikey75 added the bug Bug in existing code label Mar 28, 2024
@mikey75
Copy link
Author

mikey75 commented Mar 29, 2024

OK, sorry, disregard, Dispatcher here was imported (autoimport in intelij) from okhttp3.Dispatcher, and should be from okhttp3.mockwebserver.Dispatcher - as the doc says. Sorry, closing.

@mikey75 mikey75 closed this as completed Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
Development

No branches or pull requests

1 participant