From: David ‘Bombe’ Roden Date: Sun, 15 Oct 2017 17:27:01 +0000 (+0200) Subject: Return a nullable Album instead of an Optional X-Git-Tag: 0.9.8^2~15 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e666a5187afee8bdb40b5e4c82a0cdddbe713719;p=Sone.git Return a nullable Album instead of an Optional --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 63c82ed..af69f98 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -543,7 +543,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, */ @Nullable public Album getAlbum(@Nonnull String albumId) { - return database.getAlbum(albumId).orNull(); + return database.getAlbum(albumId); } public ImageBuilder imageBuilder() { diff --git a/src/main/java/net/pterodactylus/sone/database/AlbumProvider.kt b/src/main/java/net/pterodactylus/sone/database/AlbumProvider.kt index 0ad0c67..c0b09e8 100644 --- a/src/main/java/net/pterodactylus/sone/database/AlbumProvider.kt +++ b/src/main/java/net/pterodactylus/sone/database/AlbumProvider.kt @@ -26,6 +26,6 @@ import com.google.common.base.Optional */ interface AlbumProvider { - fun getAlbum(albumId: String): Optional + fun getAlbum(albumId: String): Album? } diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 79c34d7..0223c82 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -478,11 +478,12 @@ public class MemoryDatabase extends AbstractService implements Database { // ALBUMPROVDER METHODS // + @Nullable @Override - public Optional getAlbum(String albumId) { + public Album getAlbum(@Nonnull String albumId) { lock.readLock().lock(); try { - return fromNullable(allAlbums.get(albumId)); + return allAlbums.get(albumId); } finally { lock.readLock().unlock(); } diff --git a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java index 6e66b18..d4c0954 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java @@ -191,13 +191,13 @@ public class MemoryDatabaseTest { assertThat(memoryDatabase.getPostReply("reply3"), isPostReply("reply3", "post1", 5000L, "reply3")); assertThat(memoryDatabase.getPostReply("reply4"), nullValue()); - assertThat(memoryDatabase.getAlbum("album1").get(), + assertThat(memoryDatabase.getAlbum("album1"), isAlbum("album1", null, "album1", "album-description1")); - assertThat(memoryDatabase.getAlbum("album2").get(), + assertThat(memoryDatabase.getAlbum("album2"), isAlbum("album2", null, "album2", "album-description2")); - assertThat(memoryDatabase.getAlbum("album3").get(), + assertThat(memoryDatabase.getAlbum("album3"), isAlbum("album3", "album1", "album3", "album-description3")); - assertThat(memoryDatabase.getAlbum("album4").isPresent(), is(false)); + assertThat(memoryDatabase.getAlbum("album4"), nullValue()); assertThat(memoryDatabase.getImage("image1"), isImage("image1", 1000L, "KSK@image1", "image1", "image-description1", 16, 9)); @@ -266,11 +266,11 @@ public class MemoryDatabaseTest { @Test public void testBasicAlbumFunctionality() { Album newAlbum = new AlbumImpl(mock(Sone.class)); - assertThat(memoryDatabase.getAlbum(newAlbum.getId()), is(Optional.absent())); + assertThat(memoryDatabase.getAlbum(newAlbum.getId()), nullValue()); memoryDatabase.storeAlbum(newAlbum); - assertThat(memoryDatabase.getAlbum(newAlbum.getId()), is(of(newAlbum))); + assertThat(memoryDatabase.getAlbum(newAlbum.getId()), is(newAlbum)); memoryDatabase.removeAlbum(newAlbum); - assertThat(memoryDatabase.getAlbum(newAlbum.getId()), is(Optional.absent())); + assertThat(memoryDatabase.getAlbum(newAlbum.getId()), nullValue()); } private void initializeFriends() {