@Test public void getFilesFromDriveTest() throws IOException { doReturn(mockedRequest).when(mockedDriveService).generateRequest(anyString(), anyString()); driveHelper.getFilesFromDrive(anyString(), anyString()); verify(mockedDriveService, times(1)).fetchAllFiles(any(Drive.Files.List.class), ArgumentMatchers.anyList()); clearInvocations(mockedDriveService); driveHelper.getFilesFromDrive(null, null); verify(mockedDriveService, times(0)).fetchAllFiles(any(Drive.Files.List.class), ArgumentMatchers.anyList()); }
public List<com.google.api.services.drive.model.File> getFilesFromDrive( @Nullable String folderName, @Nullable String parentId) throws IOException { List<com.google.api.services.drive.model.File> files = new ArrayList<>(); String mimeType = folderName != null ? FOLDER_MIME_TYPE : null; String requestString = generateSearchQuery(folderName, parentId, mimeType); String fields = "nextPageToken, files(modifiedTime, id, name, mimeType)"; Drive.Files.List request = buildRequest(requestString, fields); if (request != null) { driveService.fetchAllFiles(request, files); } return files; }
DriveHelper { public List<com.google.api.services.drive.model.File> getFilesFromDrive( @Nullable String folderName, @Nullable String parentId) throws IOException { List<com.google.api.services.drive.model.File> files = new ArrayList<>(); String mimeType = folderName != null ? FOLDER_MIME_TYPE : null; String requestString = generateSearchQuery(folderName, parentId, mimeType); String fields = "nextPageToken, files(modifiedTime, id, name, mimeType)"; Drive.Files.List request = buildRequest(requestString, fields); if (request != null) { driveService.fetchAllFiles(request, files); } return files; } }
DriveHelper { public List<com.google.api.services.drive.model.File> getFilesFromDrive( @Nullable String folderName, @Nullable String parentId) throws IOException { List<com.google.api.services.drive.model.File> files = new ArrayList<>(); String mimeType = folderName != null ? FOLDER_MIME_TYPE : null; String requestString = generateSearchQuery(folderName, parentId, mimeType); String fields = "nextPageToken, files(modifiedTime, id, name, mimeType)"; Drive.Files.List request = buildRequest(requestString, fields); if (request != null) { driveService.fetchAllFiles(request, files); } return files; } DriveHelper(@NonNull GoogleAccountCredential credential,
                @NonNull HttpTransport transport,
                @NonNull JsonFactory jsonFactory);   DriveHelper(DriveService driveService); }
DriveHelper { public List<com.google.api.services.drive.model.File> getFilesFromDrive( @Nullable String folderName, @Nullable String parentId) throws IOException { List<com.google.api.services.drive.model.File> files = new ArrayList<>(); String mimeType = folderName != null ? FOLDER_MIME_TYPE : null; String requestString = generateSearchQuery(folderName, parentId, mimeType); String fields = "nextPageToken, files(modifiedTime, id, name, mimeType)"; Drive.Files.List request = buildRequest(requestString, fields); if (request != null) { driveService.fetchAllFiles(request, files); } return files; } DriveHelper(@NonNull GoogleAccountCredential credential,
                @NonNull HttpTransport transport,
                @NonNull JsonFactory jsonFactory);   DriveHelper(DriveService driveService); String getRootFolderId(); @Nullable Drive.Files.List buildRequest(String query, String fields); void downloadFile(@NonNull String fileId, @NonNull File file); String createOrGetIDOfSubmissionsFolder(); @Nullable String getIDOfFolderWithName(@NonNull String name, @Nullable String inFolder, boolean shouldCreateIfNotFound); String uploadFileToDrive(String mediaName, String destinationFolderID, File toUpload); String createFolderInDrive(@NonNull String folderName,
                                      @Nullable String parentId); com.google.api.services.drive.model.File createNewFile(@NonNull String name,
                                                                  @Nullable String mimeType,
                                                                  @Nullable String parentId); List<com.google.api.services.drive.model.File> getFilesFromDrive(
            @Nullable String folderName,
            @Nullable String parentId); @Nullable String generateSearchQuery(@Nullable String folderName,
                                      @Nullable String parentId,
                                      @Nullable String mimeType); void fetchFilesForCurrentPage(Drive.Files.List request, List<com.google.api.services.drive.model.File> files); }
DriveHelper { public List<com.google.api.services.drive.model.File> getFilesFromDrive( @Nullable String folderName, @Nullable String parentId) throws IOException { List<com.google.api.services.drive.model.File> files = new ArrayList<>(); String mimeType = folderName != null ? FOLDER_MIME_TYPE : null; String requestString = generateSearchQuery(folderName, parentId, mimeType); String fields = "nextPageToken, files(modifiedTime, id, name, mimeType)"; Drive.Files.List request = buildRequest(requestString, fields); if (request != null) { driveService.fetchAllFiles(request, files); } return files; } DriveHelper(@NonNull GoogleAccountCredential credential,
                @NonNull HttpTransport transport,
                @NonNull JsonFactory jsonFactory);   DriveHelper(DriveService driveService); String getRootFolderId(); @Nullable Drive.Files.List buildRequest(String query, String fields); void downloadFile(@NonNull String fileId, @NonNull File file); String createOrGetIDOfSubmissionsFolder(); @Nullable String getIDOfFolderWithName(@NonNull String name, @Nullable String inFolder, boolean shouldCreateIfNotFound); String uploadFileToDrive(String mediaName, String destinationFolderID, File toUpload); String createFolderInDrive(@NonNull String folderName,
                                      @Nullable String parentId); com.google.api.services.drive.model.File createNewFile(@NonNull String name,
                                                                  @Nullable String mimeType,
                                                                  @Nullable String parentId); List<com.google.api.services.drive.model.File> getFilesFromDrive(
            @Nullable String folderName,
            @Nullable String parentId); @Nullable String generateSearchQuery(@Nullable String folderName,
                                      @Nullable String parentId,
                                      @Nullable String mimeType); void fetchFilesForCurrentPage(Drive.Files.List request, List<com.google.api.services.drive.model.File> files); static final String ODK_GOOGLE_DRIVE_ROOT_FOLDER_NAME; static final String ODK_GOOGLE_DRIVE_SUBMISSION_FOLDER_NAME; static final String FOLDER_MIME_TYPE; }