@Override
  public ImportResult importItem(
      UUID jobId,
      IdempotentImportExecutor idempotentImportExecutor,
      TokensAndUrlAuthData authData,
      PhotosContainerResource data)
      throws Exception {
    if (data == null) {
      return ImportResult.OK;
    }

    AppleMediaInterface mediaInterface = factory
      .getOrCreateMediaInterface(jobId, authData, appCredentials, exportingService, monitor);

    // Uploads album metadata
    final int albumCount =
      mediaInterface.importAlbums(
            jobId,
            idempotentImportExecutor,
            data.getAlbums().stream()
                .map(MediaAlbum::photoToMediaAlbum)
                .collect(Collectors.toList()),
            DataVertical.PHOTOS.getDataType());
    final Map<String, Long> importPhotosResult =
      mediaInterface.importAllMedia(
            jobId,
            idempotentImportExecutor,
            data.getPhotos(),
            DataVertical.PHOTOS.getDataType());

    // generate import result
    final ImportResult result = ImportResult.OK;
    final Map<String, Integer> counts =
        new ImmutableMap.Builder<String, Integer>()
            .put(PhotosContainerResource.ALBUMS_COUNT_DATA_NAME, albumCount)
            .put(
                PhotosContainerResource.PHOTOS_COUNT_DATA_NAME,
                importPhotosResult.get(ApplePhotosConstants.COUNT_KEY).intValue())
            .build();
    return result
        .copyWithBytes(importPhotosResult.get(ApplePhotosConstants.BYTES_KEY))
        .copyWithCounts(counts);
  }
@Test
  public void importSinglePhoto() throws Exception {
    // set up
    final int photoCount = 1;
    final List<PhotoModel> photos = createTestPhotos(photoCount);
    final Map<String, Integer> dataIdToStatus =
        photos.stream()
            .collect(
                Collectors.toMap(
                    PhotoModel::getDataId,
                    photoModel -> SC_OK));
    setUpGetUploadUrlResponse(dataIdToStatus);
    setUpUploadContentResponse(dataIdToStatus);
    setUpCreateMediaResponse(dataIdToStatus);

    // run test
    PhotosContainerResource data = new PhotosContainerResource(null, photos);
    final ImportResult importResult =
        applePhotosImporter.importItem(uuid, executor, authData, data);

    // verify correct methods were called
    final List<String> dataIds =
        photos.stream().map(PhotoModel::getDataId).collect(Collectors.toList());
    verify(mediaInterface)
        .getUploadUrl(
            uuid.toString(), DataVertical.PHOTOS.getDataType(), dataIds);
    verify(mediaInterface).uploadContent(anyMap(), anyList());
    verify(mediaInterface).createMedia(anyString(), anyString(), anyList());

    // check the result
    assertThat(importResult.getCounts().isPresent()).isTrue();
    assertThat(importResult.getCounts().get().get(ALBUMS_COUNT_DATA_NAME) == 0).isTrue();
    assertThat(importResult.getCounts().get().get(PHOTOS_COUNT_DATA_NAME) == photoCount).isTrue();
    assertThat(importResult.getBytes().get() == photoCount * PHOTOS_FILE_SIZE).isTrue();

    final Map<String, Serializable> expectedKnownValue =
        photos.stream()
            .collect(
                Collectors.toMap(
                    photoModel -> photoModel.getAlbumId() + "-" + photoModel.getDataId(),
                    photoModel -> MEDIA_RECORDID_BASE + photoModel.getDataId()));
    checkKnownValues(expectedKnownValue);
  }