Skip to content

Commit

Permalink
Add test for Drive migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
huangsam committed Dec 7, 2024
1 parent cf6c106 commit 1d3133f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void testMigratePhotos() throws DbxException {

List<String> names = List.of("bauerlite.jpg", "salad.jpg", "foobar.jpg");
PhotoPathVisitor pathVisitor = visitor(getStaticResources(), names);
DropboxMigrator migrator = new DropboxMigrator("/Foo", clientMock, new PhotoResolver(List.of()));
Migrator migrator = new DropboxMigrator("folderId123", clientMock, new PhotoResolver(List.of()));
migrator.migratePhotos(pathVisitor.getPhotos());

assertEquals(2, migrator.getSuccessCount());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.huangsam.photohaul.migration;

import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.FileList;
import io.huangsam.photohaul.TestPathBase;
import io.huangsam.photohaul.traversal.PhotoPathVisitor;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.io.IOException;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class TestGoogleDriveMigrator extends TestPathBase {
@Mock
Drive driveMock;

@Mock
Drive.Files filesMock;

@Mock
Drive.Files.List driveListMock;

@Mock
FileList fileListMock;

@Mock
File fileMock;

@Test
void testMigratePhotos() throws IOException {
when(driveMock.files()).thenReturn(filesMock);
when(filesMock.list()).thenReturn(driveListMock);
when(driveListMock.setQ(any())).thenReturn(driveListMock);
when(driveListMock.execute()).thenReturn(fileListMock);
when(fileListMock.getFiles()).thenReturn(List.of(fileMock));

List<String> names = List.of("bauerlite.jpg", "salad.jpg", "foobar.jpg");
PhotoPathVisitor pathVisitor = visitor(getStaticResources(), names);
Migrator migrator = new GoogleDriveMigrator("Foo", driveMock, new PhotoResolver(List.of()));
migrator.migratePhotos(pathVisitor.getPhotos());

assertEquals(3, migrator.getFailureCount());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TestPathMigrator extends TestPathBase {
void testMigratePhotos() {
List<String> names = List.of("bauerlite.jpg", "salad.jpg", "foobar.jpg");
PhotoPathVisitor pathVisitor = visitor(getStaticResources(), names);
PathMigrator migrator = new PathMigrator(getTempResources(), new PhotoResolver(List.of()));
Migrator migrator = new PathMigrator(getTempResources(), new PhotoResolver(List.of()));
migrator.migratePhotos(pathVisitor.getPhotos());

assertEquals(2, migrator.getSuccessCount());
Expand Down

0 comments on commit 1d3133f

Please sign in to comment.