Skip to content

Commit

Permalink
Allow third_party/bazel/ to use Mockito 2
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 239185340
  • Loading branch information
Googler authored and copybara-github committed Mar 19, 2019
1 parent 814fb29 commit f1bbbff
Show file tree
Hide file tree
Showing 27 changed files with 65 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ java_library(
"//third_party:jsr305",
"//third_party:jsr330_inject",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:truth",
"//third_party/java/mockito:mockito2_for_third_party",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ java_library(
"//src/tools/android/java/com/google/devtools/build/android/dexer",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"@bazel_tools//tools/java/runfiles",
] + select({
Expand Down
32 changes: 16 additions & 16 deletions src/test/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization:constants",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party/protobuf:protobuf_java",
],
)
Expand Down Expand Up @@ -364,7 +364,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs",
"//src/main/java/com/google/devtools/common/options",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth8",
],
)
Expand All @@ -386,7 +386,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib:out-err",
"//src/main/java/com/google/devtools/build/lib:util",
"//src/main/protobuf:bazel_flags_java_proto",
"//third_party:mockito",
"//third_party:mockito2",
],
)

Expand Down Expand Up @@ -574,7 +574,7 @@ java_library(
"//src/main/java/com/google/devtools/common/options",
"//src/main/protobuf:action_cache_java_proto",
"//third_party:jsr305",
"//third_party:mockito",
"//third_party:mockito2",
],
)

Expand Down Expand Up @@ -614,7 +614,7 @@ java_test(
"//src/main/java/com/google/devtools/common/options",
"//src/main/protobuf:action_cache_java_proto",
"//third_party:jsr305",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth8",
],
)
Expand Down Expand Up @@ -699,7 +699,7 @@ java_library(
"//src/test/java/com/google/devtools/build/lib/skyframe:testutil",
"//src/test/java/com/google/devtools/build/skyframe:testutil",
"//third_party:jsr305",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party/protobuf:protobuf_java",
"@bazel_tools//tools/java/runfiles",
],
Expand Down Expand Up @@ -754,7 +754,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/protobuf:extra_actions_base_java_proto",
"//third_party:jsr305",
"//third_party:mockito",
"//third_party:mockito2",
],
)

Expand Down Expand Up @@ -793,7 +793,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib/skyframe/trimming:trimmable_test_fragments",
"//third_party:auto_value",
"//third_party:jsr305",
"//third_party:mockito",
"//third_party:mockito2",
],
)

Expand Down Expand Up @@ -892,7 +892,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib/skyframe:testutil",
"//third_party:auto_value",
"//third_party:jsr305",
"//third_party:mockito",
"//third_party:mockito2",
],
)

Expand Down Expand Up @@ -955,7 +955,7 @@ java_library(
"//src/main/protobuf:crosstool_config_java_proto",
"//src/main/protobuf:extra_actions_base_java_proto",
"//third_party:jsr305",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party/protobuf:protobuf_java",
],
)
Expand Down Expand Up @@ -995,7 +995,7 @@ java_test(
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//src/main/protobuf:build_java_proto",
"//third_party:jsr305",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party/protobuf:protobuf_java",
],
)
Expand Down Expand Up @@ -1054,7 +1054,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/protobuf:command_server_java_proto",
"//third_party:jsr305",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party/grpc:grpc-jar",
"//third_party/protobuf:protobuf_java",
],
Expand Down Expand Up @@ -1275,7 +1275,7 @@ java_test(
"//src/main/protobuf:invocation_policy_java_proto",
"//src/main/protobuf:test_status_java_proto",
"//src/test/java/com/google/devtools/common/options:testutils",
"//third_party:mockito",
"//third_party:mockito2",
],
)

Expand Down Expand Up @@ -1406,7 +1406,7 @@ java_test(
"//src/main/java/com/google/devtools/common/options",
"//src/main/protobuf:spawn_java_proto",
"//src/main/protobuf:test_status_java_proto",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party/protobuf:protobuf_java",
],
)
Expand Down Expand Up @@ -1434,7 +1434,7 @@ java_test(
"//src/main/java/com/google/devtools/common/options",
"//src/main/tools:process-wrapper",
"//src/test/shell/integration:spend_cpu_time",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth8",
],
)
Expand All @@ -1455,7 +1455,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs",
"//third_party:mockito",
"//third_party:mockito2",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ java_test(
"//third_party:jsr305",
"//third_party:junit4",
"//third_party:maven",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"@bazel_tools//tools/java/runfiles",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib:testutil",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib:testutil",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ public class HttpStreamTest {
@Before
public void before() throws Exception {
when(connection.getInputStream()).thenReturn(new ByteArrayInputStream(data));
when(progress.create(any(InputStream.class), any(URL.class), any(URL.class))).thenAnswer(
new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock invocation) throws Throwable {
return (InputStream) invocation.getArguments()[0];
}
});
when(progress.create(any(InputStream.class), any(), any(URL.class)))
.thenAnswer(
new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock invocation) throws Throwable {
return (InputStream) invocation.getArguments()[0];
}
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib:testutil",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"//third_party/grpc:grpc-jar",
"@com_google_protobuf//:protobuf_java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ java_test(
"//src/main/java/com/google/devtools/common/options",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib:packages_testutil",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"//third_party/protobuf:protobuf_java",
"//third_party/protobuf:protobuf_java_util",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ public void testThatTestLogAndOutputAreReturned() throws Exception {
when(spawnActionContext.exec(any(), any()))
.thenAnswer(
(invocation) -> {
Spawn spawn = invocation.getArgumentAt(0, Spawn.class);
Spawn spawn = invocation.getArgument(0);
if (spawn.getOutputFiles().size() != 1) {
FileOutErr outErr =
invocation.getArgumentAt(1, ActionExecutionContext.class).getFileOutErr();
ActionExecutionContext context = invocation.getArgument(1);
FileOutErr outErr = context.getFileOutErr();
try (OutputStream stream = outErr.getOutputStream()) {
stream.write("This will not appear in the test output: bla\n".getBytes(UTF_8));
stream.write((TestLogHelper.HEADER_DELIMITER + "\n").getBytes(UTF_8));
Expand Down Expand Up @@ -537,9 +537,9 @@ public void testThatTestLogAndOutputAreReturnedWithSplitXmlGeneration() throws E
when(spawnActionContext.exec(any(), any()))
.thenAnswer(
(invocation) -> {
Spawn spawn = invocation.getArgumentAt(0, Spawn.class);
FileOutErr outErr =
invocation.getArgumentAt(1, ActionExecutionContext.class).getFileOutErr();
Spawn spawn = invocation.getArgument(0);
ActionExecutionContext context = invocation.getArgument(1);
FileOutErr outErr = context.getFileOutErr();
called.add(outErr);
if (spawn.getOutputFiles().size() != 1) {
try (OutputStream stream = outErr.getOutputStream()) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/google/devtools/build/lib/profiler/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib:testutil",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/vfs",
"//third_party:guava",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"//third_party/pprof:profile_java_proto",
],
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/google/devtools/build/lib/query2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ java_library(
"//third_party:guava",
"//third_party:jsr305",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
],
)
2 changes: 1 addition & 1 deletion src/test/java/com/google/devtools/build/lib/remote/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib/remote/util",
"//third_party:api_client",
"//third_party:guava",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"//third_party/grpc:grpc-jar",
"//third_party/protobuf:protobuf_java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ java_test(
"//third_party:api_client",
"//third_party:auth",
"//third_party:guava",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:netty",
"//third_party:truth",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ java_test(
"//src/test/java/com/google/devtools/build/lib:test_runner",
"//src/test/java/com/google/devtools/build/lib:testutil",
"//third_party:guava",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"//third_party/grpc:grpc-jar",
"//third_party/protobuf:protobuf_java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ java_test(
"//third_party:guava-testlib",
"//third_party:jsr305",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"//third_party/protobuf:protobuf_java",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ java_test(
"//third_party:guava",
"//third_party:jsr305",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"//third_party/protobuf:protobuf_java",
],
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/google/devtools/build/lib/shell/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ java_library(
"//third_party:guava-testlib",
"//third_party:jsr305",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"//third_party:truth8",
],
Expand Down Expand Up @@ -266,7 +266,7 @@ java_test(
"//third_party:guava-testlib",
"//third_party:jsr305",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"//third_party:truth8",
],
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/google/devtools/build/lib/skyframe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ java_test(
"//third_party:guava-testlib",
"//third_party:jsr305",
"//third_party:junit4",
"//third_party:mockito",
"//third_party:mockito2",
"//third_party:truth",
"//third_party/protobuf:protobuf_java",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.mockito.hamcrest.MockitoHamcrest;

/**
* Test for WorkspaceASTFunction.
Expand Down Expand Up @@ -69,9 +69,10 @@ private RootedPath createWorkspaceFile(String... contents) throws IOException {

private SkyFunction.Environment getEnv() throws InterruptedException {
SkyFunction.Environment env = Mockito.mock(SkyFunction.Environment.class);
Mockito.when(env.getValue(Matchers.argThat(new SkyKeyMatchers(FileValue.FILE))))
Mockito.when(env.getValue(MockitoHamcrest.argThat(new SkyKeyMatchers(FileValue.FILE))))
.thenReturn(fakeWorkspaceFileValue);
Mockito.when(env.getValue(Matchers.argThat(new SkyKeyMatchers(SkyFunctions.PRECOMPUTED))))
Mockito.when(
env.getValue(MockitoHamcrest.argThat(new SkyKeyMatchers(SkyFunctions.PRECOMPUTED))))
.thenReturn(new PrecomputedValue(Optional.<RootedPath>absent()));
return env;
}
Expand Down
Loading

0 comments on commit f1bbbff

Please sign in to comment.