Source:
public void cookieRenewal() throws Exception { final String hello = "{\"hello\":\"world\"}\r\n"; final String authSession = "AuthSession="; final String renewalCookieToken = "RenewCookie_a2ltc3RlYmVsOjUxMzRBQTUzOtiY2_IDUIdsTJEVNEjObAbyhrgz"; final String renewalCookieValue = authSession + renewalCookieToken; mockWebServer.enqueue(MockWebServerResources.OK_COOKIE); mockWebServer.enqueue(new MockResponse().setResponseCode(200).addHeader("Set-Cookie", String.format(Locale.ENGLISH, "%s;", renewalCookieValue + MockWebServerResources.COOKIE_PROPS)) .setBody(hello)); mockWebServer.enqueue(new MockResponse()); CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer) .username("a") .password("b") .build(); String response = c.executeRequest(Http.GET(c.getBaseUri())).responseAsString(); assertEquals("The expected response should be received", hello, response); assertEquals("The server should have received 2 requests", 2, mockWebServer .getRequestCount()); assertEquals("The request should have been for /_session", "/_session", mockWebServer .takeRequest(10, TimeUnit.SECONDS).getPath()); assertEquals("The request should have been for /", "/", mockWebServer .takeRequest(10, TimeUnit.SECONDS).getPath()); String secondResponse = c.executeRequest(Http.GET(c.getBaseUri())).responseAsString(); assertTrue("There should be no response body on the mock response" + secondResponse, secondResponse.isEmpty()); assertEquals("The server should have received 3 requests", 3, mockWebServer .getRequestCount()); RecordedRequest request = mockWebServer.takeRequest(10, TimeUnit.SECONDS); assertEquals("The request should have been for path /", "/", request.getPath()); String headerValue = request.getHeader("Cookie"); assertThat("The Cookie header should contain the expected session value", headerValue, anyOf(containsString(renewalCookieValue), containsString(authSession + "\"" + renewalCookieToken + "\""))); }

Target:
public void cookieRenewal() throws Exception { final String hello = "{\"hello\":\"world\"}\r\n"; final String authSession = "AuthSession="; final String renewalCookieToken = "RenewCookie_a2ltc3RlYmVsOjUxMzRBQTUzOtiY2_IDUIdsTJEVNEjObAbyhrgz"; final String renewalCookieValue = authSession + renewalCookieToken; mockWebServer.enqueue(MockWebServerResources.OK_COOKIE); mockWebServer.enqueue(new MockResponse().setResponseCode(200).addHeader("Set-Cookie", String.format(Locale.ENGLISH, "%s;", renewalCookieValue + MockWebServerResources.COOKIE_PROPS)) .setBody(hello)); mockWebServer.enqueue(new MockResponse()); CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer) .username("a") .password("b") .build(); String response = c.executeRequest(Http.GET(c.getBaseUri())).responseAsString(); assertEquals("The expected response should be received", hello, response); assertEquals("The server should have received 2 requests", 2, mockWebServer .getRequestCount()); assertEquals("The request should have been for /_session", "/_session", MockWebServerResources.takeRequestWithTimeout(mockWebServer).getPath()); assertEquals("The request should have been for /", "/", MockWebServerResources.takeRequestWithTimeout(mockWebServer).getPath()); String secondResponse = c.executeRequest(Http.GET(c.getBaseUri())).responseAsString(); assertTrue("There should be no response body on the mock response" + secondResponse, secondResponse.isEmpty()); assertEquals("The server should have received 3 requests", 3, mockWebServer .getRequestCount()); RecordedRequest request = MockWebServerResources.takeRequestWithTimeout(mockWebServer); assertEquals("The request should have been for path /", "/", request.getPath()); String headerValue = request.getHeader("Cookie"); assertThat("The Cookie header should contain the expected session value", headerValue, anyOf(containsString(renewalCookieValue), containsString(authSession + "\"" + renewalCookieToken + "\""))); }