+ public void setupAlbum() {
+ final Album album = SoneDownloaderTest.this.album;
+ when(album.getAlbumImage()).thenReturn(mock(Image.class));
+ doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) {
+ nestedAlbums.put(album, (Album) invocation.getArguments()[0]);
+ return null;
+ }
+ }).when(album).addAlbum(any(Album.class));
+ doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocation) {
+ albumImages.put(album, (Image) invocation.getArguments()[0]);
+ return null;
+ }
+ }).when(album).addImage(any(Image.class));
+ when(album.getAlbums()).thenAnswer(new Answer<List<Album>>() {
+ @Override
+ public List<Album> answer(InvocationOnMock invocation) {
+ return nestedAlbums.get(album);
+ }
+ });
+ when(album.getImages()).thenAnswer(new Answer<List<Image>>() {
+ @Override
+ public List<Image> answer(InvocationOnMock invocation) {
+ return albumImages.get(album);
+ }
+ });
+ final Modifier albumModifier = new Modifier() {
+ private String title = album.getTitle();
+ private String description = album.getDescription();
+ private String imageId = album.getAlbumImage().getId();
+
+ @Override
+ public Modifier setTitle(String title) {
+ this.title = title;
+ return this;
+ }
+
+ @Override
+ public Modifier setDescription(String description) {
+ this.description = description;
+ return this;
+ }
+
+ @Override
+ public Modifier setAlbumImage(String imageId) {
+ this.imageId = imageId;
+ return this;
+ }
+
+ @Override
+ public Album update() throws IllegalStateException {
+ when(album.getTitle()).thenReturn(title);
+ when(album.getDescription()).thenReturn(description);
+ Image image = mock(Image.class);
+ when(image.getId()).thenReturn(imageId);
+ when(album.getAlbumImage()).thenReturn(image);
+ return album;
+ }
+ };
+ when(album.modify()).thenReturn(albumModifier);
+ }
+
+ @Before
+ public void setupAlbumBuilder() {
+ when(albumBuilder.withId(anyString())).thenAnswer(new Answer<AlbumBuilder>() {
+ @Override
+ public AlbumBuilder answer(InvocationOnMock invocation) {
+ when(album.getId()).thenReturn((String) invocation.getArguments()[0]);
+ return albumBuilder;
+ }
+ });
+ when(albumBuilder.randomId()).thenAnswer(new Answer<AlbumBuilder>() {
+ @Override
+ public AlbumBuilder answer(InvocationOnMock invocation) {
+ when(album.getId()).thenReturn(randomUUID().toString());
+ return albumBuilder;
+ }
+ });
+ when(albumBuilder.by(any(Sone.class))).thenAnswer(new Answer<AlbumBuilder>() {
+ @Override
+ public AlbumBuilder answer(InvocationOnMock invocation) {
+ when(album.getSone()).thenReturn((Sone) invocation.getArguments()[0]);
+ return albumBuilder;
+ }
+ });
+ when(albumBuilder.build()).thenAnswer(new Answer<Album>() {
+ @Override
+ public Album answer(InvocationOnMock invocation) {
+ Album album = SoneDownloaderTest.this.album;
+ albums.put(album.getId(), album);
+ SoneDownloaderTest.this.album = mock(Album.class);
+ setupAlbum();
+ return album;
+ }
+ });
+ when(core.albumBuilder()).thenReturn(albumBuilder);
+ }
+
+ @Before