Skip to content

Commit

Permalink
[Cronet] Partial migrate to Truth assertTrue
Browse files Browse the repository at this point in the history
Migrates all javatests except urlconnection tests

Bug: b/280423217
Change-Id: Ic1c96f36dd0bb93596b68076b32ed779533b22c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4579809
Reviewed-by: Stefano Duo <stefanoduo@google.com>
Commit-Queue: Chidera Olibie <colibie@google.com>
Cr-Commit-Position: refs/heads/main@{#1153810}
  • Loading branch information
colibie authored and Chromium LUCI CQ committed Jun 6, 2023
1 parent 2030337 commit 9c288f4
Show file tree
Hide file tree
Showing 25 changed files with 260 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertTrue;

import static org.chromium.net.CronetTestRule.getContext;

import androidx.test.ext.junit.runners.AndroidJUnit4;
Expand Down Expand Up @@ -76,7 +74,7 @@ public void testSimpleGet() throws Exception {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString)
.isEqualTo("This is a simple text file served by QUIC.\n");
Expand Down Expand Up @@ -109,7 +107,7 @@ public void testSimplePost() throws Exception {
Date startTime = new Date();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
requestFinishedListener.blockUntilDone();
Date endTime = new Date();
RequestFinishedInfo finishedInfo = requestFinishedListener.getRequestInfo();
Expand Down Expand Up @@ -147,7 +145,7 @@ public void testSimplePostWithFlush() throws Exception {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString)
.isEqualTo("This is a simple text file served by QUIC.\n");
Expand Down Expand Up @@ -182,7 +180,7 @@ public void testSimplePostWithFlushTwice() throws Exception {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString)
.isEqualTo("This is a simple text file served by QUIC.\n");
Expand Down Expand Up @@ -220,7 +218,7 @@ public void onStreamReady(BidirectionalStream stream) {

stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();

// Flush after stream is completed is no-op. It shouldn't call into the destroyed
// adapter.
Expand Down Expand Up @@ -254,7 +252,7 @@ public void testSimplePostWithFlushAfterOneWrite() throws Exception {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();

assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString)
Expand Down Expand Up @@ -299,7 +297,7 @@ public void onWriteCompleted(BidirectionalStream stream, UrlResponseInfo info,
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
// Server terminated on us, so the stream must fail.
// QUIC reports this as ERR_QUIC_PROTOCOL_ERROR. Sometimes we get ERR_CONNECTION_REFUSED.
assertThat(callback.mError).isInstanceOf(NetworkException.class);
Expand Down Expand Up @@ -333,7 +331,7 @@ public void onStreamReady(BidirectionalStream stream) {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mError).isNotNull();
if (callback.mError instanceof QuicException) {
QuicException quicException = (QuicException) callback.mError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import static org.chromium.net.CronetTestRule.getContext;
Expand Down Expand Up @@ -65,12 +64,12 @@ public void setUp() throws Exception {
builder, QuicTestServer.createMockCertVerifier()));

mCronetEngine = mTestRule.getTestFramework().startEngine();
assertTrue(Http2TestServer.startHttp2TestServer(getContext()));
assertThat(Http2TestServer.startHttp2TestServer(getContext())).isTrue();
}

@After
public void tearDown() throws Exception {
assertTrue(Http2TestServer.shutdownHttp2TestServer());
assertThat(Http2TestServer.shutdownHttp2TestServer()).isTrue();
}

private static void checkResponseInfo(UrlResponseInfo responseInfo, String expectedUrl,
Expand Down Expand Up @@ -117,7 +116,7 @@ private void runSimpleGetWithExpectedReceivedByteCount(int expectedReceivedBytes
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
requestFinishedListener.blockUntilDone();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
// Default method is 'GET'.
Expand Down Expand Up @@ -210,7 +209,7 @@ public void testFailPlainHttp() throws Exception {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mError)
.hasMessageThat()
.contains("Exception in BidirectionalStream: net::ERR_DISALLOWED_URL_SCHEME");
Expand Down Expand Up @@ -240,7 +239,7 @@ public void testSimpleHead() throws Exception {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString).isEqualTo("HEAD");
UrlResponseInfo urlResponseInfo =
Expand Down Expand Up @@ -272,7 +271,7 @@ public void testSimplePost() throws Exception {
Date startTime = new Date();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
requestFinishedListener.blockUntilDone();
Date endTime = new Date();
RequestFinishedInfo finishedInfo = requestFinishedListener.getRequestInfo();
Expand Down Expand Up @@ -341,7 +340,7 @@ public void testSimpleGetWithCombinedHeader() throws Exception {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
requestFinishedListener.blockUntilDone();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
// Default method is 'GET'.
Expand Down Expand Up @@ -372,7 +371,7 @@ public void testSimplePostWithFlush() throws Exception {

stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();

// Flush after stream is completed is no-op. It shouldn't call into the destroyed adapter.
stream.flush();
Expand Down Expand Up @@ -418,7 +417,7 @@ public void onWriteCompleted(BidirectionalStream stream, UrlResponseInfo info,
ByteBuffer pendingBuffer = pendingData.get(0);
byte[] content = new byte[pendingBuffer.remaining()];
pendingBuffer.get(content);
assertTrue(Arrays.equals("6".getBytes(), content));
assertThat(content).isEqualTo("6".getBytes());

// "4" and "5" have been flushed.
assertThat(((CronetBidirectionalStream) stream).getFlushDataForTesting())
Expand All @@ -431,7 +430,7 @@ public void onWriteCompleted(BidirectionalStream stream, UrlResponseInfo info,
ByteBuffer pendingBuffer = pendingData.get(0);
byte[] content = new byte[pendingBuffer.remaining()];
pendingBuffer.get(content);
assertTrue(Arrays.equals("6".getBytes(), content));
assertThat(content).isEqualTo("6".getBytes());

stream.flush();

Expand Down Expand Up @@ -494,13 +493,15 @@ public void onStreamReady(BidirectionalStream stream) {
stream.write(getDummyData(), false);
stream.flush();
}

@Override
public void onReadCompleted(BidirectionalStream stream, UrlResponseInfo info,
ByteBuffer byteBuffer, boolean endOfStream) {
super.onReadCompleted(stream, info, byteBuffer, endOfStream);
// Cancel now when the write side is busy.
stream.cancel();
}

@Override
public void onWriteCompleted(BidirectionalStream stream, UrlResponseInfo info,
ByteBuffer buffer, boolean endOfStream) {
Expand All @@ -510,6 +511,7 @@ public void onWriteCompleted(BidirectionalStream stream, UrlResponseInfo info,
stream.write(getDummyData(), false);
stream.flush();
}

// Returns a piece of dummy data to send to the server.
private ByteBuffer getDummyData() {
byte[] data = new byte[100];
Expand All @@ -528,7 +530,7 @@ private ByteBuffer getDummyData() {
.build();
stream.start();
callback.blockForDone();
assertTrue(callback.mOnCanceledCalled);
assertThat(callback.mOnCanceledCalled).isTrue();
}

@Test
Expand Down Expand Up @@ -572,7 +574,7 @@ public void onStreamReady(BidirectionalStream stream) {

stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();

// Flush after stream is completed is no-op. It shouldn't call into the destroyed
// adapter.
Expand Down Expand Up @@ -606,7 +608,7 @@ public void testSimplePostWithFlushAfterOneWrite() throws Exception {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();

assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString).isEqualTo("Test String");
Expand Down Expand Up @@ -643,7 +645,7 @@ public void testSimplePostWithFlushTwice() throws Exception {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString)
.isEqualTo("Test String1234567890woot!Test String1234567890woot!");
Expand All @@ -668,6 +670,7 @@ public void onStreamReady(BidirectionalStream stream) {
super.onStreamReady(stream);
startNextRead(stream);
}

@Override
public void onResponseHeadersReceived(
BidirectionalStream stream, UrlResponseInfo info) {
Expand All @@ -685,7 +688,7 @@ public void onResponseHeadersReceived(
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString).isEqualTo("Test String1234567890woot!");
assertThat(callback.mResponseInfo.getAllHeaders())
Expand Down Expand Up @@ -726,7 +729,7 @@ public void onStreamReady(BidirectionalStream stream) {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString)
.isEqualTo("Test String1234567890woot!Test String1234567890woot!");
Expand Down Expand Up @@ -946,7 +949,7 @@ public void testEchoStream() throws Exception {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString).isEqualTo(stringData.toString());
assertThat(callback.mResponseInfo.getAllHeaders())
Expand All @@ -968,7 +971,7 @@ public void testEchoStreamEmptyWrite() throws Exception {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString).isEmpty();
}
Expand Down Expand Up @@ -997,7 +1000,7 @@ public void onStreamReady(BidirectionalStream stream) {
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString).isEqualTo("12");
}
Expand Down Expand Up @@ -1031,7 +1034,7 @@ public void onResponseHeadersReceived(
.build();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString).isEqualTo("12");
}
Expand Down Expand Up @@ -1064,7 +1067,7 @@ public void onResponseHeadersReceived(
callback.setAutoAdvance(true);
callback.startNextRead(stream);
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString).isEqualTo("12");
}
Expand Down Expand Up @@ -1102,13 +1105,13 @@ public void testEchoStreamWriteFirst() throws Exception {
callback.startNextRead(stream);
callback.waitForNextReadStep(); // onReadCompleted
// Verify that some part of proper response is read.
assertTrue(callback.mResponseAsString.startsWith(testData[0]));
assertTrue(stringData.toString().startsWith(callback.mResponseAsString));
assertThat(callback.mResponseAsString).startsWith(testData[0]);
assertThat(callback.mResponseAsString).startsWith(stringData.toString());
// Read the rest of the response.
callback.setAutoAdvance(true);
callback.startNextRead(stream);
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString).isEqualTo(stringData.toString());
}
Expand Down Expand Up @@ -1150,7 +1153,7 @@ public void testEchoStreamStepByStep() throws Exception {
callback.setAutoAdvance(true);
callback.startNextRead(stream);
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo.getHttpStatusCode()).isEqualTo(200);
assertThat(callback.mResponseAsString).isEqualTo(stringData.toString());
}
Expand Down Expand Up @@ -1322,7 +1325,7 @@ private void throwOrCancel(
Date startTime = new Date();
stream.start();
callback.blockForDone();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
requestFinishedListener.blockUntilDone();
Date endTime = new Date();
RequestFinishedInfo finishedInfo = requestFinishedListener.getRequestInfo();
Expand Down Expand Up @@ -1402,7 +1405,7 @@ public void testThrowOnSucceeded() {
stream.start();
callback.blockForDone();
assertThat(ResponseStep.ON_SUCCEEDED).isEqualTo(callback.mResponseStep);
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
assertThat(callback.mResponseInfo).isNotNull();
// Check that error thrown from 'onSucceeded' callback is not reported.
assertThat(callback.mError).isNull();
Expand Down Expand Up @@ -1442,7 +1445,7 @@ public void run() {
streamDestroyed.block();

assertThat(callback.isDone()).isFalse();
assertTrue(stream.isDone());
assertThat(stream.isDone()).isTrue();
}

/**
Expand Down Expand Up @@ -1536,7 +1539,7 @@ public void testCronetEngineShutdownAfterStreamFailure() throws Exception {
stream.start();
callback.setFailure(FailureType.THROW_SYNC, ResponseStep.ON_READ_COMPLETED);
callback.blockForDone();
assertTrue(callback.mOnErrorCalled);
assertThat(callback.mOnErrorCalled).isTrue();
assertThat(mCronetEngine).isNull();
}

Expand Down Expand Up @@ -1565,7 +1568,7 @@ public void testCronetEngineShutdownAfterStreamCancel() throws Exception {
assertThat(callback.mResponseStep).isEqualTo(ResponseStep.ON_RESPONSE_STARTED);
stream.cancel();
callback.blockForDone();
assertTrue(callback.mOnCanceledCalled);
assertThat(callback.mOnCanceledCalled).isTrue();
assertThat(mCronetEngine).isNull();
}

Expand Down

0 comments on commit 9c288f4

Please sign in to comment.