From f0bf9ce12950f0a6106f59f105dae69592203f35 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 7 Sep 2014 14:38:21 +0200 Subject: [PATCH] =?utf8?q?Rename=20method=20that=20creates=20albums=20if?= =?utf8?q?=20they=20don=E2=80=99t=20exist.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sone/core/Core.java | 18 ++++++++++++++++-- .../pterodactylus/sone/core/SoneDownloaderImpl.java | 2 +- .../pterodactylus/sone/core/SoneDownloaderTest.java | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) 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]); -- 2.7.4