本文整理了Java中com.squareup.okhttp.mockwebserver.MockWebServer.enqueue()
方法的一些代码示例,展示了MockWebServer.enqueue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockWebServer.enqueue()
方法的具体详情如下:
包路径:com.squareup.okhttp.mockwebserver.MockWebServer
类名称:MockWebServer
方法名:enqueue
[英]Scripts response to be returned to a request made in sequence. The first request is served by the first enqueued response; the second request by the second enqueued response; and so on.
[中]脚本响应将返回到按顺序发出的请求。第一个请求由第一个排队响应服务;由第二排队响应发出的第二请求;等等
代码示例来源:origin: google/data-transfer-project
@Test
public void testExport() throws Exception {
server.enqueue(new MockResponse().setBody(CALENDARS_RESPONSE));
server.enqueue(new MockResponse().setBody(CALENDAR1_EVENTS_RESPONSE));
server.enqueue(new MockResponse().setBody(CALENDAR2_EVENTS_RESPONSE));
server.start();
HttpUrl baseUrl = server.url("");
MicrosoftCalendarExporter exporter =
new MicrosoftCalendarExporter(baseUrl.toString(), client, mapper, transformerService);
ExportResult<CalendarContainerResource> resource = exporter
.export(UUID.randomUUID(), token, Optional.empty());
CalendarContainerResource calendarResource = resource.getExportedData();
Assert.assertEquals(2, calendarResource.getCalendars().size());
Assert.assertFalse(
calendarResource
.getCalendars()
.stream()
.anyMatch(c -> "Calendar1".equals(c.getId()) && "Calendar2".equals(c.getId())));
Assert.assertEquals(2, calendarResource.getEvents().size());
Assert.assertFalse(
calendarResource
.getEvents()
.stream()
.anyMatch(
e ->
"Test Appointment 1".equals(e.getTitle())
&& "Test Appointment 2".equals(e.getTitle())));
}
代码示例来源:origin: google/data-transfer-project
@Test
public void testExport() throws Exception {
server.enqueue(new MockResponse().setBody(PHOTOS_RESPONSE));
server.enqueue(new MockResponse().setBody(FOLDER_RESPONSE));
server.enqueue(content1Response);
server.enqueue(content2Response);
代码示例来源:origin: facebook/stetho
@Test
public void testWithResponseCompression() throws IOException {
ByteArrayOutputStream capturedOutput = hookAlmostRealInterpretResponseStream(mMockEventReporter);
byte[] uncompressedData = repeat(".", 1024).getBytes();
byte[] compressedData = compress(uncompressedData);
MockWebServer server = new MockWebServer();
server.start();
server.enqueue(new MockResponse()
.setBody(new Buffer().write(compressedData))
.addHeader("Content-Encoding: gzip"));
Request request = new Request.Builder()
.url(server.url("/"))
.build();
Response response = mClientWithInterceptor.newCall(request).execute();
// Verify that the final output and the caller both saw the uncompressed stream.
assertArrayEquals(uncompressedData, response.body().bytes());
assertArrayEquals(uncompressedData, capturedOutput.toByteArray());
// And verify that the StethoInterceptor was able to see both.
Mockito.verify(mMockEventReporter)
.dataReceived(
anyString(),
eq(compressedData.length),
eq(uncompressedData.length));
server.shutdown();
}
代码示例来源:origin: google/data-transfer-project
@Test
@SuppressWarnings("unchecked")
public void testImport() throws Exception {
server.enqueue(new MockResponse().setBody(BATCH_CALENDAR_RESPONSE));
server.enqueue(new MockResponse().setResponseCode(201).setBody(BATCH_EVENT_RESPONSE));
server.start();
代码示例来源:origin: facebook/stetho
server.enqueue(new MockResponse()
.setBody("Success!"));
代码示例来源:origin: org.hobsoft.microbrowser/microbrowser-tck
@Test
public void getSetsCookie()
{
server().enqueue(new MockResponse().addHeader("Set-Cookie", "x=y"));
String actual = newBrowser().get(url(server()))
.getCookie("x");
assertThat("cookie", actual, is("y"));
}
代码示例来源:origin: org.hobsoft.microbrowser/microbrowser-tck
public void getNameReturnsName()
{
server().enqueue(new MockResponse().setBody("<html><body>"
+ "<form name='x'/>"
+ "</body></html>"));
String actual = newBrowser().get(url(server()))
.getForm("x")
.getName();
assertThat("form name", actual, is("x"));
}
代码示例来源:origin: org.hobsoft.microbrowser/microbrowser-tck
@Test
public void getRelWhenAnchorReturnsRelationship()
{
server().enqueue(new MockResponse().setBody("<html><body>"
+ "<a rel='x'/>"
+ "</body></html>"));
String actual = newBrowser().get(url(server()))
.getLink("x")
.getRel();
assertThat("link rel", actual, is("x"));
}
代码示例来源:origin: org.hobsoft.microbrowser/microbrowser-tck
@Test
public void getRelWhenLinkReturnsRelationship()
{
server().enqueue(new MockResponse().setBody("<html><body>"
+ "<link rel='x'/>"
+ "</body></html>"));
String actual = newBrowser().get(url(server()))
.getLink("x")
.getRel();
assertThat("link rel", actual, is("x"));
}
代码示例来源:origin: segmentio/analytics-android
@Test
public void fetchSettings() throws Exception {
server.enqueue(new MockResponse());
Client.Connection connection = client.fetchSettings();
assertThat(connection.os).isNull();
assertThat(connection.is).isNotNull();
assertThat(connection.connection.getResponseCode()).isEqualTo(200);
RecordedRequestAssert.assertThat(server.takeRequest())
.hasRequestLine("GET /v1/projects/foo/settings HTTP/1.1")
.containsHeader("User-Agent", ConnectionFactory.USER_AGENT)
.containsHeader("Content-Type", "application/json");
}
代码示例来源:origin: org.hobsoft.microbrowser/microbrowser-tck
@Test
public void getWhenInternalErrorReturnsResponse() throws MalformedURLException
{
server().enqueue(new MockResponse().setResponseCode(500).setBody("<html><body>"
+ "<div itemscope='itemscope' itemtype='http://i' itemid='http://x'/>"
+ "</body></html>"));
MicrodataDocument actual = newBrowser().get(url(server()));
assertThat("response", actual.getItem("http://i"), is(item("http://x")));
}
}
代码示例来源:origin: Coinomi/coinomi-android
@Test(expected = ShapeShiftException.class)
public void testGetMarketInfoFail() throws ShapeShiftException, IOException {
server.enqueue(new MockResponse().setBody(MARKET_INFO_BTC_NBT_JSON));
// Incorrect pair
shapeShift.getMarketInfo(BTC, LTC);
}
代码示例来源:origin: org.hobsoft.microbrowser/microbrowser-tck
@Test
public void getHrefWhenLinkAndRelativeHrefReturnsAbsoluteUrl()
{
server().enqueue(new MockResponse().setBody("<html><head>"
+ "<link rel='x' href='x'/>"
+ "</head></html>"));
URL actual = newBrowser().get(url(server()))
.getLink("x")
.getHref();
assertThat("link href", actual, is(server().url("/x").url()));
}
代码示例来源:origin: Coinomi/coinomi-android
@Test(expected = ShapeShiftException.class)
public void testGetTxStatusFail() throws ShapeShiftException, AddressMalformedException, IOException {
server.enqueue(new MockResponse().setBody(TX_STATUS_COMPLETE_JSON));
// Used an incorrect address, correct is 1NDQPAGamGePkSZXW2CYBzXJEefB7N4bTN
shapeShift.getTxStatus(BTC.newAddress("18ETaXCYhJ8sxurh41vpKC3E6Tu7oJ94q8"));
}
代码示例来源:origin: Coinomi/coinomi-android
@Test(expected = ShapeShiftException.class)
public void testNormalTransactionFail() throws ShapeShiftException, AddressMalformedException, IOException {
server.enqueue(new MockResponse().setBody(NORMAL_TRANSACTION_JSON));
// Incorrect Dogecoin address, correct is DMHLQYG4j96V8cZX9WSuXxLs5RnZn6ibrV
shapeShift.exchange(DOGE.newAddress("DSntbp199h851m3Y1g3ruYCQHzWYCZQmmA"),
BTC.newAddress("1Nz4xHJjNCnZFPjRUq8CN4BZEXTgLZfeUW"));
}
代码示例来源:origin: org.hobsoft.microbrowser/microbrowser-tck
@Test
public void followWhenInvalidUrlThrowsException()
{
server().enqueue(new MockResponse().setBody("<html><body>"
+ "<a rel='r' href='x:/a'>a</a>"
+ "</body></html>"));
Link link = newBrowser().get(url(server()))
.getLink("r");
thrown().expect(IllegalArgumentException.class);
thrown().expectMessage("Invalid URL: x:/a");
link.follow();
}
代码示例来源:origin: org.hobsoft.microbrowser/microbrowser-tck
@Test
public void setControlValueWithUnknownNameThrowsException()
{
server().enqueue(new MockResponse().setBody("<html><body>"
+ "<form name='f'/>"
+ "</body></html>"));
Form form = newBrowser().get(url(server()))
.getForm("f");
thrown().expect(ControlNotFoundException.class);
thrown().expectMessage("x");
form.setControlValue("x", "y");
}
代码示例来源:origin: org.hobsoft.microbrowser/microbrowser-tck
@Test
public void submitWhenNoSubmitButtonThrowsException()
{
server().enqueue(new MockResponse().setBody("<html><body>"
+ "<form name='f'/>"
+ "</body></html>"));
Form form = newBrowser().get(url(server()))
.getForm("f");
thrown().expect(IllegalStateException.class);
thrown().expectMessage("Missing form submit button");
form.submit();
}
代码示例来源:origin: Coinomi/coinomi-android
@Test(expected = ShapeShiftException.class)
public void testFixedAmountTransactionFail()
throws ShapeShiftException, AddressMalformedException, IOException {
server.enqueue(new MockResponse().setBody(FIXED_AMOUNT_TRANSACTION_JSON));
// We withdraw Dogecoins to a Bitcoin address
shapeShift.exchangeForAmount(DOGE.value("1000"),
BTC.newAddress("18ETaXCYhJ8sxurh41vpKC3E6Tu7oJ94q8"),
BTC.newAddress("1Nz4xHJjNCnZFPjRUq8CN4BZEXTgLZfeUW"));
}
代码示例来源:origin: Coinomi/coinomi-android
@Test(expected = ShapeShiftException.class)
public void testFixedAmountTransactionFail2()
throws ShapeShiftException, AddressMalformedException, IOException {
server.enqueue(new MockResponse().setBody(FIXED_AMOUNT_TRANSACTION_JSON));
// Incorrect Dogecoin address, correct is DMHLQYG4j96V8cZX9WSuXxLs5RnZn6ibrV
shapeShift.exchangeForAmount(DOGE.value("1000"),
DOGE.newAddress("DSntbp199h851m3Y1g3ruYCQHzWYCZQmmA"),
BTC.newAddress("1Nz4xHJjNCnZFPjRUq8CN4BZEXTgLZfeUW"));
}
内容来源于网络,如有侵权,请联系作者删除!