From: David ‘Bombe’ Roden Date: Mon, 16 Oct 2017 19:27:57 +0000 (+0200) Subject: Return nullable Post instead of Optional X-Git-Tag: 0.9.8^2~12 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=fd32e307db87c617a4c455f592b6e649ec50ae8a;p=Sone.git Return nullable Post instead of Optional --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index af69f98..2746d7b 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -422,11 +422,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, return database.newPostBuilder(); } - /** - * {@inheritDoc} - */ + @Nullable @Override - public Optional getPost(String postId) { + public Post getPost(@Nonnull String postId) { return database.getPost(postId); } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java index 5084c1c..3571172 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.data.impl; +import static com.google.common.base.Optional.fromNullable; + import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.database.PostProvider; @@ -78,7 +80,7 @@ public class PostReplyImpl extends ReplyImpl implements PostReply { */ @Override public Optional getPost() { - return postProvider.getPost(postId); + return fromNullable(postProvider.getPost(postId)); } } diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabase.java index 594cf2b..4c4bc3f 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabase.java @@ -1,5 +1,6 @@ package net.pterodactylus.sone.database.memory; +import static com.google.common.base.Optional.fromNullable; import static com.google.common.collect.FluentIterable.from; import java.util.HashSet; @@ -99,7 +100,7 @@ public class MemoryBookmarkDatabase implements BookmarkDatabase { new Function() { @Override public Post apply(String postId) { - return memoryDatabase.getPost(postId) + return fromNullable(memoryDatabase.getPost(postId)) .or(new EmptyPost(postId)); } }).toSet(); 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 0223c82..5e5021c 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -59,7 +59,6 @@ import net.pterodactylus.sone.database.SoneProvider; import net.pterodactylus.util.config.Configuration; import net.pterodactylus.util.config.ConfigurationException; -import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; @@ -332,12 +331,12 @@ public class MemoryDatabase extends AbstractService implements Database { // POSTPROVIDER METHODS // - /** {@inheritDocs} */ + @Nullable @Override - public Optional getPost(String postId) { + public Post getPost(@Nonnull String postId) { lock.readLock().lock(); try { - return fromNullable(allPosts.get(postId)); + return allPosts.get(postId); } finally { lock.readLock().unlock(); } diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java index 2fc8a88..687c28a 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryPostReply.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.database.memory; +import static com.google.common.base.Optional.fromNullable; + import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.PostReply; import net.pterodactylus.sone.data.Sone; @@ -150,7 +152,7 @@ class MemoryPostReply implements PostReply { */ @Override public Optional getPost() { - return database.getPost(postId); + return fromNullable(database.getPost(postId)); } // diff --git a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java index a47bde3..9942af7 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java +++ b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java @@ -184,11 +184,11 @@ public abstract class AbstractSoneCommand extends AbstractCommand { protected Post getPost(SimpleFieldSet simpleFieldSet, String parameterName) throws FcpException { try { String postId = simpleFieldSet.getString(parameterName); - Optional post = core.getPost(postId); - if (!post.isPresent()) { + Post post = core.getPost(postId); + if (post == null) { throw new FcpException("Could not load post from “" + postId + "”."); } - return post.get(); + return post; } catch (FSParseException fspe1) { throw new FcpException("Could not post ID from “" + parameterName + "”.", fspe1); } diff --git a/src/main/kotlin/net/pterodactylus/sone/database/PostProvider.kt b/src/main/kotlin/net/pterodactylus/sone/database/PostProvider.kt index fba9daf..37cb2a1 100644 --- a/src/main/kotlin/net/pterodactylus/sone/database/PostProvider.kt +++ b/src/main/kotlin/net/pterodactylus/sone/database/PostProvider.kt @@ -29,7 +29,7 @@ import com.google.inject.ImplementedBy @ImplementedBy(MemoryDatabase::class) interface PostProvider { - fun getPost(postId: String): Optional + fun getPost(postId: String): Post? fun getPosts(soneId: String): Collection fun getDirectedPosts(recipientId: String): Collection diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt index b185d2b..35ac0e2 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/BookmarkAjaxPage.kt @@ -1,6 +1,5 @@ package net.pterodactylus.sone.web.ajax -import net.pterodactylus.sone.utils.also import net.pterodactylus.sone.utils.emptyToNull import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface @@ -15,9 +14,10 @@ class BookmarkAjaxPage(webInterface: WebInterface) : JsonPage("bookmark.ajax", w override fun createJsonObject(request: FreenetRequest) = request.parameters["post"].emptyToNull - ?.let(core::getPost) - ?.also(core::bookmarkPost) - ?.let { createSuccessJsonObject() } + ?.let { postId -> + core.getPost(postId)?.also(core::bookmarkPost) + createSuccessJsonObject() + } ?: createErrorJsonObject("invalid-post-id") } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt index 96fb7e4..cb3b86d 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.kt @@ -3,7 +3,6 @@ package net.pterodactylus.sone.web.ajax import net.pterodactylus.sone.freenet.L10nFilter import net.pterodactylus.sone.text.TimeTextConverter import net.pterodactylus.sone.utils.jsonObject -import net.pterodactylus.sone.utils.let import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest @@ -27,7 +26,7 @@ class GetTimesAjaxPage(webInterface: WebInterface, override fun createJsonObject(request: FreenetRequest) = createSuccessJsonObject().apply { - put("postTimes", request.parameters["posts"]!!.idsToJson { core.getPost(it).let { it.id to it.time } }) + put("postTimes", request.parameters["posts"]!!.idsToJson { core.getPost(it)?.let { it.id to it.time } }) put("replyTimes", request.parameters["replies"]!!.idsToJson { core.getPostReply(it)?.let { it.id to it.time } }) } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt index 224007d..0451eaa 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.kt @@ -1,8 +1,5 @@ package net.pterodactylus.sone.web.ajax -import com.google.common.base.Optional -import net.pterodactylus.sone.utils.asOptional -import net.pterodactylus.sone.utils.mapPresent import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest @@ -16,16 +13,16 @@ class MarkAsKnownAjaxPage(webInterface: WebInterface) : JsonPage("markAsKnown.aj override val requiresLogin = false override fun createJsonObject(request: FreenetRequest) = when (request.parameters["type"]) { - "sone" -> processIds(request, { core.getSone(it).asOptional() }, core::markSoneKnown) + "sone" -> processIds(request, core::getSone, core::markSoneKnown) "post" -> processIds(request, core::getPost, core::markPostKnown) - "reply" -> processIds(request, { core.getPostReply(it).asOptional() }, core::markReplyKnown) + "reply" -> processIds(request, core::getPostReply, core::markReplyKnown) else -> createErrorJsonObject("invalid-type") } - private fun processIds(request: FreenetRequest, getter: (String) -> Optional, marker: (T) -> Unit) = + private fun processIds(request: FreenetRequest, getter: (String) -> T?, marker: (T) -> Unit) = request.parameters["id"] ?.split(Regex(" +")) - ?.mapPresent(getter) + ?.mapNotNull(getter) ?.onEach(marker) .let { createSuccessJsonObject() } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt index 519d49e..7fb2320 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/BookmarkPage.kt @@ -16,7 +16,7 @@ class BookmarkPage(template: Template, webInterface: WebInterface) if (freenetRequest.isPOST) { val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) val postId = freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36) - webInterface.core.getPost(postId).orNull()?.let { + webInterface.core.getPost(postId)?.let { webInterface.core.bookmarkPost(it) } throw RedirectException(returnPage) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt index a6c58e4..a3fc1f3 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPage.kt @@ -22,7 +22,7 @@ class CreateReplyPage(template: Template, webInterface: WebInterface): templateContext["errorTextEmpty"] = true return } - val post = webInterface.core.getPost(postId).orNull() ?: throw RedirectException("noPermission.html") + val post = webInterface.core.getPost(postId) ?: throw RedirectException("noPermission.html") val sender = webInterface.core.getLocalSone(freenetRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: getCurrentSone(freenetRequest.toadletContext) webInterface.core.createReply(sender, post, TextFilter.filter(freenetRequest.httpRequest.getHeader("Host"), text)) throw RedirectException(returnPage) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt index 21465d7..181144e 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt @@ -14,7 +14,7 @@ class DeletePostPage(template: Template, webInterface: WebInterface): override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { if (freenetRequest.isPOST) { - val post = webInterface.core.getPost(freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)).orNull() ?: throw RedirectException("noPermission.html") + val post = webInterface.core.getPost(freenetRequest.httpRequest.getPartAsStringFailsafe("post", 36)) ?: throw RedirectException("noPermission.html") val returnPage = freenetRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256) if (!post.sone.isLocal) { throw RedirectException("noPermission.html") @@ -29,7 +29,7 @@ class DeletePostPage(template: Template, webInterface: WebInterface): templateContext["returnPage"] = returnPage return } - templateContext["post"] = webInterface.core.getPost(freenetRequest.httpRequest.getParam("post")).orNull() ?: throw RedirectException("noPermission.html") + templateContext["post"] = webInterface.core.getPost(freenetRequest.httpRequest.getParam("post")) ?: throw RedirectException("noPermission.html") templateContext["returnPage"] = freenetRequest.httpRequest.getParam("returnPage") } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt index 31e70fc..49c1075 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPage.kt @@ -19,7 +19,7 @@ class MarkAsKnownPage(template: Template, webInterface: WebInterface): val ids = freenetRequest.parameters["id", 65536]!!.split(" ") when (freenetRequest.parameters["type", 5]) { "sone" -> ids.mapNotNull(webInterface.core::getSone).forEach(webInterface.core::markSoneKnown) - "post" -> ids.mapPresent(webInterface.core::getPost).forEach(webInterface.core::markPostKnown) + "post" -> ids.mapNotNull(webInterface.core::getPost).forEach(webInterface.core::markPostKnown) "reply" -> ids.mapNotNull(webInterface.core::getPostReply).forEach(webInterface.core::markReplyKnown) else -> throw RedirectException("invalid.html") } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt index d021dfb..02d63c5 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/SearchPage.kt @@ -43,7 +43,7 @@ class SearchPage @JvmOverloads constructor(template: Template, webInterface: Web 1 -> phrases.first().phrase.also { word -> when { word.removePrefix("sone://").let(webInterface.core::getSone) != null -> redirect("viewSone.html?sone=${word.removePrefix("sone://")}") - word.removePrefix("post://").let(webInterface.core::getPost).isPresent -> redirect("viewPost.html?post=${word.removePrefix("post://")}") + word.removePrefix("post://").let(webInterface.core::getPost) != null -> redirect("viewPost.html?post=${word.removePrefix("post://")}") word.removePrefix("reply://").let(webInterface.core::getPostReply) != null -> redirect("viewPost.html?post=${word.removePrefix("reply://").let(webInterface.core::getPostReply)?.postId}") word.removePrefix("album://").let(webInterface.core::getAlbum) != null -> redirect("imageBrowser.html?album=${word.removePrefix("album://")}") word.removePrefix("image://").let { webInterface.core.getImage(it, false) } != null -> redirect("imageBrowser.html?image=${word.removePrefix("image://")}") diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt index d331417..910c939 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ViewPostPage.kt @@ -16,7 +16,7 @@ class ViewPostPage(template: Template, webInterface: WebInterface): SoneTemplatePage("viewPost.html", template, "Page.ViewPost.Title", webInterface, false) { override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { - templateContext["post"] = freenetRequest.parameters["post"]?.let(webInterface.core::getPost)?.orNull() + templateContext["post"] = freenetRequest.parameters["post"]?.let(webInterface.core::getPost) templateContext["raw"] = freenetRequest.parameters["raw"] == "true" } diff --git a/src/test/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabaseTest.java b/src/test/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabaseTest.java index e6bfffe..7edea06 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabaseTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryBookmarkDatabaseTest.java @@ -1,6 +1,5 @@ package net.pterodactylus.sone.database.memory; -import static com.google.common.base.Optional.fromNullable; import static net.pterodactylus.sone.test.Matchers.isPostWithId; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; @@ -19,7 +18,6 @@ import java.util.Set; import net.pterodactylus.sone.data.Post; -import com.google.common.base.Optional; import org.junit.Before; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; @@ -42,12 +40,11 @@ public class MemoryBookmarkDatabaseTest { @Before public void setupMemoryDatabase() { when(memoryDatabase.getPost(anyString())).thenAnswer( - new Answer>() { + new Answer() { @Override - public Optional answer( + public Post answer( InvocationOnMock invocation) { - return fromNullable( - posts.get(invocation.getArguments()[0])); + return posts.get(invocation.getArguments()[0]); } }); } 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 d4c0954..bb62eaf 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java @@ -178,12 +178,12 @@ public class MemoryDatabaseTest { firstAlbum.addImage(thirdImage); secondAlbum.addImage(secondImage); memoryDatabase.storeSone(sone); - assertThat(memoryDatabase.getPost("post1").get(), + assertThat(memoryDatabase.getPost("post1"), isPost(firstPost.getId(), 1000L, "post1", Optional.absent())); - assertThat(memoryDatabase.getPost("post2").get(), + assertThat(memoryDatabase.getPost("post2"), isPost(secondPost.getId(), 2000L, "post2", of(RECIPIENT_ID))); - assertThat(memoryDatabase.getPost("post3").isPresent(), is(false)); + assertThat(memoryDatabase.getPost("post3"), nullValue()); assertThat(memoryDatabase.getPostReply("reply1"), isPostReply("reply1", "post1", 3000L, "reply1")); assertThat(memoryDatabase.getPostReply("reply2"), diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index b763cd1..79f1974 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -467,9 +467,10 @@ public class SoneTextParserTest { private static class TestPostProvider implements PostProvider { + @Nullable @Override - public Optional getPost(final String postId) { - return Optional.of(new Post() { + public Post getPost(@Nonnull final String postId) { + return new Post() { @Override public String getId() { return postId; @@ -514,7 +515,7 @@ public class SoneTextParserTest { public Post setKnown(boolean known) { return null; } - }); + }; } @Override @@ -531,9 +532,10 @@ public class SoneTextParserTest { private static class AbsentPostProvider extends TestPostProvider { + @Nullable @Override - public Optional getPost(String postId) { - return Optional.absent(); + public Post getPost(@Nonnull String postId) { + return null; } } diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt index 5b4809c..a6e69cd 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/CreateReplyCommandTest.kt @@ -64,7 +64,7 @@ class CreateReplyCommandTest : SoneCommandTest() { private fun addValidPostParameter() { parameters += "Post" to "ValidPostId" - whenever(core.getPost("ValidPostId")).thenReturn(of(post)) + whenever(core.getPost("ValidPostId")).thenReturn(post) } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt index 751ad24..30fc4cb 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt @@ -38,7 +38,7 @@ class DeletePostCommandTest : SoneCommandTest() { @Test fun `request with post from remote sone returns error response`() { parameters += "Post" to "RemotePostId" - whenever(core.getPost("RemotePostId")).thenReturn(of(postFromRemoteSone)) + whenever(core.getPost("RemotePostId")).thenReturn(postFromRemoteSone) val response = command.execute(parameters) assertThat(response.replyParameters["Message"], equalTo("Error")) assertThat(response.replyParameters["ErrorCode"], equalTo("401")) @@ -47,7 +47,7 @@ class DeletePostCommandTest : SoneCommandTest() { @Test fun `request with post from local sone deletes posts`() { parameters += "Post" to "LocalPostId" - whenever(core.getPost("LocalPostId")).thenReturn(of(postFromLocalSone)) + whenever(core.getPost("LocalPostId")).thenReturn(postFromLocalSone) val response = command.execute(parameters) assertThat(response.replyParameters["Message"], equalTo("PostDeleted")) verify(core).deletePost(postFromLocalSone) diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt index b7f911c..5c76c5b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/GetPostCommandTest.kt @@ -31,7 +31,7 @@ class GetPostCommandTest : SoneCommandTest() { @Before fun setupPostWithLikesAndReplies() { - whenever(core.getPost("ValidPostId")).thenReturn(post.asOptional()) + whenever(core.getPost("ValidPostId")).thenReturn(post) whenever(core.getLikes(post)).thenReturn(setOf(sone1, sone2)) val replies = listOf(postReply1, postReply2) whenever(core.getReplies("ValidPostId")).thenReturn(replies) diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/LikePostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/LikePostCommandTest.kt index b344f51..6c7d40c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/LikePostCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/LikePostCommandTest.kt @@ -23,7 +23,7 @@ class LikePostCommandTest : SoneCommandTest() { @Before fun setupPostAndSones() { - whenever(core.getPost("PostId")).thenReturn(post.asOptional()) + whenever(core.getPost("PostId")).thenReturn(post) whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone) whenever(core.getSone("LocalSoneId")).thenReturn(localSone) } diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt index 5397683..de92612 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/SoneCommandTest.kt @@ -39,7 +39,7 @@ abstract class SoneCommandTest { @Before fun setupCore() { whenever(core.getSone(anyString())).thenReturn(null) - whenever(core.getPost(anyString())).thenReturn(absent()) + whenever(core.getPost(anyString())).thenReturn(null) whenever(core.getPostReply(anyString())).thenReturn(null) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt index 0dbbeaf..a42e5ba 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt @@ -93,7 +93,7 @@ open class TestObjects { whenever(core.updateChecker).thenReturn(updateChecker) whenever(core.getSone(ArgumentMatchers.anyString())).thenAnswer { (localSones + remoteSones)[it.getArgument(0)] } whenever(core.getLocalSone(ArgumentMatchers.anyString())).thenAnswer { localSones[it[0]] } - whenever(core.getPost(ArgumentMatchers.anyString())).thenAnswer { (posts + newPosts)[it[0]].asOptional() } + whenever(core.getPost(ArgumentMatchers.anyString())).thenAnswer { (posts + newPosts)[it[0]] } whenever(core.getLikes(ArgumentMatchers.any())).then { postLikes[it[0]] ?: emptySet() } whenever(core.getLikes(ArgumentMatchers.any())).then { replyLikes[it[0]] ?: emptySet() } whenever(core.getPostReply(ArgumentMatchers.anyString())).then { replies[it[0]] } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt index 2687963..ce16c85 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt @@ -92,7 +92,7 @@ open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePag whenever(core.getSone(anyString())).then { allSones[it[0]] } whenever(core.localSones).then { localSones.values } whenever(core.getLocalSone(anyString())).then { localSones[it[0]] } - whenever(core.getPost(anyString())).then { allPosts[it[0]].asOptional() } + whenever(core.getPost(anyString())).then { allPosts[it[0]] } whenever(core.getPostReply(anyString())).then { allPostReplies[it[0]] } whenever(core.getReplies(anyString())).then { perPostReplies[it[0]].asList() } whenever(core.getAlbum(anyString())).then { allAlbums[it[0]] }