@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 importAlbumWithoutName() throws Exception {
    // set up
    when(mediaInterface.createAlbums(any(), any(), any())).thenCallRealMethod();
    when(mediaInterface.makePhotosServicePostRequest(any(), any()))
            .thenAnswer(
                    (Answer<byte[]>)
                            invocation -> {
                              Object[] args = invocation.getArguments();
                              final byte[] payload = (byte[]) args[1];
                              final PhotosProtocol.CreateAlbumsRequest createAlbumsRequest = PhotosProtocol.CreateAlbumsRequest.parseFrom(payload);
                              final List<NewPhotoAlbumResponse> newPhotoAlbumResponseList =
                                      createAlbumsRequest.getNewPhotoAlbumRequestsList().stream()
                                              .map(
                                                      newPhotoAlbumRequest ->
                                                              NewPhotoAlbumResponse.newBuilder()
                                                                      .setRecordId(
                                                                              ALBUM_RECORDID_BASE + newPhotoAlbumRequest.getDataId())
                                                                      .setDataId(newPhotoAlbumRequest.getDataId())
                                                                      .setName(newPhotoAlbumRequest.getName())
                                                                      .setStatus(
                                                                              Status.newBuilder()
                                                                                      .setCode(SC_OK)
                                                                                      .build())
                                                                      .build())
                                              .collect(Collectors.toList());
                              return CreateAlbumsResponse.newBuilder()
                                      .addAllNewPhotoAlbumResponses(newPhotoAlbumResponseList)
                                      .build().toByteArray();
                            });
    final int albumCount = 1;
    final List<PhotoAlbum> photoAlbums = List.of(new PhotoAlbum(ALBUM_DATAID_BASE, null, ALBUM_DESCRIPTION_BASE));

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

    // verify correct methods were called
    verify(mediaInterface)
            .createAlbums(
                    uuid.toString(),
                    DataVertical.PHOTOS.getDataType(),
                    data.getAlbums().stream()
                            .map(MediaAlbum::photoToMediaAlbum)
                            .collect(Collectors.toList()));

    // check the result
    assertThat(importResult.getCounts().isPresent()).isTrue();
    assertThat(importResult.getCounts().get().get(ALBUMS_COUNT_DATA_NAME) == albumCount).isTrue();
    final Map<String, Serializable> expectedKnownValue =
            photoAlbums.stream()
                    .collect(
                            Collectors.toMap(
                                    PhotoAlbum::getId, photoAlbum -> ALBUM_RECORDID_BASE + photoAlbum.getId()));
    checkKnownValues(expectedKnownValue);
  }