Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The class has a static method setup() which sets up the mock server by creating a MockWebServer instance and setting up a Dispatcher to handle incoming requests. The Dispatcher maps the request paths to the corresponding MockResponse instances, which are stored in a HashMap.

The setup() method also sets up a proxy for Unirest by calling Unirest.setProxy() with the hostname and port of the mock server.

The ContentSearchMock class has a static method teardown() which shuts down the mock server.

The Dispatcher instance is created using a lambda expression that implements the dispatch() method, which receives the incoming request and returns the corresponding MockResponse.

The lambda expression extracts the request path is extracted from the RecordedRequest object using a regular expression pattern. The path is used to look up the corresponding MockResponse in the HashMap. If no MockResponse is found for the path, a default MockResponse with a 404 status code is returned.

...