From: David ‘Bombe’ Roden Date: Sun, 7 Sep 2014 12:38:21 +0000 (+0200) Subject: Rename method that creates albums if they don’t exist. X-Git-Tag: 0.9-rc1^2~3^2~147 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f0bf9ce12950f0a6106f59f105dae69592203f35;p=Sone.git Rename method that creates albums if they don’t exist. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 1229448..ba12a8d 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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) { diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java index 9da1ba0..ca47132 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloaderImpl.java @@ -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 { diff --git a/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java index 6b98ace..c17c12f 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java @@ -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() { + when(core.getOrCreateAlbum(anyString())).thenAnswer(new Answer() { @Override public Album answer(InvocationOnMock invocation) throws Throwable { return albums.get(invocation.getArguments()[0]);