To ensure all tests can run in parallel with completely isolated independent data it is important to include a value unique to each test for the request matcher.

If each test generates a different value (i.e. a UUID) for the sessionId cookie then each test can receive completely independent response. Instead of a cookie value a query parameter or header (such as the Referer header) can also be used to ensure mock responses are unique to each test.

Java

new MockServerClient("127.0.0.1", 1080)
        .when(
                request()
                        .withMethod("GET")
                        .withPath("/somePath")
                        .withCookies(
                                new Cookie("sessionId", "2By8LOhBmaW5nZXJwcmludCIlMDAzMW")
                        )
        )
        .respond(
                response()
                        .withStatusCode(200)
                        .withBody("{ name: 'value' }")
        );

JavaScript

mockServerClient("localhost", 1080).mockAnyResponse(
    {
        'httpRequest': {
            'method': 'GET',
            'path': '/somePath',
            "cookies": [
                {
                    "name": "sessionId",
                    "values": ["2By8LOhBmaW5nZXJwcmludCIlMDAzMW"]
                }
            ]
        },
        'httpResponse': {
            'statusCode': 200,
            'body': JSON.stringify({ name: 'value' })
        }
    }
);

Ruby

client = MockServerClient.new('localhost', 1080)
expectation = expectation do |expectation|
     expectation.request do |request|
        request.method = 'GET'
        request.path = '/somePath'
        request.cookies = [cookie('sessionId', '2By8LOhBmaW5nZXJwcmludCIlMDAzMW')]
     end

    expectation.response do |response|
        response.status_code = 200
        response.body = body("{ name: 'value' }")
    end
end
client.register(expectation)