{
//Setup
Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
User user = new User(TEST_USER_ID , TEST_PASSWORD);
user.addToAlbums(album);
Photo photo = new Photo(TEST_PHOTO_NAME, TEST_PHOTO_CONTENT);
photo.setUploadTime(new Date());
for(Album anAlbum: user.getAlbums())
{
if(anAlbum.equals(album))
{
anAlbum.addToPhotos(photo);
}
}
em.persist(user);
long albumId = album.getAlbumId();
long photoId = photo.getPhotoId();
em.flush();
em.clear();
//Execute
user.removeFromAlbums(album);
user = repository.modify(user);
em.flush();
em.clear();
//Verify
User actualUser = em.find(User.class, TEST_USER_ID);
Album actualAlbum = em.find(Album.class, albumId);
Photo actualPhoto = em.find(Photo.class, photoId);
assertEquals(user, actualUser);
assertFalse(actualUser.getAlbums().contains(album));
assertNull(actualAlbum);
assertNull(actualPhoto);
}