コード例 #1
0
  @Test
  public void testModifyAlbumRemoveMultiplePhotos() throws Exception {
    // Setup
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    Album createdAlbum = repository.create(album);

    Photo photo = new Photo(TEST_PHOTO_NAME, TEST_PHOTO_CONTENT);
    photo.setUploadTime(new Date());
    createdAlbum.addToPhotos(photo);
    Photo secondPhoto = new Photo("Photo #2", "Photo Content #2".getBytes());
    secondPhoto.setUploadTime(new Date());
    createdAlbum.addToPhotos(secondPhoto);
    Photo thirdPhoto = new Photo("Photo #3", "Photo Content #3".getBytes());
    thirdPhoto.setUploadTime(new Date());
    createdAlbum.addToPhotos(thirdPhoto);
    createdAlbum = repository.modify(createdAlbum);
    em.flush();

    // Execute
    createdAlbum.removeFromPhotos(photo);
    Album modifiedAlbum = repository.modify(createdAlbum);

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, modifiedAlbum.getAlbumId());
    assertEquals(modifiedAlbum, actualAlbum);
    assertThat(actualAlbum.getPhotos(), hasItems(secondPhoto, thirdPhoto));
    assertThat(actualAlbum.getCoverPhoto(), either(equalTo(secondPhoto)).or(equalTo(thirdPhoto)));
  }
コード例 #2
0
  @Test
  public void testModifyAlbumRemovePhoto() throws Exception {
    // Setup
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    Album createdAlbum = repository.create(album);

    Photo photo = new Photo(TEST_PHOTO_NAME, TEST_PHOTO_CONTENT);
    photo.setUploadTime(new Date());
    createdAlbum.addToPhotos(photo);
    createdAlbum = repository.modify(createdAlbum);
    em.flush();

    // Execute
    createdAlbum.removeFromPhotos(photo);
    Album modifiedAlbum = repository.modify(createdAlbum);

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, modifiedAlbum.getAlbumId());
    assertEquals(modifiedAlbum, actualAlbum);
    assertFalse(actualAlbum.getPhotos().contains(photo));
    assertNull(actualAlbum.getCoverPhoto());
  }