private val uskManager = mock<USKManager>()
private val sone = mock<Sone>()
private val callbackCaptor: ArgumentCaptor<USKCallback> = forClass(USKCallback::class.java)
- private val image = mock<Image>()
+ private val image: Image = ImageImpl()
private val insertToken: InsertToken
private val bucket = mock<Bucket>()
private val clientGetCallback: ArgumentCaptor<ClientGetCallback> = forClass(ClientGetCallback::class.java)
import net.pterodactylus.sone.core.FreenetInterface.InsertToken
import net.pterodactylus.sone.core.FreenetInterface.InsertTokenSupplier
-import net.pterodactylus.sone.data.Image
import net.pterodactylus.sone.data.TemporaryImage
+import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.test.getInstance
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
class ImageInserterTest {
private val temporaryImage = mock<TemporaryImage>().apply { whenever(id).thenReturn("image-id") }
- private val image = mock<Image>().apply { whenever(id).thenReturn("image-id") }
+ private val image = ImageImpl("image-id")
private val freenetInterface = mock<FreenetInterface>()
private val insertToken = mock<InsertToken>()
private val insertTokenSupplier: InsertTokenSupplier = mock<InsertTokenSupplier>().apply { whenever(apply(any())).thenReturn(insertToken) }
assertThat(memoryDatabase.getPostReply("reply2"), isPostReply("reply2", "post2", 4000L, "reply2"))
assertThat(memoryDatabase.getPostReply("reply3"), isPostReply("reply3", "post1", 5000L, "reply3"))
assertThat(memoryDatabase.getPostReply("reply4"), nullValue())
- assertThat(memoryDatabase.getAlbum("album1"), isAlbum("album1", null, "album1", "album-description1"))
- assertThat(memoryDatabase.getAlbum("album2"), isAlbum("album2", null, "album2", "album-description2"))
+ assertThat(memoryDatabase.getAlbum("album1"), isAlbum("album1", "root", "album1", "album-description1"))
+ assertThat(memoryDatabase.getAlbum("album2"), isAlbum("album2", "root", "album2", "album-description2"))
assertThat(memoryDatabase.getAlbum("album3"), isAlbum("album3", "album1", "album3", "album-description3"))
assertThat(memoryDatabase.getAlbum("album4"), nullValue())
assertThat(memoryDatabase.getImage("image1"), isImage("image1", 1000L, "KSK@image1", "image1", "image-description1", 16, 9))
.setDescription("album-description3")
.update()
firstAlbum.addAlbum(thirdAlbum)
- val rootAlbum = mock<Album>()
- whenever(rootAlbum.id).thenReturn("root")
- whenever(rootAlbum.albums).thenReturn(listOf(firstAlbum, secondAlbum))
+ val rootAlbum = AlbumImpl(sone, "root").also {
+ it.addAlbum(firstAlbum)
+ it.addAlbum(secondAlbum)
+ }
whenever(sone.rootAlbum).thenReturn(rootAlbum)
val firstImage = TestImageBuilder().withId("image1")
.build()
package net.pterodactylus.sone.template
-import net.pterodactylus.sone.data.Album
-import net.pterodactylus.sone.data.Image
-import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.test.whenever
+import net.pterodactylus.sone.data.impl.*
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.nullValue
-import org.junit.Before
import org.junit.Test
/**
class ImageAccessorTest {
private val accessor = ImageAccessor()
- private val album = mock<Album>()
- private val images = listOf(mock<Image>(), mock())
-
- @Before
- fun setupImages() {
- whenever(album.images).thenReturn(images)
- images.forEach {
- whenever(it.album).thenReturn(album)
- }
- }
@Test
fun `accessor returns next image for first image`() {
}
}
+
+private val sone = IdOnlySone("sone")
+private val album = AlbumImpl(sone)
+private val images = listOf(ImageImpl().modify().setSone(sone).update(), ImageImpl().modify().setSone(sone).update()).onEach(album::addImage)
import net.pterodactylus.sone.data.Sone.SoneStatus.idle
import net.pterodactylus.sone.data.Sone.SoneStatus.inserting
import net.pterodactylus.sone.data.Sone.SoneStatus.unknown
+import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.freenet.L10nText
import net.pterodactylus.sone.freenet.wot.Identity
import net.pterodactylus.sone.freenet.wot.OwnIdentity
@Test
fun `accessor returns all images in the correct order`() {
- val images = listOf(mock<Image>(), mock(), mock(), mock(), mock())
- val firstAlbum = createAlbum(listOf(), listOf(images[0], images[3]))
- val secondAlbum = createAlbum(listOf(), listOf(images[1], images[4], images[2]))
- val rootAlbum = createAlbum(listOf(firstAlbum, secondAlbum), listOf())
+ val images = (0 until 5).map { ImageImpl().modify().setSone(sone).update() }
+ val firstAlbum = createAlbum(emptyList(), listOf(images[0], images[3]))
+ val secondAlbum = createAlbum(emptyList(), listOf(images[1], images[4], images[2]))
+ val rootAlbum = createAlbum(listOf(firstAlbum, secondAlbum), emptyList())
whenever(sone.rootAlbum).thenReturn(rootAlbum)
assertAccessorReturnValueMatches("allImages", contains(images[0], images[3], images[1], images[4], images[2]))
}
private fun createAlbum(albums: List<Album>, images: List<Image>) =
- mock<Album>().apply {
- whenever(this.albums).thenReturn(albums)
- whenever(this.images).thenReturn(images)
+ AlbumImpl(sone).also {
+ albums.forEach(it::addAlbum)
+ images.forEach(it::addImage)
}
@Test
fun `accessor returns all albums in the correct order`() {
- val albums = listOf(mock<Album>(), mock(), mock(), mock(), mock())
- val rootAlbum = createAlbum(albums, listOf())
+ val albums = (0 until 5).map { AlbumImpl(sone) }
+ val rootAlbum = createAlbum(albums, emptyList())
whenever(sone.rootAlbum).thenReturn(rootAlbum)
assertAccessorReturnValueMatches("albums", contains(*albums.toTypedArray()))
}
package net.pterodactylus.sone.web.ajax
-import net.pterodactylus.sone.data.Album
-import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.data.impl.AlbumImpl
-import net.pterodactylus.sone.test.deepMock
import net.pterodactylus.sone.test.getInstance
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
class EditAlbumAjaxPageTest : JsonPageTest("editAlbum.ajax", pageSupplier = ::EditAlbumAjaxPage) {
private val sone = mock<Sone>()
- private val localSone = mock<Sone>().apply { whenever(isLocal).thenReturn(true) }
- private val album = mock<Album>().apply { whenever(id).thenReturn("album-id") }
+ private val album = AlbumImpl(sone, "album-id")
@Test
fun `request without album results in invalid-album-id`() {
@Test
fun `request with non-local album results in not-authorized`() {
- whenever(album.sone).thenReturn(sone)
addAlbum(album)
addRequestParameter("album", "album-id")
assertThatJsonFailed("not-authorized")
@Test
fun `request with moveLeft moves album to the left`() {
- whenever(album.sone).thenReturn(localSone)
- val swappedAlbum = mock<Album>().apply { whenever(id).thenReturn("swapped") }
- val parentAlbum = mock<Album>()
- whenever(parentAlbum.moveAlbumUp(album)).thenReturn(swappedAlbum)
- whenever(album.parent).thenReturn(parentAlbum)
+ setupLocalSone()
+ AlbumImpl(sone).also {
+ it.addAlbum(AlbumImpl(sone, "swapped"))
+ it.addAlbum(album)
+ }
addAlbum(album)
addRequestParameter("album", "album-id")
addRequestParameter("moveLeft", "true")
@Test
fun `request with moveRight moves album to the right`() {
- whenever(album.sone).thenReturn(localSone)
- val swappedAlbum = mock<Album>().apply { whenever(id).thenReturn("swapped") }
- val parentAlbum = mock<Album>()
- whenever(parentAlbum.moveAlbumDown(album)).thenReturn(swappedAlbum)
- whenever(album.parent).thenReturn(parentAlbum)
+ setupLocalSone()
+ AlbumImpl(sone).also {
+ it.addAlbum(album)
+ it.addAlbum(AlbumImpl(sone, "swapped"))
+ }
addAlbum(album)
addRequestParameter("album", "album-id")
addRequestParameter("moveRight", "true")
@Test
fun `request with missing title results in invalid-title`() {
- whenever(album.sone).thenReturn(localSone)
- whenever(album.modify()).thenReturn(deepMock())
- whenever(album.modify().setTitle("")).thenThrow(AlbumTitleMustNotBeEmpty::class.java)
+ setupLocalSone()
addAlbum(album)
addRequestParameter("album", "album-id")
assertThatJsonFailed("invalid-album-title")
assertThat(baseInjector.getInstance<EditAlbumAjaxPage>(), notNullValue())
}
+ private fun setupLocalSone() {
+ whenever(sone.isLocal).thenReturn(true)
+ }
+
}
import net.pterodactylus.sone.data.Album
import net.pterodactylus.sone.data.Image
import net.pterodactylus.sone.data.Sone
-import net.pterodactylus.sone.data.impl.ImageImpl
+import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.template.ParserFilter
import net.pterodactylus.sone.template.RenderFilter
import net.pterodactylus.sone.template.ShortenFilter
@Test
fun `request with non-local image results in not-authorized`() {
- val image = mock<Image>()
val sone = mock<Sone>()
- whenever(image.sone).thenReturn(sone)
+ val image = ImageImpl().modify().setSone(sone).update()
addImage(image, "image-id")
addRequestParameter("image", "image-id")
assertThatJsonFailed("not-authorized")
@Test
fun `moving an image to the left returns the correct values`() {
- val image = mock<Image>().apply { whenever(id).thenReturn("image-id") }
val sone = mock<Sone>().apply { whenever(isLocal).thenReturn(true) }
- whenever(image.sone).thenReturn(sone)
- val swapped = mock<Image>().apply { whenever(id).thenReturn("swapped") }
- val album = mock<Album>()
- whenever(album.moveImageUp(image)).thenReturn(swapped)
- whenever(image.album).thenReturn(album)
+ val image = ImageImpl("image-id").modify().setSone(sone).update()
+ AlbumImpl(sone).also {
+ it.addImage(ImageImpl("swapped").modify().setSone(sone).update())
+ it.addImage(image)
+ }
addImage(image)
addRequestParameter("image", "image-id")
addRequestParameter("moveLeft", "true")
@Test
fun `moving an image to the right returns the correct values`() {
- val image = mock<Image>().apply { whenever(id).thenReturn("image-id") }
val sone = mock<Sone>().apply { whenever(isLocal).thenReturn(true) }
- whenever(image.sone).thenReturn(sone)
- val swapped = mock<Image>().apply { whenever(id).thenReturn("swapped") }
- val album = mock<Album>()
- whenever(album.moveImageDown(image)).thenReturn(swapped)
- whenever(image.album).thenReturn(album)
+ val image = ImageImpl("image-id").modify().setSone(sone).update()
+ AlbumImpl(sone).also {
+ it.addImage(image)
+ it.addImage(ImageImpl("swapped").modify().setSone(sone).update())
+ }
addImage(image)
addRequestParameter("image", "image-id")
addRequestParameter("moveRight", "true")
@Test
fun `request with empty title results in invalid-image-title`() {
- val image = mock<Image>().apply { whenever(id).thenReturn("image-id") }
val sone = mock<Sone>().apply { whenever(isLocal).thenReturn(true) }
- whenever(image.sone).thenReturn(sone)
+ val image = ImageImpl("image-id").modify().setSone(sone).update()
addImage(image)
addRequestParameter("image", "image-id")
assertThatJsonFailed("invalid-image-title")
package net.pterodactylus.sone.web.pages
-import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.test.*
import net.pterodactylus.sone.web.*
import net.pterodactylus.sone.web.page.*
*/
class DeleteAlbumPageTest : WebPageTest(::DeleteAlbumPage) {
- private val sone = mock<Sone>()
- private val album = mock<Album>()
- private val parentAlbum = mock<Album>()
+ private val album = AlbumImpl(currentSone, "album-id")
+ private val parentAlbum = AlbumImpl(currentSone, "parent-id").also { it.addAlbum(album) }
@Before
fun setupAlbums() {
- whenever(sone.id).thenReturn("sone-id")
- whenever(sone.isLocal).thenReturn(true)
- whenever(parentAlbum.id).thenReturn("parent-id")
- whenever(parentAlbum.isRoot).thenReturn(true)
- whenever(album.id).thenReturn("album-id")
- whenever(album.sone).thenReturn(sone)
- whenever(album.parent).thenReturn(parentAlbum)
- whenever(sone.rootAlbum).thenReturn(parentAlbum)
+ whenever(currentSone.id).thenReturn("sone-id")
+ whenever(currentSone.isLocal).thenReturn(true)
+ whenever(currentSone.rootAlbum).thenReturn(parentAlbum)
}
@Test
@Test
fun `get request with valid album ID sets album in template context`() {
- val album = mock<Album>()
addAlbum("album-id", album)
addHttpRequestParameter("album", "album-id")
page.processTemplate(freenetRequest, templateContext)
@Test
fun `post request redirects to no permissions page if album is not local`() {
setMethod(POST)
- whenever(sone.isLocal).thenReturn(false)
+ whenever(currentSone.isLocal).thenReturn(false)
addAlbum("album-id", album)
addHttpRequestPart("album", "album-id")
verifyRedirect("noPermission.html")
@Test
fun `album is deleted and page redirects to album if parent album is not root album`() {
setMethod(POST)
- whenever(parentAlbum.isRoot).thenReturn(false)
- whenever(sone.rootAlbum).thenReturn(mock())
- addAlbum("album-id", album)
- addHttpRequestPart("album", "album-id")
- verifyRedirect("imageBrowser.html?album=parent-id") {
- verify(core).deleteAlbum(album)
+ val subAlbum = AlbumImpl(currentSone, "sub-album-id")
+ album.addAlbum(subAlbum)
+ addAlbum("sub-album-id", subAlbum)
+ addHttpRequestPart("album", "sub-album-id")
+ verifyRedirect("imageBrowser.html?album=album-id") {
+ verify(core).deleteAlbum(subAlbum)
}
}
package net.pterodactylus.sone.web.pages
import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.test.*
import net.pterodactylus.sone.web.*
import net.pterodactylus.sone.web.page.*
*/
class DeleteImagePageTest : WebPageTest(::DeleteImagePage) {
- private val image = mock<Image>()
private val sone = mock<Sone>()
+ private val image = ImageImpl("image-id").modify().setSone(sone).update()!!
@Before
fun setupImage() {
- val album = mock<Album>()
- whenever(album.id).thenReturn("album-id")
- whenever(image.id).thenReturn("image-id")
- whenever(image.sone).thenReturn(sone)
- whenever(image.album).thenReturn(album)
+ AlbumImpl(sone, "album-id").also { it.addImage(image) }
whenever(sone.isLocal).thenReturn(true)
}
package net.pterodactylus.sone.web.pages
-import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.data.Album.*
-import net.pterodactylus.sone.data.Album.Modifier.*
+import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.test.*
import net.pterodactylus.sone.web.*
import net.pterodactylus.util.web.Method.*
*/
class EditAlbumPageTest : WebPageTest(::EditAlbumPage) {
- private val album = mock<Album>()
- private val parentAlbum = mock<Album>()
- private val modifier = mockBuilder<Modifier>()
- private val sone = mock<Sone>()
+ private val album = AlbumImpl(currentSone, "album-id")
+ private val parentAlbum = AlbumImpl(currentSone, "parent-id").also {
+ it.addAlbum(AlbumImpl(currentSone))
+ it.addAlbum(album)
+ it.addAlbum(AlbumImpl(currentSone))
+ }
@Before
fun setup() {
- whenever(album.id).thenReturn("album-id")
- whenever(album.sone).thenReturn(sone)
- whenever(album.parent).thenReturn(parentAlbum)
- whenever(album.modify()).thenReturn(modifier)
- whenever(modifier.update()).thenReturn(album)
- whenever(parentAlbum.id).thenReturn("parent-id")
- whenever(sone.isLocal).thenReturn(true)
+ whenever(currentSone.isLocal).thenReturn(true)
addHttpRequestHeader("Host", "www.te.st")
}
@Test
fun `post request with album of non-local sone redirects to no permissions page`() {
setMethod(POST)
- whenever(sone.isLocal).thenReturn(false)
+ whenever(currentSone.isLocal).thenReturn(false)
addAlbum("album-id", album)
addHttpRequestPart("album", "album-id")
verifyRedirect("noPermission.html")
addHttpRequestPart("album", "album-id")
addHttpRequestPart("moveLeft", "true")
verifyRedirect("imageBrowser.html?album=parent-id") {
- verify(parentAlbum).moveAlbumUp(album)
+ assertThat(parentAlbum.albums.indexOf(album), equalTo(0))
verify(core).touchConfiguration()
}
}
addHttpRequestPart("album", "album-id")
addHttpRequestPart("moveRight", "true")
verifyRedirect("imageBrowser.html?album=parent-id") {
- verify(parentAlbum).moveAlbumDown(album)
+ assertThat(parentAlbum.albums.indexOf(album), equalTo(2))
verify(core).touchConfiguration()
}
}
setMethod(POST)
addAlbum("album-id", album)
addHttpRequestPart("album", "album-id")
- whenever(modifier.setTitle("")).thenThrow(AlbumTitleMustNotBeEmpty())
verifyRedirect("emptyAlbumTitle.html")
}
addHttpRequestPart("title", "title")
addHttpRequestPart("description", "description")
verifyRedirect("imageBrowser.html?album=album-id") {
- verify(modifier).setTitle("title")
- verify(modifier).setDescription("description")
- verify(modifier).update()
+ assertThat(album.title, equalTo("title"))
+ assertThat(album.description, equalTo("description"))
verify(core).touchConfiguration()
}
}
package net.pterodactylus.sone.web.pages
import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.data.Image.*
-import net.pterodactylus.sone.data.Image.Modifier.*
+import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.test.*
import net.pterodactylus.sone.web.*
import net.pterodactylus.util.web.Method.*
*/
class EditImagePageTest : WebPageTest(::EditImagePage) {
- private val image = mock<Image>()
- private val modifier = mockBuilder<Modifier>()
private val sone = mock<Sone>()
- private val album = mock<Album>()
+ private val image = ImageImpl("image-id").modify().setSone(sone).update()!!
+ private val album = AlbumImpl(sone, "album-id").also {
+ it.addImage(ImageImpl("1").modify().setSone(sone).update())
+ it.addImage(image)
+ it.addImage(ImageImpl("2").modify().setSone(sone).update())
+ }
@Before
fun setupImage() {
whenever(sone.isLocal).thenReturn(true)
- whenever(album.id).thenReturn("album-id")
- whenever(modifier.update()).thenReturn(image)
- whenever(image.sone).thenReturn(sone)
- whenever(image.album).thenReturn(album)
- whenever(image.modify()).thenReturn(modifier)
}
@Test
addHttpRequestPart("returnPage", "return.html")
addHttpRequestPart("moveLeft", "true")
verifyRedirect("return.html") {
- verify(album).moveImageUp(image)
+ assertThat(album.images.indexOf(image), equalTo(0))
verify(core).touchConfiguration()
}
}
addHttpRequestPart("returnPage", "return.html")
addHttpRequestPart("moveRight", "true")
verifyRedirect("return.html") {
- verify(album).moveImageDown(image)
+ assertThat(album.images.indexOf(image), equalTo(2))
verify(core).touchConfiguration()
}
}
addHttpRequestPart("image", "image-id")
addHttpRequestPart("returnPage", "return.html")
addHttpRequestPart("title", " ")
- whenever(modifier.update()).doThrow<ImageTitleMustNotBeEmpty>()
verifyRedirect("emptyImageTitle.html") {
verify(core, never()).touchConfiguration()
}
addHttpRequestPart("title", "Title")
addHttpRequestPart("description", "Description")
verifyRedirect("return.html") {
- verify(modifier).setTitle("Title")
- verify(modifier).setDescription("Description")
- verify(modifier).update()
+ assertThat(image.title, equalTo("Title"))
+ assertThat(image.description, equalTo("Description"))
verify(core).touchConfiguration()
}
}
addHttpRequestHeader("Host", "www.te.st")
addHttpRequestPart("description", "Get http://www.te.st/KSK@GPL.txt")
verifyRedirect("return.html") {
- verify(modifier).setTitle("Title")
- verify(modifier).setDescription("Get KSK@GPL.txt")
- verify(modifier).update()
+ assertThat(image.title, equalTo("Title"))
+ assertThat(image.description, equalTo("Get KSK@GPL.txt"))
verify(core).touchConfiguration()
}
}
package net.pterodactylus.sone.web.pages
import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.test.*
import net.pterodactylus.sone.web.*
import net.pterodactylus.sone.web.page.*
@Before
fun setupProfile() {
- val avatar = mock<Image>()
- whenever(avatar.id).thenReturn("image-id")
- whenever(avatar.sone).thenReturn(currentSone)
profile.firstName = "First"
profile.middleName = "Middle"
profile.lastName = "Last"
profile.birthDay = 31
profile.birthMonth = 12
profile.birthYear = 1999
- profile.setAvatar(avatar)
+ profile.setAvatar(ImageImpl("image-id").modify().setSone(currentSone).update())
whenever(currentSone.profile).thenReturn(profile)
}
@Test
fun `post request with new avatar ID and save profile saves the profile and redirects back to profile edit page`() {
- val newAvatar = mock<Image>()
- whenever(newAvatar.sone).thenReturn(currentSone)
- whenever(newAvatar.id).thenReturn("avatar-id")
+ val newAvatar = ImageImpl("avatar-id").modify().setSone(currentSone).update()
addImage("avatar-id", newAvatar)
verifySingleFieldCanBeChanged("avatarId", "avatar-id") { profile.avatar }
}
@Test
fun `get request with album sets album and page in template context`() {
- val album = mock<Album>()
+ val album = AlbumImpl(currentSone, "album-id")
addAlbum("album-id", album)
addHttpRequestParameter("album", "album-id")
addHttpRequestParameter("page", "5")
@Test
fun `get request with image sets image in template context`() {
- val image = mock<Image>()
+ val image = ImageImpl()
addImage("image-id", image)
addHttpRequestParameter("image", "image-id")
verifyNoRedirect {
package net.pterodactylus.sone.web.pages
import net.pterodactylus.sone.data.*
+import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.freenet.wot.*
import net.pterodactylus.sone.test.*
import net.pterodactylus.sone.utils.*
whenever(this.time).thenReturn(time)
whenever(this.posts).thenReturn((0..(posts - 1)).map { mock<Post>() })
whenever(this.replies).thenReturn((0..(replies - 1)).map { mock<PostReply>() }.toSet())
- val album = mock<Album>()
- whenever(album.images).thenReturn(((0..(images - 1)).map { mock<Image>() }))
- val rootAlbum = mock<Album>().apply {
- whenever(albums).thenReturn(listOf(album))
+ val album = AlbumImpl(this)
+ repeat(images) {
+ ImageImpl().modify().setSone(this).update()
+ .also(album::addImage)
}
+ val rootAlbum = AlbumImpl(this).also { it.addAlbum(album) }
whenever(this.rootAlbum).thenReturn(rootAlbum)
whenever(this.profile).thenReturn(mock())
whenever(id).thenReturn(name.toLowerCase())
package net.pterodactylus.sone.web.pages
import net.pterodactylus.sone.data.*
-import net.pterodactylus.sone.data.Image.*
+import net.pterodactylus.sone.data.impl.*
import net.pterodactylus.sone.test.getInstance
import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.test.mockBuilder
import net.pterodactylus.sone.test.whenever
import net.pterodactylus.sone.web.*
import net.pterodactylus.sone.web.page.*
*/
class UploadImagePageTest : WebPageTest(::UploadImagePage) {
- private val parentAlbum = mock<Album>().apply {
- whenever(id).thenReturn("parent-id")
- whenever(sone).thenReturn(currentSone)
- }
+ private val parentAlbum = AlbumImpl(currentSone, "parent-id")
@Test
fun `page returns correct path`() {
@Test
fun `post request with parent that is not the current sone results in no permission error page`() {
setMethod(POST)
+ val remoteAlbum = AlbumImpl(mock(), "parent-id")
+ addAlbum("parent-id", remoteAlbum)
addHttpRequestPart("parent", "parent-id")
- whenever(parentAlbum.sone).thenReturn(mock())
- addAlbum("parent-id", parentAlbum)
verifyRedirect("noPermission.html")
}
addHttpRequestHeader("Host", "localhost:8888")
addUploadedFile("image", "upload-image-value-image.png", "image/png", "upload-image-value-image.png")
val temporaryImage = TemporaryImage("temp-image")
- val imageModifier = mockBuilder<Modifier>()
- val image = mock<Image>().apply {
- whenever(modify()).thenReturn(imageModifier)
- }
+ val image = ImageImpl()
whenever(core.createTemporaryImage(eq("image/png"), any())).thenReturn(temporaryImage)
whenever(core.createImage(currentSone, parentAlbum, temporaryImage)).thenReturn(image)
verifyRedirect("imageBrowser.html?album=parent-id") {
- verify(image).modify()
- verify(imageModifier).setWidth(2)
- verify(imageModifier).setHeight(1)
- verify(imageModifier).setTitle("Title")
- verify(imageModifier).setDescription("Description @ KSK@foo")
- verify(imageModifier).update()
+ assertThat(image.width, equalTo(2))
+ assertThat(image.height, equalTo(1))
+ assertThat(image.title, equalTo("Title"))
+ assertThat(image.description, equalTo("Description @ KSK@foo"))
}
}