X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FEditProfilePageTest.kt;h=0bdff6992f022eb80a057850db23d4bac0cf82c0;hp=333d9852905c3e648fe3f00d270dec22a43a1ee7;hb=a9c1c1770651720ec3b271464a4b490ea4a1334f;hpb=7eac5c60bdb241d7b98e548cf974d41e22af1b5c diff --git a/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt index 333d985..0bdff69 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/EditProfilePageTest.kt @@ -26,6 +26,8 @@ class EditProfilePageTest : WebPageTest() { private val firstField = profile.addField("First Field") private val secondField = profile.addField("Second Field") + override fun getPage() = page + @Before fun setupProfile() { val avatar = mock() @@ -73,10 +75,7 @@ class EditProfilePageTest : WebPageTest() { request("", POST) addHttpRequestParameter("save-profile", "true") addHttpRequestParameter(fieldName, newValue.toString()) - expectedException.expect(WebTestUtils.redirectsTo("editProfile.html")) - try { - page.handleRequest(freenetRequest, templateContext) - } finally { + verifyRedirect("editProfile.html") { verify(core).touchConfiguration() assertThat(fieldAccessor(), equalTo(expectedValue)) } @@ -153,10 +152,7 @@ class EditProfilePageTest : WebPageTest() { request("", POST) addHttpRequestParameter("add-field", "true") addHttpRequestParameter("field-name", "new-field") - expectedException.expect(WebTestUtils.redirectsTo("editProfile.html#profile-fields")) - try { - page.handleRequest(freenetRequest, templateContext) - } finally { + verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.getFieldByName("new-field"), notNullValue()) verify(currentSone).profile = profile verify(core).touchConfiguration() @@ -167,18 +163,14 @@ class EditProfilePageTest : WebPageTest() { fun `deleting a field redirects to delete field page`() { request("", POST) addHttpRequestParameter("delete-field-${firstField.id}", "true") - expectedException.expect(WebTestUtils.redirectsTo("deleteProfileField.html?field=${firstField.id}")) - page.handleRequest(freenetRequest, templateContext) + verifyRedirect("deleteProfileField.html?field=${firstField.id}") } @Test fun `moving a field up moves the field up and redirects to the edit profile page`() { request("", POST) addHttpRequestParameter("move-up-field-${secondField.id}", "true") - expectedException.expect(WebTestUtils.redirectsTo("editProfile.html#profile-fields")) - try { - page.handleRequest(freenetRequest, templateContext) - } finally { + verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.fields, contains(secondField, firstField)) verify(currentSone).profile = profile } @@ -188,18 +180,14 @@ class EditProfilePageTest : WebPageTest() { fun `moving an invalid field up redirects to the invalid page`() { request("", POST) addHttpRequestParameter("move-up-field-foo", "true") - expectedException.expect(WebTestUtils.redirectsTo("invalid.html")) - page.handleRequest(freenetRequest, templateContext) + verifyRedirect("invalid.html") } @Test fun `moving a field down moves the field down and redirects to the edit profile page`() { request("", POST) addHttpRequestParameter("move-down-field-${firstField.id}", "true") - expectedException.expect(WebTestUtils.redirectsTo("editProfile.html#profile-fields")) - try { - page.handleRequest(freenetRequest, templateContext) - } finally { + verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.fields, contains(secondField, firstField)) verify(currentSone).profile = profile } @@ -209,16 +197,14 @@ class EditProfilePageTest : WebPageTest() { fun `moving an invalid field down redirects to the invalid page`() { request("", POST) addHttpRequestParameter("move-down-field-foo", "true") - expectedException.expect(WebTestUtils.redirectsTo("invalid.html")) - page.handleRequest(freenetRequest, templateContext) + verifyRedirect("invalid.html") } @Test fun `editing a field redirects to the edit profile page`() { request("", POST) addHttpRequestParameter("edit-field-${firstField.id}", "true") - expectedException.expect(WebTestUtils.redirectsTo("editProfileField.html?field=${firstField.id}")) - page.handleRequest(freenetRequest, templateContext) + verifyRedirect("editProfileField.html?field=${firstField.id}") } }