🔀 Merge branch 'release/v82'
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / EditProfilePageTest.kt
index dce4ee5..ac909ea 100644 (file)
@@ -1,6 +1,7 @@
 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.*
@@ -13,7 +14,7 @@ import org.mockito.Mockito.*
 /**
  * Unit test for [EditProfilePage].
  */
-class EditProfilePageTest: WebPageTest(::EditProfilePage) {
+class EditProfilePageTest : WebPageTest(::EditProfilePage) {
 
        private val profile = Profile(currentSone)
        private val firstField = profile.addField("First Field")
@@ -21,32 +22,29 @@ class EditProfilePageTest: WebPageTest(::EditProfilePage) {
 
        @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 `page returns correct path`() {
-           assertThat(page.path, equalTo("editProfile.html"))
+               assertThat(page.path, equalTo("editProfile.html"))
        }
 
        @Test
        fun `page requires login`() {
-           assertThat(page.requiresLogin(), equalTo(true))
+               assertThat(page.requiresLogin(), equalTo(true))
        }
 
        @Test
        fun `page returns correct title`() {
-           whenever(l10n.getString("Page.EditProfile.Title")).thenReturn("edit profile page title")
+               addTranslation("Page.EditProfile.Title", "edit profile page title")
                assertThat(page.getPageTitle(soneRequest), equalTo("edit profile page title"))
        }
 
@@ -120,9 +118,7 @@ class EditProfilePageTest: WebPageTest(::EditProfilePage) {
 
        @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 }
        }
@@ -216,17 +212,17 @@ class EditProfilePageTest: WebPageTest(::EditProfilePage) {
 
        @Test
        fun `page can be created by dependency injection`() {
-           assertThat(baseInjector.getInstance<EditProfilePage>(), notNullValue())
+               assertThat(baseInjector.getInstance<EditProfilePage>(), notNullValue())
        }
 
        @Test
        fun `page is annotated with correct menuname`() {
-           assertThat(page.menuName, equalTo("EditProfile"))
+               assertThat(page.menuName, equalTo("EditProfile"))
        }
 
        @Test
        fun `page is annotated with correct template path`() {
-           assertThat(page.templatePath, equalTo("/templates/editProfile.html"))
+               assertThat(page.templatePath, equalTo("/templates/editProfile.html"))
        }
 
 }