Skip to content

Commit

Permalink
Automatic code cleanup.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 250489470
  • Loading branch information
Googler authored and irengrig committed Jul 15, 2019
1 parent 7470686 commit 9b319f4
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import static com.google.devtools.build.lib.bazel.repository.downloader.HttpParser.readHttpRequest;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.util.Arrays.asList;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.doAnswer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static java.nio.charset.StandardCharsets.US_ASCII;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static com.google.devtools.build.lib.bazel.repository.downloader.DownloaderTestUtils.makeUrl;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.bazel.repository.downloader.DownloaderTestUtils.makeUrl;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static com.google.devtools.build.lib.remote.util.DigestUtil.toBinaryDigest;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Matchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.fail;
import static org.mockito.AdditionalAnswers.answerVoid;
import static org.mockito.Mockito.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -102,6 +102,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
Expand Down Expand Up @@ -590,12 +591,12 @@ public void findMissingBlobs(
for (int chunkSize = 1; chunkSize <= 6; ++chunkSize) {
GrpcRemoteCache client = newClient();
Chunker.setDefaultChunkSizeForTesting(chunkSize);
when(mockByteStreamImpl.write(Mockito.<StreamObserver<WriteResponse>>anyObject()))
when(mockByteStreamImpl.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any()))
.thenAnswer(blobChunkedWriteAnswer("abcdef", chunkSize));
assertThat(client.uploadBlob("abcdef".getBytes(UTF_8))).isEqualTo(digest);
}
Mockito.verify(mockByteStreamImpl, Mockito.times(6))
.write(Mockito.<StreamObserver<WriteResponse>>anyObject());
.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any());
}

@Test
Expand Down Expand Up @@ -893,7 +894,7 @@ public void updateActionResult(
});
ByteStreamImplBase mockByteStreamImpl = Mockito.mock(ByteStreamImplBase.class);
serviceRegistry.addService(mockByteStreamImpl);
when(mockByteStreamImpl.write(Mockito.<StreamObserver<WriteResponse>>anyObject()))
when(mockByteStreamImpl.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any()))
.thenAnswer(
new Answer<StreamObserver<WriteRequest>>() {
private int numErrors = 4;
Expand Down Expand Up @@ -965,7 +966,7 @@ public void onError(Throwable t) {
outErr);
// 4 times for the errors, 3 times for the successful uploads.
Mockito.verify(mockByteStreamImpl, Mockito.times(7))
.write(Mockito.<StreamObserver<WriteResponse>>anyObject());
.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.fail;
import static org.mockito.AdditionalAnswers.answerVoid;
import static org.mockito.Mockito.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -116,6 +116,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
Expand Down Expand Up @@ -616,7 +617,7 @@ public void findMissingBlobs(
serviceRegistry.addService(ServerInterceptors.intercept(cas, new RequestHeadersValidator()));

ByteStreamImplBase mockByteStreamImpl = Mockito.mock(ByteStreamImplBase.class);
when(mockByteStreamImpl.write(Mockito.<StreamObserver<WriteResponse>>anyObject()))
when(mockByteStreamImpl.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any()))
.thenAnswer(blobWriteAnswer("xyz".getBytes(UTF_8)));
serviceRegistry.addService(
ServerInterceptors.intercept(mockByteStreamImpl, new RequestHeadersValidator()));
Expand All @@ -627,7 +628,7 @@ public void findMissingBlobs(
assertThat(result.isCacheHit()).isFalse();
assertThat(outErr.outAsLatin1()).isEqualTo("stdout");
assertThat(outErr.errAsLatin1()).isEqualTo("stderr");
Mockito.verify(mockByteStreamImpl).write(Mockito.<StreamObserver<WriteResponse>>anyObject());
Mockito.verify(mockByteStreamImpl).write(ArgumentMatchers.<StreamObserver<WriteResponse>>any());
}

private Answer<Void> answerWith(@Nullable Operation op, Status status) {
Expand Down Expand Up @@ -702,13 +703,14 @@ public void getActionResult(
.doAnswer(answerWith(opSuccess, Status.UNAVAILABLE)) // last status should be ignored.
.when(mockExecutionImpl)
.execute(
Mockito.<ExecuteRequest>anyObject(), Mockito.<StreamObserver<Operation>>anyObject());
ArgumentMatchers.<ExecuteRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
Mockito.doAnswer(answerWith(null, Status.UNAVAILABLE))
.doAnswer(answerWith(operationWithExecuteError, Status.OK))
.when(mockExecutionImpl)
.waitExecution(
Mockito.<WaitExecutionRequest>anyObject(),
Mockito.<StreamObserver<Operation>>anyObject());
ArgumentMatchers.<WaitExecutionRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
serviceRegistry.addService(mockExecutionImpl);

serviceRegistry.addService(
Expand All @@ -734,7 +736,7 @@ public void findMissingBlobs(
});

ByteStreamImplBase mockByteStreamImpl = Mockito.mock(ByteStreamImplBase.class);
when(mockByteStreamImpl.write(Mockito.<StreamObserver<WriteResponse>>anyObject()))
when(mockByteStreamImpl.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any()))
.thenAnswer(blobWriteAnswerError()) // Error on the input file.
.thenAnswer(blobWriteAnswerError()) // Error on the input file again.
.thenAnswer(blobWriteAnswer("xyz".getBytes(UTF_8))); // Upload input file successfully.
Expand Down Expand Up @@ -770,7 +772,9 @@ public void findMissingBlobs(
return null;
})
.when(mockByteStreamImpl)
.read(Mockito.<ReadRequest>anyObject(), Mockito.<StreamObserver<ReadResponse>>anyObject());
.read(
ArgumentMatchers.<ReadRequest>any(),
ArgumentMatchers.<StreamObserver<ReadResponse>>any());
serviceRegistry.addService(mockByteStreamImpl);

SpawnResult result = client.exec(simpleSpawn, simplePolicy);
Expand All @@ -781,15 +785,18 @@ public void findMissingBlobs(
assertThat(outErr.errAsLatin1()).isEqualTo("stderr");
Mockito.verify(mockExecutionImpl, Mockito.times(4))
.execute(
Mockito.<ExecuteRequest>anyObject(), Mockito.<StreamObserver<Operation>>anyObject());
ArgumentMatchers.<ExecuteRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
Mockito.verify(mockExecutionImpl, Mockito.times(2))
.waitExecution(
Mockito.<WaitExecutionRequest>anyObject(),
Mockito.<StreamObserver<Operation>>anyObject());
ArgumentMatchers.<WaitExecutionRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
Mockito.verify(mockByteStreamImpl, Mockito.times(2))
.read(Mockito.<ReadRequest>anyObject(), Mockito.<StreamObserver<ReadResponse>>anyObject());
.read(
ArgumentMatchers.<ReadRequest>any(),
ArgumentMatchers.<StreamObserver<ReadResponse>>any());
Mockito.verify(mockByteStreamImpl, Mockito.times(3))
.write(Mockito.<StreamObserver<WriteResponse>>anyObject());
.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any());
}

@Test
Expand Down Expand Up @@ -833,13 +840,14 @@ public void getActionResult(
.doAnswer(answerWith(unfinishedOperation, Status.UNAVAILABLE))
.when(mockExecutionImpl)
.execute(
Mockito.<ExecuteRequest>anyObject(), Mockito.<StreamObserver<Operation>>anyObject());
ArgumentMatchers.<ExecuteRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
Mockito.doAnswer(answerWith(unfinishedOperation, Status.NOT_FOUND))
.doAnswer(answerWith(opSuccess, Status.UNAVAILABLE)) // This error is ignored.
.when(mockExecutionImpl)
.waitExecution(
Mockito.<WaitExecutionRequest>anyObject(),
Mockito.<StreamObserver<Operation>>anyObject());
ArgumentMatchers.<WaitExecutionRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
serviceRegistry.addService(mockExecutionImpl);

serviceRegistry.addService(
Expand All @@ -859,7 +867,7 @@ public void findMissingBlobs(
});

ByteStreamImplBase mockByteStreamImpl = Mockito.mock(ByteStreamImplBase.class);
when(mockByteStreamImpl.write(Mockito.<StreamObserver<WriteResponse>>anyObject()))
when(mockByteStreamImpl.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any()))
.thenAnswer(blobWriteAnswer("xyz".getBytes(UTF_8))); // Upload input file successfully.
Mockito.doAnswer(
invocationOnMock -> {
Expand All @@ -872,7 +880,9 @@ public void findMissingBlobs(
return null;
})
.when(mockByteStreamImpl)
.read(Mockito.<ReadRequest>anyObject(), Mockito.<StreamObserver<ReadResponse>>anyObject());
.read(
ArgumentMatchers.<ReadRequest>any(),
ArgumentMatchers.<StreamObserver<ReadResponse>>any());
serviceRegistry.addService(mockByteStreamImpl);

SpawnResult result = client.exec(simpleSpawn, simplePolicy);
Expand All @@ -883,15 +893,18 @@ public void findMissingBlobs(
assertThat(outErr.errAsLatin1()).isEqualTo("stderr");
Mockito.verify(mockExecutionImpl, Mockito.times(3))
.execute(
Mockito.<ExecuteRequest>anyObject(), Mockito.<StreamObserver<Operation>>anyObject());
ArgumentMatchers.<ExecuteRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
Mockito.verify(mockExecutionImpl, Mockito.times(2))
.waitExecution(
Mockito.<WaitExecutionRequest>anyObject(),
Mockito.<StreamObserver<Operation>>anyObject());
ArgumentMatchers.<WaitExecutionRequest>any(),
ArgumentMatchers.<StreamObserver<Operation>>any());
Mockito.verify(mockByteStreamImpl)
.read(Mockito.<ReadRequest>anyObject(), Mockito.<StreamObserver<ReadResponse>>anyObject());
.read(
ArgumentMatchers.<ReadRequest>any(),
ArgumentMatchers.<StreamObserver<ReadResponse>>any());
Mockito.verify(mockByteStreamImpl, Mockito.times(1))
.write(Mockito.<StreamObserver<WriteResponse>>anyObject());
.write(ArgumentMatchers.<StreamObserver<WriteResponse>>any());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
package com.google.devtools.build.lib.remote;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import static com.google.common.truth.Truth.assertThat;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyCollection;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
Expand Down

0 comments on commit 9b319f4

Please sign in to comment.