import com.google.common.base.Optional.of
import net.pterodactylus.sone.core.Core
import net.pterodactylus.sone.data.Post
-import net.pterodactylus.sone.freenet.fcp.FcpException
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
import org.hamcrest.MatcherAssert.assertThat
fun `request without text results in fcp exception`() {
parameters.putSingle("Sone", "LocalSoneId")
whenever(core.getSone("LocalSoneId")).thenReturn(Optional.of(localSone))
- expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ executeCommandAndExpectFcpException()
}
@Test
whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
val post = mock<Post>().apply { whenever(id).thenReturn("PostId") }
whenever(core.createPost(localSone, absent(), "Test")).thenReturn(post)
- val response = command.execute(parameters, null, null)
+ val response = command.execute(parameters)
assertThat(response.replyParameters.get("Message"), equalTo("PostCreated"))
assertThat(response.replyParameters.get("Post"), equalTo("PostId"))
}
parameters.putSingle("Text", "Test")
parameters.putSingle("Recipient", "InvalidSoneId")
whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
- expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ executeCommandAndExpectFcpException()
}
@Test
parameters.putSingle("Text", "Test")
parameters.putSingle("Recipient", "LocalSoneId")
whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
- val response = command.execute(parameters, null, null)
+ val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("Error"))
assertThat(response.replyParameters["ErrorMessage"], notNullValue())
}
whenever(core.getSone("RemoteSoneId")).thenReturn(of(remoteSone))
val post = mock<Post>().apply { whenever(id).thenReturn("PostId") }
whenever(core.createPost(localSone, of(remoteSone), "Test")).thenReturn(post)
- val response = command.execute(parameters, null, null)
+ val response = command.execute(parameters)
assertThat(response.replyParameters.get("Message"), equalTo("PostCreated"))
assertThat(response.replyParameters.get("Post"), equalTo("PostId"))
}