mirror of
https://github.com/google/nomulus.git
synced 2025-07-21 18:26:12 +02:00
Allow third_party/java_src/gtld/ to use :mockito2_for_third_party
In [] a change would have been made to your project that is incompatible with your open source integration. To make sure the open source variant of your project remains working, we have eagerly updated your open source copy to use Mockito 2. This CL integrates that change into []. Please read []and understand the consequences of this change. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=238445356
This commit is contained in:
parent
1a6c068471
commit
202ed9db6a
70 changed files with 200 additions and 199 deletions
|
@ -13,13 +13,13 @@ java_library(
|
|||
deps = [
|
||||
"//java/google/registry/storage/drive",
|
||||
"//javatests/google/registry/testing",
|
||||
"//third_party/java/mockito",
|
||||
"@com_google_apis_google_api_services_drive",
|
||||
"@com_google_guava",
|
||||
"@com_google_http_client",
|
||||
"@com_google_truth",
|
||||
"@com_google_truth_extensions_truth_java8_extension",
|
||||
"@junit",
|
||||
"@org_mockito_core",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -17,8 +17,9 @@ package google.registry.storage.drive;
|
|||
import static com.google.common.io.ByteStreams.toByteArray;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
@ -59,14 +60,11 @@ public class DriveConnectionTest {
|
|||
List<String> allChildren;
|
||||
|
||||
private ArgumentMatcher<ByteArrayContent> hasByteArrayContent(final byte[] data) {
|
||||
return new ArgumentMatcher<ByteArrayContent>() {
|
||||
@Override
|
||||
public boolean matches(Object arg) {
|
||||
try {
|
||||
return Arrays.equals(data, toByteArray(((ByteArrayContent) arg).getInputStream()));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return arg -> {
|
||||
try {
|
||||
return Arrays.equals(data, toByteArray(arg.getInputStream()));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -97,28 +95,29 @@ public class DriveConnectionTest {
|
|||
when(childrenList.execute()).thenReturn(childList1, childList2);
|
||||
when(childrenList.setQ(anyString())).thenReturn(childrenList);
|
||||
when(childrenList.getPageToken()).thenCallRealMethod();
|
||||
when(childrenList.setPageToken(anyString())).thenCallRealMethod();
|
||||
when(childrenList.setPageToken(any())).thenCallRealMethod();
|
||||
when(children.list("driveFolderId")).thenReturn(childrenList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFileAtRoot() throws Exception {
|
||||
when(files.insert(
|
||||
eq(new File().setTitle("title").setMimeType("image/gif")),
|
||||
argThat(hasByteArrayContent(DATA))))
|
||||
.thenReturn(insert);
|
||||
eq(new File().setTitle("title").setMimeType("image/gif")),
|
||||
argThat(hasByteArrayContent(DATA))))
|
||||
.thenReturn(insert);
|
||||
assertThat(driveConnection.createFile("title", MediaType.GIF, null, DATA)).isEqualTo("id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFileInFolder() throws Exception {
|
||||
when(files.insert(
|
||||
eq(new File()
|
||||
.setTitle("title")
|
||||
.setMimeType("image/gif")
|
||||
.setParents(ImmutableList.of(new ParentReference().setId("parent")))),
|
||||
argThat(hasByteArrayContent(DATA))))
|
||||
.thenReturn(insert);
|
||||
eq(
|
||||
new File()
|
||||
.setTitle("title")
|
||||
.setMimeType("image/gif")
|
||||
.setParents(ImmutableList.of(new ParentReference().setId("parent")))),
|
||||
argThat(hasByteArrayContent(DATA))))
|
||||
.thenReturn(insert);
|
||||
assertThat(driveConnection.createFile("title", MediaType.GIF, "parent", DATA)).isEqualTo("id");
|
||||
}
|
||||
|
||||
|
@ -164,12 +163,13 @@ public class DriveConnectionTest {
|
|||
@Test
|
||||
public void testCreateOrUpdateFile_succeedsForNewFile() throws Exception {
|
||||
when(files.insert(
|
||||
eq(new File()
|
||||
.setTitle("title")
|
||||
.setMimeType("video/webm")
|
||||
.setParents(ImmutableList.of(new ParentReference().setId("driveFolderId")))),
|
||||
argThat(hasByteArrayContent(DATA))))
|
||||
.thenReturn(insert);
|
||||
eq(
|
||||
new File()
|
||||
.setTitle("title")
|
||||
.setMimeType("video/webm")
|
||||
.setParents(ImmutableList.of(new ParentReference().setId("driveFolderId")))),
|
||||
argThat(hasByteArrayContent(DATA))))
|
||||
.thenReturn(insert);
|
||||
ChildList emptyChildList = new ChildList().setItems(ImmutableList.of()).setNextPageToken(null);
|
||||
when(childrenList.execute()).thenReturn(emptyChildList);
|
||||
assertThat(driveConnection.createOrUpdateFile(
|
||||
|
@ -183,10 +183,8 @@ public class DriveConnectionTest {
|
|||
@Test
|
||||
public void testCreateOrUpdateFile_succeedsForUpdatingFile() throws Exception {
|
||||
when(files.update(
|
||||
eq("id"),
|
||||
eq(new File().setTitle("title")),
|
||||
argThat(hasByteArrayContent(DATA))))
|
||||
.thenReturn(update);
|
||||
eq("id"), eq(new File().setTitle("title")), argThat(hasByteArrayContent(DATA))))
|
||||
.thenReturn(update);
|
||||
ChildList childList = new ChildList()
|
||||
.setItems(ImmutableList.of(new ChildReference().setId("id")))
|
||||
.setNextPageToken(null);
|
||||
|
@ -224,10 +222,8 @@ public class DriveConnectionTest {
|
|||
@Test
|
||||
public void testUpdateFile_succeeds() throws Exception {
|
||||
when(files.update(
|
||||
eq("id"),
|
||||
eq(new File().setTitle("title")),
|
||||
argThat(hasByteArrayContent(DATA))))
|
||||
.thenReturn(update);
|
||||
eq("id"), eq(new File().setTitle("title")), argThat(hasByteArrayContent(DATA))))
|
||||
.thenReturn(update);
|
||||
assertThat(driveConnection.updateFile("id", "title", MediaType.WEBM_VIDEO, DATA))
|
||||
.isEqualTo("id");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue