import net.pterodactylus.util.thread.NamedThreadFactory;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
* The text of the post
* @return The created post
*/
- public Post createPost(Sone sone, Optional<Sone> recipient, String text) {
+ public Post createPost(Sone sone, @Nullable Sone recipient, String text) {
checkNotNull(text, "text must not be null");
checkArgument(text.trim().length() > 0, "text must not be empty");
if (!sone.isLocal()) {
}
PostBuilder postBuilder = database.newPostBuilder();
postBuilder.from(sone.getId()).randomId().currentTime().withText(text.trim());
- if (recipient.isPresent()) {
- postBuilder.to(recipient.get().getId());
+ if (recipient != null) {
+ postBuilder.to(recipient.getId());
}
final Post post = postBuilder.build();
database.storePost(post);
/**
* FCP command that creates a new {@link Post}.
*
- * @see Core#createPost(Sone, Optional, String)
+ * @see Core#createPost(Sone, Sone, String)
*/
public class CreatePostCommand extends AbstractSoneCommand {
if (sone.equals(recipient)) {
return new ErrorResponse("Sone and Recipient must not be the same.");
}
- Post post = getCore().createPost(sone, Optional.fromNullable(recipient), text);
+ Post post = getCore().createPost(sone, recipient, text);
return new Response("PostCreated", new SimpleFieldSetBuilder().put("Post", post.getId()).get());
}
*/
@Subscribe
public void newPostFound(NewPostFoundEvent newPostFoundEvent) {
- Post post = newPostFoundEvent.post();
+ Post post = newPostFoundEvent.getPost();
boolean isLocal = post.getSone().isLocal();
if (isLocal) {
localPostNotification.add(post);
*/
@Subscribe
public void newReplyFound(NewPostReplyFoundEvent newPostReplyFoundEvent) {
- PostReply reply = newPostReplyFoundEvent.postReply();
+ PostReply reply = newPostReplyFoundEvent.getPostReply();
boolean isLocal = reply.getSone().isLocal();
if (isLocal) {
localReplyNotification.add(reply);
@Subscribe
public void postRemoved(PostRemovedEvent postRemovedEvent) {
- removePost(postRemovedEvent.post());
+ removePost(postRemovedEvent.getPost());
}
private void removePost(Post post) {
@Subscribe
public void replyRemoved(PostReplyRemovedEvent postReplyRemovedEvent) {
- removeReply(postReplyRemovedEvent.postReply());
+ removeReply(postReplyRemovedEvent.getPostReply());
}
private void removeReply(PostReply reply) {
/**
* Event that signals that a new post was found.
*/
-data class NewPostFoundEvent(val post: Post) {
-
- @Deprecated(message = "will go away", replaceWith = ReplaceWith("post"))
- fun post() = post
-
-}
+data class NewPostFoundEvent(val post: Post)
/**
* Event that signals that a new [PostReply] was found.
*/
-data class NewPostReplyFoundEvent(val postReply: PostReply) {
-
- @Deprecated(message = "will go away", replaceWith = ReplaceWith("postReply"))
- fun postReply() = postReply
-
-}
+data class NewPostReplyFoundEvent(val postReply: PostReply)
/**
* Event that signals that a [Post] was removed.
*/
-data class PostRemovedEvent(val post: Post) {
-
- @Deprecated(message = "will go away", replaceWith = ReplaceWith("post"))
- fun post() = post
-
-}
+data class PostRemovedEvent(val post: Post)
--- /dev/null
+package net.pterodactylus.sone.main
+
+import com.google.common.base.*
+import com.google.common.eventbus.*
+import com.google.inject.*
+import com.google.inject.matcher.*
+import com.google.inject.name.Names.*
+import com.google.inject.spi.*
+import net.pterodactylus.sone.database.*
+import net.pterodactylus.sone.database.memory.*
+import net.pterodactylus.sone.freenet.wot.*
+import net.pterodactylus.util.config.*
+import net.pterodactylus.util.config.ConfigurationException
+import net.pterodactylus.util.version.Version
+import java.io.*
+
+class SoneModule(private val sonePlugin: SonePlugin) : AbstractModule() {
+
+ override fun configure() {
+ val sonePropertiesFile = File("sone.properties")
+ val firstStart = !sonePropertiesFile.exists()
+ var newConfig = false
+ val configuration = try {
+ Configuration(MapConfigurationBackend(sonePropertiesFile, false))
+ } catch (ce: ConfigurationException) {
+ sonePropertiesFile.delete()
+ newConfig = true
+ Configuration(MapConfigurationBackend(sonePropertiesFile, true))
+ }
+ val context = Context("Sone")
+ val loaders = configuration.getStringValue("Developer.LoadFromFilesystem")
+ .getValue(null)
+ ?.let {
+ configuration.getStringValue("Developer.FilesystemPath")
+ .getValue(null)
+ ?.let { DebugLoaders(it) }
+ }
+ val eventBus = EventBus()
+
+ bind(Configuration::class.java).toInstance(configuration)
+ bind(EventBus::class.java).toInstance(eventBus)
+ bind(Boolean::class.java).annotatedWith(named("FirstStart")).toInstance(firstStart)
+ bind(Boolean::class.java).annotatedWith(named("NewConfig")).toInstance(newConfig)
+ bind(Context::class.java).toInstance(context)
+ bind(object : TypeLiteral<Optional<Context>>() {}).toInstance(Optional.of(context))
+ bind(SonePlugin::class.java).toInstance(sonePlugin)
+ bind(Version::class.java).toInstance(sonePlugin.version.parseVersion())
+ bind(PluginVersion::class.java).toInstance(PluginVersion(sonePlugin.version))
+ bind(PluginYear::class.java).toInstance(PluginYear(sonePlugin.year))
+ bind(PluginHomepage::class.java).toInstance(PluginHomepage(sonePlugin.homepage))
+ bind(Database::class.java).to(MemoryDatabase::class.java).`in`(Singleton::class.java)
+ loaders?.let { bind(Loaders::class.java).toInstance(it) }
+
+ bindListener(Matchers.any(), object : TypeListener {
+ override fun <I> hear(typeLiteral: TypeLiteral<I>, typeEncounter: TypeEncounter<I>) {
+ typeEncounter.register(InjectionListener { injectee -> eventBus.register(injectee) })
+ }
+ })
+ }
+
+}
+
+private fun String.parseVersion(): Version = Version.parse(this)
+++ /dev/null
-package net.pterodactylus.sone.main
-
-import com.google.common.base.*
-import com.google.common.eventbus.*
-import com.google.inject.*
-import com.google.inject.matcher.*
-import com.google.inject.name.Names.*
-import com.google.inject.spi.*
-import net.pterodactylus.sone.database.*
-import net.pterodactylus.sone.database.memory.*
-import net.pterodactylus.sone.freenet.wot.*
-import net.pterodactylus.util.config.*
-import net.pterodactylus.util.config.ConfigurationException
-import net.pterodactylus.util.version.Version
-import java.io.*
-
-class SoneModuleCreator {
-
- fun createModule(sonePlugin: SonePlugin) = object : AbstractModule() {
- override fun configure() {
- val sonePropertiesFile = File("sone.properties")
- val firstStart = !sonePropertiesFile.exists()
- var newConfig = false
- val configuration = try {
- Configuration(MapConfigurationBackend(sonePropertiesFile, false))
- } catch (ce: ConfigurationException) {
- sonePropertiesFile.delete()
- newConfig = true
- Configuration(MapConfigurationBackend(sonePropertiesFile, true))
- }
- val context = Context("Sone")
- val loaders = configuration.getStringValue("Developer.LoadFromFilesystem")
- .getValue(null)
- ?.let {
- configuration.getStringValue("Developer.FilesystemPath")
- .getValue(null)
- ?.let { DebugLoaders(it) }
- }
- val eventBus = EventBus()
-
- bind(Configuration::class.java).toInstance(configuration)
- bind(EventBus::class.java).toInstance(eventBus)
- bind(Boolean::class.java).annotatedWith(named("FirstStart")).toInstance(firstStart)
- bind(Boolean::class.java).annotatedWith(named("NewConfig")).toInstance(newConfig)
- bind(Context::class.java).toInstance(context)
- bind(object : TypeLiteral<Optional<Context>>() {}).toInstance(Optional.of(context))
- bind(SonePlugin::class.java).toInstance(sonePlugin)
- bind(Version::class.java).toInstance(sonePlugin.version.parseVersion())
- bind(PluginVersion::class.java).toInstance(PluginVersion(sonePlugin.version))
- bind(PluginYear::class.java).toInstance(PluginYear(sonePlugin.year))
- bind(PluginHomepage::class.java).toInstance(PluginHomepage(sonePlugin.homepage))
- bind(Database::class.java).to(MemoryDatabase::class.java).`in`(Singleton::class.java)
- loaders?.let { bind(Loaders::class.java).toInstance(it) }
-
- bindListener(Matchers.any(), object : TypeListener {
- override fun <I> hear(typeLiteral: TypeLiteral<I>, typeEncounter: TypeEncounter<I>) {
- typeEncounter.register(InjectionListener { injectee -> eventBus.register(injectee) })
- }
- })
- }
- }
-
-}
-
-private fun String.parseVersion(): Version = Version.parse(this)
?.let { text ->
val sender = request.parameters["sender"].emptyToNull?.let(core::getSone) ?: currentSone
val recipient = request.parameters["recipient"]?.let(core::getSone)
- core.createPost(sender, recipient.asOptional(), text).let { post ->
+ core.createPost(sender, recipient, text).let { post ->
createSuccessJsonObject().apply {
put("postId", post.id)
put("sone", sender.id)
}
val sender = soneRequest.core.getLocalSone(soneRequest.httpRequest.getPartAsStringFailsafe("sender", 43)) ?: currentSone
val recipient = soneRequest.core.getSone(soneRequest.httpRequest.getPartAsStringFailsafe("recipient", 43))
- soneRequest.core.createPost(sender, recipient.asOptional(), TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), text))
+ soneRequest.core.createPost(sender, recipient, TextFilter.filter(soneRequest.httpRequest.getHeader("Host"), text))
throw RedirectException(returnPage)
}
}
mismatchDescription.appendText("is not PostRemovedEvent");
return false;
}
- if (((PostRemovedEvent) item).post() != post) {
- mismatchDescription.appendText("post is ").appendValue(((PostRemovedEvent) item).post());
+ if (((PostRemovedEvent) item).getPost() != post) {
+ mismatchDescription.appendText("post is ").appendValue(((PostRemovedEvent) item).getPost());
return false;
}
return true;
parameters += "Text" to "Test"
whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
val post = mock<Post>().apply { whenever(id).thenReturn("PostId") }
- whenever(core.createPost(localSone, absent(), "Test")).thenReturn(post)
+ whenever(core.createPost(localSone, null, "Test")).thenReturn(post)
val response = command.execute(parameters)
assertThat(response.replyParameters.get("Message"), equalTo("PostCreated"))
assertThat(response.replyParameters.get("Post"), equalTo("PostId"))
whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone)
val post = mock<Post>().apply { whenever(id).thenReturn("PostId") }
- whenever(core.createPost(localSone, of(remoteSone), "Test")).thenReturn(post)
+ whenever(core.createPost(localSone, remoteSone, "Test")).thenReturn(post)
val response = command.execute(parameters)
assertThat(response.replyParameters.get("Message"), equalTo("PostCreated"))
assertThat(response.replyParameters.get("Post"), equalTo("PostId"))
+++ /dev/null
-package net.pterodactylus.sone.main
-
-import com.google.common.base.*
-import com.google.common.eventbus.*
-import com.google.inject.*
-import com.google.inject.name.Names.*
-import net.pterodactylus.sone.database.*
-import net.pterodactylus.sone.database.memory.*
-import net.pterodactylus.sone.freenet.wot.*
-import net.pterodactylus.sone.test.*
-import net.pterodactylus.util.config.*
-import net.pterodactylus.util.version.Version
-import org.hamcrest.MatcherAssert.*
-import org.hamcrest.Matchers.*
-import org.junit.*
-import java.io.*
-import java.util.concurrent.atomic.*
-
-class SoneModuleCreatorTest {
-
- private val currentDir: File = File(".")
- private val pluginVersion = Version("", 0, 1, 2)
- private val pluginYear = 2019
- private val pluginHomepage = "home://page"
- private val sonePlugin = mock<SonePlugin>().apply {
- whenever(version).thenReturn(pluginVersion.toString())
- whenever(year).thenReturn(pluginYear)
- whenever(homepage).thenReturn(pluginHomepage)
- }
-
- @After
- fun removePropertiesFromCurrentDirectory() {
- File(currentDir, "sone.properties").delete()
- }
-
- @Test
- fun `creator binds configuration when no file is present`() {
- File(currentDir, "sone.properties").delete()
- assertThat(getInstance<Configuration>(), notNullValue())
- }
-
- @Test
- fun `creator binds first start to true when no file is present`() {
- File(currentDir, "sone.properties").delete()
- assertThat(getInstance(named("FirstStart")), equalTo(true))
- }
-
- @Test
- fun `config file is created in current directory if not present`() {
- File(currentDir, "sone.properties").delete()
- val configuration = getInstance<Configuration>()
- configuration.save()
- assertThat(File(currentDir, "sone.properties").exists(), equalTo(true))
- }
-
- @Test
- fun `creator binds configuration when file is present`() {
- File(currentDir, "sone.properties").writeText("Option=old")
- assertThat(getInstance<Configuration>().getStringValue("Option").value, equalTo("old"))
- }
-
- @Test
- fun `creator binds first start to false when file is present`() {
- File(currentDir, "sone.properties").writeText("Option=old")
- assertThat(getInstance(named("FirstStart")), equalTo(false))
- }
-
- @Test
- fun `invalid config file leads to new config being created`() {
- File(currentDir, "sone.properties").writeText("Option=old\nbroken")
- val configuration = getInstance<Configuration>()
- assertThat(configuration.getStringValue("Option").getValue(null), nullValue())
- }
-
- @Test
- fun `invalid config file leads to new config being set to true`() {
- File(currentDir, "sone.properties").writeText("Option=old\nbroken")
- assertThat(getInstance(named("NewConfig")), equalTo(true))
- }
-
- @Test
- fun `valid config file leads to new config being set to false`() {
- File(currentDir, "sone.properties").writeText("Option=old")
- assertThat(getInstance(named("NewConfig")), equalTo(false))
- }
-
- @Test
- fun `event bus is bound`() {
- assertThat(getInstance<EventBus>(), notNullValue())
- }
-
- @Test
- fun `context is bound`() {
- assertThat(getInstance<Context>().context, equalTo("Sone"))
- }
-
- @Test
- fun `optional context is bound`() {
- assertThat(getInstance<Optional<Context>>().get().context, equalTo("Sone"))
- }
-
- @Test
- fun `sone plugin is bound`() {
- assertThat(getInstance(), sameInstance(sonePlugin))
- }
-
- @Test
- fun `version is bound`() {
- assertThat(getInstance(), equalTo(pluginVersion))
- }
-
- @Test
- fun `plugin version is bound`() {
- assertThat(getInstance(), equalTo(PluginVersion(pluginVersion.toString())))
- }
-
- @Test
- fun `plugin year is bound`() {
- assertThat(getInstance(), equalTo(PluginYear(pluginYear)))
- }
-
- @Test
- fun `plugin homepage in bound`() {
- assertThat(getInstance(), equalTo(PluginHomepage(pluginHomepage)))
- }
-
- @Test
- fun `database is bound correctly`() {
- assertThat(getInstance<Database>(), instanceOf(MemoryDatabase::class.java))
- }
-
- @Test
- fun `default loader is used without dev options`() {
- assertThat(getInstance<Loaders>(), instanceOf(DefaultLoaders::class.java))
- }
-
- @Test
- fun `default loaders are used if no path is given`() {
- File(currentDir, "sone.properties").writeText("Developer.LoadFromFilesystem=true")
- assertThat(getInstance<Loaders>(), instanceOf(DefaultLoaders::class.java))
- }
-
- @Test
- fun `debug loaders are used if path is given`() {
- File(currentDir, "sone.properties").writeText("Developer.LoadFromFilesystem=true\nDeveloper.FilesystemPath=/tmp")
- assertThat(getInstance<Loaders>(), instanceOf(DebugLoaders::class.java))
- }
-
- class TestObject {
- val ref: AtomicReference<Any?> = AtomicReference()
- @Subscribe
- fun testEvent(event: Any?) {
- ref.set(event)
- }
- }
-
- @Test
- fun `created objects are registered with event bus`() {
- val injector = createInjector()
- val eventBus: EventBus = getInstance(injector = injector)
- val testObject = getInstance<TestObject>(injector = injector)
- val event = Any()
- eventBus.post(event)
- assertThat(testObject.ref.get(), sameInstance(event))
- }
-
- private fun createInjector(): Injector = SoneModuleCreator()
- .createModule(sonePlugin)
- .let { Guice.createInjector(it) }
-
- private inline fun <reified R : Any> getInstance(annotation: Annotation? = null, injector: Injector = createInjector()): R =
- annotation
- ?.let { injector.getInstance(Key.get(object : TypeLiteral<R>() {}, it)) }
- ?: injector.getInstance(Key.get(object : TypeLiteral<R>() {}))
-
-}
--- /dev/null
+package net.pterodactylus.sone.main
+
+import com.google.common.base.*
+import com.google.common.eventbus.*
+import com.google.inject.Guice.*
+import com.google.inject.name.Names.*
+import net.pterodactylus.sone.database.*
+import net.pterodactylus.sone.database.memory.*
+import net.pterodactylus.sone.freenet.wot.*
+import net.pterodactylus.sone.test.*
+import net.pterodactylus.util.config.*
+import net.pterodactylus.util.version.Version
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import org.junit.*
+import java.io.*
+import java.util.concurrent.atomic.*
+
+class SoneModuleTest {
+
+ private val currentDir: File = File(".")
+ private val pluginVersion = Version("", 0, 1, 2)
+ private val pluginYear = 2019
+ private val pluginHomepage = "home://page"
+ private val sonePlugin = mock<SonePlugin>().apply {
+ whenever(version).thenReturn(pluginVersion.toString())
+ whenever(year).thenReturn(pluginYear)
+ whenever(homepage).thenReturn(pluginHomepage)
+ }
+
+ private val injector by lazy { createInjector(SoneModule(sonePlugin)) }
+
+ @After
+ fun removePropertiesFromCurrentDirectory() {
+ File(currentDir, "sone.properties").delete()
+ }
+
+ @Test
+ fun `creator binds configuration when no file is present`() {
+ File(currentDir, "sone.properties").delete()
+ assertThat(injector.getInstance<Configuration>(), notNullValue())
+ }
+
+ @Test
+ fun `creator binds first start to true when no file is present`() {
+ File(currentDir, "sone.properties").delete()
+ assertThat(injector.getInstance(named("FirstStart")), equalTo(true))
+ }
+
+ @Test
+ fun `config file is created in current directory if not present`() {
+ File(currentDir, "sone.properties").delete()
+ val configuration = injector.getInstance<Configuration>()
+ configuration.save()
+ assertThat(File(currentDir, "sone.properties").exists(), equalTo(true))
+ }
+
+ @Test
+ fun `creator binds configuration when file is present`() {
+ File(currentDir, "sone.properties").writeText("Option=old")
+ assertThat(injector.getInstance<Configuration>().getStringValue("Option").value, equalTo("old"))
+ }
+
+ @Test
+ fun `creator binds first start to false when file is present`() {
+ File(currentDir, "sone.properties").writeText("Option=old")
+ assertThat(injector.getInstance(named("FirstStart")), equalTo(false))
+ }
+
+ @Test
+ fun `invalid config file leads to new config being created`() {
+ File(currentDir, "sone.properties").writeText("Option=old\nbroken")
+ val configuration = injector.getInstance<Configuration>()
+ assertThat(configuration.getStringValue("Option").getValue(null), nullValue())
+ }
+
+ @Test
+ fun `invalid config file leads to new config being set to true`() {
+ File(currentDir, "sone.properties").writeText("Option=old\nbroken")
+ assertThat(injector.getInstance(named("NewConfig")), equalTo(true))
+ }
+
+ @Test
+ fun `valid config file leads to new config being set to false`() {
+ File(currentDir, "sone.properties").writeText("Option=old")
+ assertThat(injector.getInstance(named("NewConfig")), equalTo(false))
+ }
+
+ @Test
+ fun `event bus is bound`() {
+ assertThat(injector.getInstance<EventBus>(), notNullValue())
+ }
+
+ @Test
+ fun `context is bound`() {
+ assertThat(injector.getInstance<Context>().context, equalTo("Sone"))
+ }
+
+ @Test
+ fun `optional context is bound`() {
+ assertThat(injector.getInstance<Optional<Context>>().get().context, equalTo("Sone"))
+ }
+
+ @Test
+ fun `sone plugin is bound`() {
+ assertThat(injector.getInstance(), sameInstance(sonePlugin))
+ }
+
+ @Test
+ fun `version is bound`() {
+ assertThat(injector.getInstance(), equalTo(pluginVersion))
+ }
+
+ @Test
+ fun `plugin version is bound`() {
+ assertThat(injector.getInstance(), equalTo(PluginVersion(pluginVersion.toString())))
+ }
+
+ @Test
+ fun `plugin year is bound`() {
+ assertThat(injector.getInstance(), equalTo(PluginYear(pluginYear)))
+ }
+
+ @Test
+ fun `plugin homepage in bound`() {
+ assertThat(injector.getInstance(), equalTo(PluginHomepage(pluginHomepage)))
+ }
+
+ @Test
+ fun `database is bound correctly`() {
+ assertThat(injector.getInstance<Database>(), instanceOf(MemoryDatabase::class.java))
+ }
+
+ @Test
+ fun `default loader is used without dev options`() {
+ assertThat(injector.getInstance<Loaders>(), instanceOf(DefaultLoaders::class.java))
+ }
+
+ @Test
+ fun `default loaders are used if no path is given`() {
+ File(currentDir, "sone.properties").writeText("Developer.LoadFromFilesystem=true")
+ assertThat(injector.getInstance<Loaders>(), instanceOf(DefaultLoaders::class.java))
+ }
+
+ @Test
+ fun `debug loaders are used if path is given`() {
+ File(currentDir, "sone.properties").writeText("Developer.LoadFromFilesystem=true\nDeveloper.FilesystemPath=/tmp")
+ assertThat(injector.getInstance<Loaders>(), instanceOf(DebugLoaders::class.java))
+ }
+
+ class TestObject {
+ val ref: AtomicReference<Any?> = AtomicReference()
+ @Subscribe
+ fun testEvent(event: Any?) {
+ ref.set(event)
+ }
+ }
+
+ @Test
+ fun `created objects are registered with event bus`() {
+ val eventBus: EventBus = injector.getInstance()
+ val testObject = injector.getInstance<TestObject>()
+ val event = Any()
+ eventBus.post(event)
+ assertThat(testObject.ref.get(), sameInstance(event))
+ }
+
+}
package net.pterodactylus.sone.test
-import com.google.inject.Injector
-import com.google.inject.Module
+import com.google.inject.*
import com.google.inject.name.*
import org.mockito.*
import javax.inject.Provider
-import kotlin.reflect.KClass
+import kotlin.reflect.*
fun <T : Any> KClass<T>.isProvidedBy(instance: T) = Module { it.bind(this.java).toProvider(Provider<T> { instance }) }
fun <T : Any> KClass<T>.withNameIsProvidedBy(instance: T, name: String) = Module { it.bind(this.java).annotatedWith(Names.named(name)).toProvider(Provider<T> { instance }) }
inline fun <reified T : Any> KClass<T>.isProvidedByMock() = Module { it.bind(this.java).toProvider(Provider<T> { mock() }) }
inline fun <reified T : Any> KClass<T>.isProvidedByDeepMock() = Module { it.bind(this.java).toProvider(Provider<T> { deepMock() }) }
-inline fun <reified T : Any> Injector.getInstance() = getInstance(T::class.java)!!
+inline fun <reified T : Any> Injector.getInstance(annotation: Annotation? = null): T = annotation
+ ?.let { getInstance(Key.get(object : TypeLiteral<T>() {}, it)) }
+ ?: getInstance(Key.get(object : TypeLiteral<T>() {}))
fun <T : Any> supply(javaClass: Class<T>): Source<T> = object : Source<T> {
override fun fromInstance(instance: T) = Module { it.bind(javaClass).toInstance(instance) }
fun `request with valid data creates post`() {
addRequestParameter("text", "test")
val post = createPost()
- whenever(core.createPost(currentSone, Optional.absent(), "test")).thenReturn(post)
+ whenever(core.createPost(currentSone, null, "test")).thenReturn(post)
assertThatJsonIsSuccessful()
assertThat(json["postId"]?.asText(), equalTo("id"))
assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
addRequestParameter("text", "test")
addRequestParameter("recipient", "invalid")
val post = createPost()
- whenever(core.createPost(currentSone, Optional.absent(), "test")).thenReturn(post)
+ whenever(core.createPost(currentSone, null, "test")).thenReturn(post)
assertThatJsonIsSuccessful()
assertThat(json["postId"]?.asText(), equalTo("id"))
assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
val recipient = mock<Sone>().apply { whenever(id).thenReturn("valid") }
addSone(recipient)
val post = createPost("valid")
- whenever(core.createPost(currentSone, Optional.of(recipient), "test")).thenReturn(post)
+ whenever(core.createPost(currentSone, recipient, "test")).thenReturn(post)
assertThatJsonIsSuccessful()
assertThat(json["postId"]?.asText(), equalTo("id"))
assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
addRequestParameter("text", "Link http://freenet.test:8888/KSK@foo is filtered")
addRequestHeader("Host", "freenet.test:8888")
val post = createPost()
- whenever(core.createPost(currentSone, Optional.absent(), "Link KSK@foo is filtered")).thenReturn(post)
+ whenever(core.createPost(currentSone, null, "Link KSK@foo is filtered")).thenReturn(post)
assertThatJsonIsSuccessful()
assertThat(json["postId"]?.asText(), equalTo("id"))
assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
addHttpRequestPart("returnPage", "return.html")
addHttpRequestPart("text", "post text")
verifyRedirect("return.html") {
- verify(core).createPost(currentSone, absent(), "post text")
+ verify(core).createPost(currentSone, null, "post text")
}
}
val sender = mock<Sone>()
addLocalSone("sender-id", sender)
verifyRedirect("return.html") {
- verify(core).createPost(sender, absent(), "post text")
+ verify(core).createPost(sender, null, "post text")
}
}
val recipient = mock<Sone>()
addSone("recipient-id", recipient)
verifyRedirect("return.html") {
- verify(core).createPost(currentSone, recipient.asOptional(), "post text")
+ verify(core).createPost(currentSone, recipient, "post text")
}
}
addHttpRequestPart("text", "post http://localhost:12345/KSK@foo text")
addHttpRequestHeader("Host", "localhost:12345")
verifyRedirect("return.html") {
- verify(core).createPost(currentSone, absent(), "post KSK@foo text")
+ verify(core).createPost(currentSone, null, "post KSK@foo text")
}
}