Rename method that creates albums if they don’t exist.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 7 Sep 2014 12:38:21 +0000 (14:38 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 7 Sep 2014 12:38:21 +0000 (14:38 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java
src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java

index 1229448..ba12a8d 100644 (file)
@@ -229,6 +229,20 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                this.database = database;
        }
 
+       @VisibleForTesting
+       protected Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, SoneDownloader soneDownloader, ImageInserter imageInserter, UpdateChecker updateChecker, WebOfTrustUpdater webOfTrustUpdater, EventBus eventBus, Database database) {
+               super("Sone Core");
+               this.configuration = configuration;
+               this.freenetInterface = freenetInterface;
+               this.identityManager = identityManager;
+               this.soneDownloader = soneDownloader;
+               this.imageInserter = imageInserter;
+               this.updateChecker = updateChecker;
+               this.webOfTrustUpdater = webOfTrustUpdater;
+               this.eventBus = eventBus;
+               this.database = database;
+       }
+
        //
        // ACCESSORS
        //
@@ -592,7 +606,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         *            The ID of the album
         * @return The album with the given ID
         */
-       public Album getAlbum(String albumId) {
+       public Album getOrCreateAlbum(String albumId) {
                return getAlbum(albumId, true);
        }
 
@@ -1217,7 +1231,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                                logger.log(Level.WARNING, "Invalid album found, aborting load!");
                                return;
                        }
-                       Album album = getAlbum(albumId).setSone(sone).modify().setTitle(albumTitle).setDescription(albumDescription).setAlbumImage(albumImageId).update();
+                       Album album = getOrCreateAlbum(albumId).setSone(sone).modify().setTitle(albumTitle).setDescription(albumDescription).setAlbumImage(albumImageId).update();
                        if (albumParentId != null) {
                                Album parentAlbum = getAlbum(albumParentId, false);
                                if (parentAlbum == null) {
index 9da1ba0..ca47132 100644 (file)
@@ -455,7 +455,7 @@ public class SoneDownloaderImpl extends AbstractService implements SoneDownloade
                                                return null;
                                        }
                                }
-                               Album album = core.getAlbum(id).setSone(sone).modify().setTitle(title).setDescription(description).update();
+                               Album album = core.getOrCreateAlbum(id).setSone(sone).modify().setTitle(title).setDescription(description).update();
                                if (parent != null) {
                                        parent.addAlbum(album);
                                } else {
index 6b98ace..c17c12f 100644 (file)
@@ -211,7 +211,7 @@ public class SoneDownloaderTest {
        public void setupAlbums() {
                albums.put("album-id-1", new AlbumImpl("album-id-1"));
                albums.put("album-id-2", new AlbumImpl("album-id-2"));
-               when(core.getAlbum(anyString())).thenAnswer(new Answer<Album>() {
+               when(core.getOrCreateAlbum(anyString())).thenAnswer(new Answer<Album>() {
                        @Override
                        public Album answer(InvocationOnMock invocation) throws Throwable {
                                return albums.get(invocation.getArguments()[0]);