Return a nullable Album instead of an Optional
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 15 Oct 2017 17:27:01 +0000 (19:27 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 15 Oct 2017 17:27:01 +0000 (19:27 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/database/AlbumProvider.kt
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java

index 63c82ed..af69f98 100644 (file)
@@ -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() {
index 0ad0c67..c0b09e8 100644 (file)
@@ -26,6 +26,6 @@ import com.google.common.base.Optional
  */
 interface AlbumProvider {
 
-       fun getAlbum(albumId: String): Optional<Album>
+       fun getAlbum(albumId: String): Album?
 
 }
index 79c34d7..0223c82 100644 (file)
@@ -478,11 +478,12 @@ public class MemoryDatabase extends AbstractService implements Database {
        // ALBUMPROVDER METHODS
        //
 
+       @Nullable
        @Override
-       public Optional<Album> 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();
                }
index 6e66b18..d4c0954 100644 (file)
@@ -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.<Album>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.<Album>absent()));
+               assertThat(memoryDatabase.getAlbum(newAlbum.getId()), nullValue());
        }
 
        private void initializeFriends() {