本文整理了Java中com.squareup.okhttp.mockwebserver.MockResponse.<init>()
方法的一些代码示例,展示了MockResponse.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MockResponse.<init>()
方法的具体详情如下:
包路径:com.squareup.okhttp.mockwebserver.MockResponse
类名称:MockResponse
方法名:<init>
[英]Creates a new mock response with an empty body.
[中]使用空主体创建新的模拟响应。
代码示例来源:origin: google/data-transfer-project
private MockResponse createContentResponse(String contentType, byte[] content) {
MockResponse response = new MockResponse();
response.setHeader("content-type", contentType);
Buffer body = new Buffer();
body.write(content);
response.setBody(body);
return response;
}
代码示例来源: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: 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: google/data-transfer-project
@Test
public void testExport() throws Exception {
server.enqueue(new MockResponse().setBody(PHOTOS_RESPONSE));
server.enqueue(new MockResponse().setBody(FOLDER_RESPONSE));
代码示例来源:origin: facebook/stetho
server.enqueue(new MockResponse()
.setBody("Success!"));
代码示例来源:origin: com.squareup.okhttp/mockwebserver
/**
* Returns an early guess of the next response, used for policy on how an
* incoming request should be received. The default implementation returns an
* empty response. Mischievous implementations can return other values to test
* HTTP edge cases, such as unhappy socket policies or throttled request
* bodies.
*/
public MockResponse peek() {
return new MockResponse().setSocketPolicy(SocketPolicy.KEEP_OPEN);
}
}
代码示例来源:origin: com.squareup.okhttp/mockwebserver
public void setFailFast(boolean failFast) {
MockResponse failFastResponse = failFast
? new MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
: null;
setFailFast(failFastResponse);
}
代码示例来源: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: 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: 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"));
}
内容来源于网络,如有侵权,请联系作者删除!