http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/TagTesterTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/TagTesterTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/TagTesterTest.java index d4fe36e..1f040f1 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/TagTesterTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/TagTesterTest.java @@ -16,21 +16,22 @@ */ package org.apache.wicket.util.tester; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test of TagTester */ -public class TagTesterTest extends Assert +class TagTesterTest { /** Mock markup 1 */ private static final String MARKUP_1 = "<p id=\"test\" class=\"class1\"><span class=\"class2\" id=\"test2\">mock</span></p>"; @@ -45,7 +46,7 @@ public class TagTesterTest extends Assert * WICKET-6278 */ @Test - public void tagNoRequiredClose() { + void tagNoRequiredClose() { TagTester tester = TagTester.createTagByAttribute(NON_CLOSED_INPUT, "wicket:id", "p"); assertEquals("<input wicket:id=\"wicketId\" type=\"text\">", tester.getValue()); @@ -55,38 +56,38 @@ public class TagTesterTest extends Assert * https://issues.apache.org/jira/browse/WICKET-5874 */ @Test - public void getTagTesterForNonClosedTag() + void getTagTesterForNonClosedTag() { TagTester tester = TagTester.createTagByAttribute(NON_CLOSED_INPUT, "wicket:id", "wicketId"); - assertThat(tester, is(notNullValue())); + assertNotNull(tester); String type = tester.getAttribute("type"); - assertThat(type, is(equalTo("text"))); + assertEquals("text", type); - assertThat(tester.getValue(), is(nullValue())); + assertNull(tester.getValue()); } /** * https://issues.apache.org/jira/browse/WICKET-6172 */ @Test - public void getTagTestersForNonClosedTag() + void getTagTestersForNonClosedTag() { List<TagTester> testers = TagTester.createTagsByAttribute(NON_CLOSED_INPUT, "wicket:id", "wicketId", false); - assertThat(testers, is(notNullValue())); - assertThat(testers.size(), is(1)); + assertNotNull(testers); + assertEquals(1, testers.size()); String type = testers.get(0).getAttribute("type"); - assertThat(type, is(equalTo("text"))); + assertEquals("text", type); - assertThat(testers.get(0).getValue(), is(nullValue())); + assertNull(testers.get(0).getValue()); } /** * https://issues.apache.org/jira/browse/WICKET-5137 */ @Test - public void getTagInAjaxResponse() + void getTagInAjaxResponse() { TagTester tester = TagTester.createTagByAttribute(AJAX_MARKUP_1, "id", "compId"); assertNotNull(tester); @@ -99,7 +100,7 @@ public class TagTesterTest extends Assert * Test the static factory method */ @Test - public void createTagByAttribute() + void createTagByAttribute() { TagTester tester = TagTester.createTagByAttribute(null, null, null); assertNull(tester); @@ -118,7 +119,7 @@ public class TagTesterTest extends Assert * Test that getName returns the correct tag name. */ @Test - public void getName() + void getName() { TagTester tester = TagTester.createTagByAttribute(MARKUP_1, "id", "test"); assertNotNull(tester); @@ -138,7 +139,7 @@ public class TagTesterTest extends Assert * It also tests that the order of the attributes doesn't matter. */ @Test - public void hasAttribute() + void hasAttribute() { TagTester tester = TagTester.createTagByAttribute(MARKUP_1, "id", "test"); assertNotNull(tester); @@ -158,7 +159,7 @@ public class TagTesterTest extends Assert * If the attribute doesn't exist on the tag, the method should return null. */ @Test - public void getAttribute() + void getAttribute() { TagTester tester = TagTester.createTagByAttribute(MARKUP_1, "id", "test"); assertNotNull(tester); @@ -195,7 +196,7 @@ public class TagTesterTest extends Assert * value. It should not be case in-sensitive and not trim the attribute value. */ @Test - public void getAttributeContains() + void getAttributeContains() { TagTester tester = TagTester.createTagByAttribute(MARKUP_1, "id", "test"); assertNotNull(tester); @@ -217,7 +218,7 @@ public class TagTesterTest extends Assert * exactly the same as the parameter. */ @Test - public void getAttributeIs() + void getAttributeIs() { TagTester tester = TagTester.createTagByAttribute(MARKUP_1, "id", "test"); assertNotNull(tester); @@ -237,7 +238,7 @@ public class TagTesterTest extends Assert * be contained must only be at the end. */ @Test - public void getAttributeEndsWith() + void getAttributeEndsWith() { TagTester tester = TagTester.createTagByAttribute(MARKUP_1, "id", "test"); assertNotNull(tester); @@ -257,7 +258,7 @@ public class TagTesterTest extends Assert * */ @Test - public void hasChildTag() + void hasChildTag() { TagTester tester = TagTester.createTagByAttribute(MARKUP_1, "id", "test"); @@ -303,7 +304,7 @@ public class TagTesterTest extends Assert } @Test - public void getChildByTagName() + void getChildByTagName() { TagTester tester = TagTester.createTagByAttribute( "<div id=\"id\">" + @@ -313,19 +314,19 @@ public class TagTesterTest extends Assert "</label>" + "</div>" + "</div>", "id", "id"); - assertThat(tester.getChild("DIV"), is(notNullValue())); // case-insensitive + assertNotNull(tester.getChild("DIV")); // case-insensitive TagTester divClassRadioTagTester = tester.getChild("div"); - assertThat(divClassRadioTagTester, is(notNullValue())); + assertNotNull(divClassRadioTagTester); TagTester labelTagTester = divClassRadioTagTester.getChild("label"); String labelMarkup = labelTagTester.getValue(); - assertThat(labelMarkup, endsWith(" One")); + assertThat(labelMarkup).endsWith(" One"); } /** * Test getMarkup returns the open-tag + content + close-tag */ @Test - public void getMarkup() + void getMarkup() { TagTester tagTester = TagTester.createTagByAttribute(MARKUP_1, "id", "test2"); @@ -336,7 +337,7 @@ public class TagTesterTest extends Assert * Test getValue returns the data between the open and close tag. */ @Test - public void getValue() + void getValue() { TagTester tagTester = TagTester.createTagByAttribute(MARKUP_1, "id", "test2"); assertEquals("mock", tagTester.getValue()); @@ -350,7 +351,7 @@ public class TagTesterTest extends Assert * https://issues.apache.org/jira/browse/WICKET-6173 */ @Test - public void valueFromTagsByAttribute() + void valueFromTagsByAttribute() { TagTester tagTester = TagTester.createTagByAttribute(MARKUP_1, "id", "test2"); assertEquals("mock", tagTester.getValue()); @@ -398,7 +399,7 @@ public class TagTesterTest extends Assert * WICKET-6220 */ @Test - public void testOpenAndClose() { + void testOpenAndClose() { List<TagTester> tags = TagTester.createTagsByAttribute(MARKUP, "wicket:id", "item", false); assertEquals(2, tags.size()); assertEquals("li", tags.get(0).getName()); @@ -413,7 +414,7 @@ public class TagTesterTest extends Assert * WICKET-6220 */ @Test - public void testWrongHtmlStructure() { + void testWrongHtmlStructure() { List<TagTester> tags = TagTester.createTagsByAttribute(WRONG_MARKUP, "wicket:id", "p", false); assertEquals(1, tags.size()); assertEquals("span", tags.get(0).getName()); @@ -425,7 +426,7 @@ public class TagTesterTest extends Assert * WICKET-6220 */ @Test - public void testOpenOrClose() { + void testOpenOrClose() { List<TagTester> tags = TagTester.createTagsByAttribute(MARKUP, "wicket:id", "p", false); assertEquals(2, tags.size()); assertEquals("p", tags.get(0).getName()); @@ -440,7 +441,7 @@ public class TagTesterTest extends Assert * WICKET-6220 */ @Test - public void testOpen() { + void testOpen() { List<TagTester> tags = TagTester.createTagsByAttribute(MARKUP, "wicket:id", "img", false); assertEquals(2, tags.size()); assertEquals("img", tags.get(0).getName()); @@ -455,7 +456,7 @@ public class TagTesterTest extends Assert * WICKET-6220 */ @Test - public void testOpenClose() { + void testOpenClose() { List<TagTester> tags = TagTester.createTagsByAttribute(MARKUP, "wicket:id", "hr", false); assertEquals(2, tags.size()); assertEquals("hr", tags.get(0).getName());
http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterClickExternalLinkTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterClickExternalLinkTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterClickExternalLinkTest.java index 7cab37e..5789165 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterClickExternalLinkTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterClickExternalLinkTest.java @@ -18,15 +18,15 @@ package org.apache.wicket.util.tester; import org.apache.wicket.MockPageWithLink; import org.apache.wicket.markup.html.link.ExternalLink; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test for https://issues.apache.org/jira/browse/WICKET-5840 */ -public class WicketTesterClickExternalLinkTest extends WicketTestCase +class WicketTesterClickExternalLinkTest extends WicketTestCase { @Test - public void clickExternalLink() + void clickExternalLink() { MockPageWithLink page = new MockPageWithLink(); String href = "http://wicket.apache.org"; http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java index c99b1e6..c4aa53c 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterCookieTest.java @@ -16,13 +16,17 @@ */ package org.apache.wicket.util.tester; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; - import javax.servlet.http.Cookie; import org.apache.wicket.protocol.http.mock.Cookies; @@ -30,21 +34,101 @@ import org.apache.wicket.util.tester.apps_1.CreateBook; import org.apache.wicket.util.tester.cookies.CollectAllRequestCookiesPage; import org.apache.wicket.util.tester.cookies.EndPage; import org.apache.wicket.util.tester.cookies.SetCookiePage; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * test code for wicket tester cookie handling * * @author mosmann */ -public class WicketTesterCookieTest extends WicketTestCase +class WicketTesterCookieTest extends WicketTestCase { /** + * creates a new cookie with maxAge set + * + * @param name + * name + * @param value + * value + * @param maxAge + * maxAge + * @return a cookie + */ + private static Cookie newCookie(String name, String value, int maxAge) + { + Cookie cookie = new Cookie(name, value); + cookie.setMaxAge(maxAge); + return cookie; + } + + /** + * make cookie map more readable + * + * @param cookieMap + * cookie map + * @return string + */ + private static String asString(Map<String, Cookie> cookieMap) + { + StringBuilder sb = new StringBuilder(); + sb.append('{'); + for (Map.Entry<String, Cookie> e : cookieMap.entrySet()) + { + sb.append(e.getKey()).append('=').append(asString(e.getValue())); + sb.append(","); + } + sb.append('}'); + return sb.toString(); + } + + /** + * make cookie more readable + * + * @param c + * cookie + * @return string + */ + private static String asString(Cookie c) + { + StringBuilder sb = new StringBuilder(); + sb.append('['); + sb.append("name=").append(c.getName()).append(','); + sb.append("value=").append(c.getValue()).append(','); + sb.append("maxAge=").append(c.getMaxAge()); + sb.append(']'); + return sb.toString(); + } + + /** + * create a cookie map based on cookie name + * + * @param cookies + * cookie list + * @return as map + * @throws RuntimeException + * if more than one cookie with the same name + */ + private static Map<String, Cookie> cookiesFromList(List<Cookie> cookies) + { + Map<String, Cookie> ret = new LinkedHashMap<String, Cookie>(); + for (Cookie cookie : cookies) + { + Cookie oldValue = ret.put(cookie.getName(), cookie); + if (oldValue != null) + { + throw new RuntimeException( + String.format("Cookie with name '%s' ('%s') already in map %s", + cookie.getName(), asString(oldValue), asString(ret))); + } + } + return ret; + } + + /** * */ @Test - public void cookieIsFoundWhenAddedToRequest() + void cookieIsFoundWhenAddedToRequest() { tester.getRequest().addCookie(new Cookie("name", "value")); assertEquals("value", tester.getRequest().getCookie("name").getValue()); @@ -54,20 +138,20 @@ public class WicketTesterCookieTest extends WicketTestCase * */ @Test - public void cookieIsFoundWhenAddedToResponse() + void cookieIsFoundWhenAddedToResponse() { tester.startPage(CreateBook.class); tester.getLastResponse().addCookie(new Cookie("name", "value")); Collection<Cookie> cookies = tester.getLastResponse().getCookies(); assertEquals(cookies.iterator().next().getValue(), "value"); } - + /** * Tests that setting a cookie with age > 0 before creating the page will survive after the * rendering of the page and it will be used for the next request cycle. */ @Test - public void transferCookies() + void transferCookies() { String cookieName = "wicket4289Name"; String cookieValue = "wicket4289Value"; @@ -97,7 +181,7 @@ public class WicketTesterCookieTest extends WicketTestCase * Tests that setting a cookie with age == 0 will not be stored after the request cycle. */ @Test - public void dontTransferCookiesWithNegativeAge() + void dontTransferCookiesWithNegativeAge() { String cookieName = "wicket4289Name"; String cookieValue = "wicket4289Value"; @@ -119,7 +203,7 @@ public class WicketTesterCookieTest extends WicketTestCase * Tests that setting a cookie with age < 0 will not be stored after the request cycle. */ @Test - public void dontTransferCookiesWithZeroAge() + void dontTransferCookiesWithZeroAge() { String cookieName = "wicket4289Name"; String cookieValue = "wicket4289Value"; @@ -138,73 +222,72 @@ public class WicketTesterCookieTest extends WicketTestCase } /** - * A cookie set in the request headers should not be - * expected in the response headers unless the page - * sets it explicitly. + * A cookie set in the request headers should not be expected in the response headers unless the + * page sets it explicitly. * * https://issues.apache.org/jira/browse/WICKET-4989 */ @Test - public void cookieSetInRequestShouldNotBeInResponse() + void cookieSetInRequestShouldNotBeInResponse() { - //start and render the test page + // start and render the test page tester.getRequest().addCookie(new Cookie("dummy", "sample")); tester.startPage(tester.getApplication().getHomePage()); - //assert rendered page class + // assert rendered page class tester.assertRenderedPage(tester.getApplication().getHomePage()); - Assert.assertEquals("The cookie should not be in the response unless explicitly set", - 0, tester.getLastResponse().getCookies().size()); + assertEquals(0, tester.getLastResponse().getCookies().size(), + "The cookie should not be in the response unless explicitly set"); // The cookie should be in each following request unless the server code // schedules it for removal it with cookie.setMaxAge(0) - Assert.assertEquals("The cookie should be in each following request", - 1, tester.getRequest().getCookies().length); + assertEquals(1, tester.getRequest().getCookies().length, + "The cookie should be in each following request"); } /** - * The response cookie should not be the same instance as the request - * cookie. + * The response cookie should not be the same instance as the request cookie. * * https://issues.apache.org/jira/browse/WICKET-4989 */ @Test - public void doNotReuseTheSameInstanceOfTheCookieForRequestAndResponse() + void doNotReuseTheSameInstanceOfTheCookieForRequestAndResponse() { - //start and render the test page + // start and render the test page String cookieName = "cookieName"; String cookieValue = "cookieValue"; Cookie requestCookie = new Cookie(cookieName, cookieValue); tester.getRequest().addCookie(requestCookie); tester.startPage(new CookiePage(cookieName, cookieValue)); - //assert rendered page class + // assert rendered page class tester.assertRenderedPage(CookiePage.class); Cookie responseCookie = tester.getLastResponse().getCookies().get(0); requestCookie.setValue("valueChanged"); - Assert.assertEquals(cookieValue, responseCookie.getValue()); + assertEquals(cookieValue, responseCookie.getValue()); } /** * @see WicketTester - * - * TODO add a cookie to request, which should override cookie from last response and last request - * https://issues.apache.org/jira/browse/WICKET-5147 + * + * TODO add a cookie to request, which should override cookie from last response and last + * request https://issues.apache.org/jira/browse/WICKET-5147 */ @Test - public void wicketTesterCookieHandlingWithoutRedirect() { + void wicketTesterCookieHandlingWithoutRedirect() + { // no cookies set CollectAllRequestCookiesPage collectingPage = collectAllRequestCookiesOnThisPage(); - Assert.assertTrue("no cookie in first request",collectingPage.getCookies().isEmpty()); + assertTrue(collectingPage.getCookies().isEmpty(), "no cookie in first request"); lastResponseDoesNotHaveAnyCookies(); responseDoesNotHaveAnyCookies(); requestDoesNotHaveAnyCookies(); - + // set cookie on request - Cookie firstCookie = newCookie("a","firstValue",1); + Cookie firstCookie = newCookie("a", "firstValue", 1); tester.getRequest().addCookie(firstCookie); collectingPage = collectAllRequestCookiesOnThisPage(); requestOnPageShouldHaveTheseCookies(collectingPage, firstCookie); @@ -220,24 +303,24 @@ public class WicketTesterCookieTest extends WicketTestCase responseDoesNotHaveAnyCookies(); // cookie will be overwritten if response will do so - Cookie cookieSetInResponse = newCookie("a","overwriteWithNewValue",1); + Cookie cookieSetInResponse = newCookie("a", "overwriteWithNewValue", 1); setCookieInResponse(cookieSetInResponse); lastResponseShouldHaveTheseCookies(cookieSetInResponse); requestShouldHaveTheseCookies(cookieSetInResponse); - + // cookies from last response then should appear on following requests collectingPage = collectAllRequestCookiesOnThisPage(); requestOnPageShouldHaveTheseCookies(collectingPage, cookieSetInResponse); lastResponseDoesNotHaveAnyCookies(); requestShouldHaveTheseCookies(cookieSetInResponse); - + // cookies from requests will be deleted if the response will do so - Cookie expiredCookieSetInResponse = newCookie("a","removeMe",0); + Cookie expiredCookieSetInResponse = newCookie("a", "removeMe", 0); setCookieInResponse(expiredCookieSetInResponse); lastResponseShouldHaveTheseCookies(expiredCookieSetInResponse); responseDoesNotHaveAnyCookies(); requestDoesNotHaveAnyCookies(); - + // no cookies in next request while last cookie was deleted collectingPage = collectAllRequestCookiesOnThisPage(); requestOnPageShouldHaveTheseCookies(collectingPage); @@ -248,48 +331,49 @@ public class WicketTesterCookieTest extends WicketTestCase /** * @see WicketTesterCookieTest#wicketTesterCookieHandlingWithoutRedirect() - * - * https://issues.apache.org/jira/browse/WICKET-5147 + * + * https://issues.apache.org/jira/browse/WICKET-5147 */ @Test - public void wicketTesterCookieHandlingWithRedirect() { + void wicketTesterCookieHandlingWithRedirect() + { // set cookie in response then redirect to other page - Cookie firstCookie = newCookie("a","firstValue",1); + Cookie firstCookie = newCookie("a", "firstValue", 1); setCookieInResponseAndRedirect(firstCookie); lastResponseShouldHaveTheseCookies(firstCookie); requestShouldHaveTheseCookies(firstCookie); // cookie in response after redirect should appear in next request CollectAllRequestCookiesPage collectingPage = collectAllRequestCookiesOnThisPage(); - requestOnPageShouldHaveTheseCookies(collectingPage,firstCookie); + requestOnPageShouldHaveTheseCookies(collectingPage, firstCookie); lastResponseDoesNotHaveAnyCookies(); requestShouldHaveTheseCookies(firstCookie); responseDoesNotHaveAnyCookies(); - + // set cookie on request and overwrite in response then redirect to other page - Cookie cookieSetInRequest = newCookie("a","valueFromRequest",1); - Cookie cookieSetInResponse = newCookie("a","overwriteInResponse",1); + Cookie cookieSetInRequest = newCookie("a", "valueFromRequest", 1); + Cookie cookieSetInResponse = newCookie("a", "overwriteInResponse", 1); tester.getRequest().addCookie(cookieSetInRequest); setCookieInResponseAndRedirect(cookieSetInResponse); lastResponseShouldHaveTheseCookies(cookieSetInResponse); requestShouldHaveTheseCookies(cookieSetInResponse); - + // cookie in response after redirect should appear in next request collectingPage = collectAllRequestCookiesOnThisPage(); - requestOnPageShouldHaveTheseCookies(collectingPage,cookieSetInResponse); + requestOnPageShouldHaveTheseCookies(collectingPage, cookieSetInResponse); lastResponseDoesNotHaveAnyCookies(); requestShouldHaveTheseCookies(cookieSetInResponse); responseDoesNotHaveAnyCookies(); - + // set cookie on request and remove it in response then redirect to other page - Cookie nextCookieSetInRequest = newCookie("a","nextValueFromRequest",1); - Cookie nextCookieSetInResponse = newCookie("a","newValue",0); + Cookie nextCookieSetInRequest = newCookie("a", "nextValueFromRequest", 1); + Cookie nextCookieSetInResponse = newCookie("a", "newValue", 0); tester.getRequest().addCookie(nextCookieSetInRequest); setCookieInResponseAndRedirect(nextCookieSetInResponse); lastResponseShouldHaveTheseCookies(nextCookieSetInResponse); requestDoesNotHaveAnyCookies(); responseDoesNotHaveAnyCookies(); - + // no cookies left collectingPage = collectAllRequestCookiesOnThisPage(); requestOnPageShouldHaveTheseCookies(collectingPage); @@ -297,22 +381,10 @@ public class WicketTesterCookieTest extends WicketTestCase requestDoesNotHaveAnyCookies(); responseDoesNotHaveAnyCookies(); } - - /** - * creates a new cookie with maxAge set - * @param name name - * @param value value - * @param maxAge maxAge - * @return a cookie - */ - private static Cookie newCookie(String name,String value, int maxAge) { - Cookie cookie = new Cookie(name,value); - cookie.setMaxAge(maxAge); - return cookie; - } - + /** - * start a page which collects all cookies from request + * start a page which collects all cookies from request + * * @return the page */ private CollectAllRequestCookiesPage collectAllRequestCookiesOnThisPage() @@ -322,7 +394,9 @@ public class WicketTesterCookieTest extends WicketTestCase /** * start a page which set a cookie in response - * @param cookie cookie + * + * @param cookie + * cookie */ private void setCookieInResponse(Cookie cookie) { @@ -331,88 +405,74 @@ public class WicketTesterCookieTest extends WicketTestCase /** * start a page which set a cookie in response and then redirect to different page - * @param cookie cookie + * + * @param cookie + * cookie */ private void setCookieInResponseAndRedirect(Cookie cookie) { - tester.startPage(new SetCookiePage(cookie,EndPage.class)); + tester.startPage(new SetCookiePage(cookie, EndPage.class)); } /** * check cookies collected by page - * @param page page - * @param cookies cookies + * + * @param page + * page + * @param cookies + * cookies */ - private void requestOnPageShouldHaveTheseCookies(CollectAllRequestCookiesPage page, Cookie...cookies) { + private void requestOnPageShouldHaveTheseCookies(CollectAllRequestCookiesPage page, + Cookie... cookies) + { listShouldMatchAll(page.getCookies(), cookies); } /** * check cookies in current request - * @param cookies cookies + * + * @param cookies + * cookies */ - private void requestShouldHaveTheseCookies(Cookie...cookies) { + private void requestShouldHaveTheseCookies(Cookie... cookies) + { Cookie[] cookieFromRequest = tester.getRequest().getCookies(); - listShouldMatchAll(cookieFromRequest!=null ? Arrays.asList(cookieFromRequest) : new ArrayList<Cookie>(), cookies); + listShouldMatchAll( + cookieFromRequest != null ? Arrays.asList(cookieFromRequest) : new ArrayList<Cookie>(), + cookies); } - + /** - * check if every cookie is found in the list and no cookie is left - * @param cookieList cookie list - * @param cookies cookies to check + * check if every cookie is found in the list and no cookie is left + * + * @param cookieList + * cookie list + * @param cookies + * cookies to check */ private void listShouldMatchAll(List<Cookie> cookieList, Cookie... cookies) { Map<String, Cookie> cookieMap = cookiesFromList(cookieList); - for (Cookie cookie : cookies) { + for (Cookie cookie : cookies) + { Cookie removed = cookieMap.remove(cookie.getName()); - Assert.assertNotNull("Cookie "+cookie.getName(),removed); - Assert.assertTrue("Cookie "+cookie.getName()+" matches",Cookies.isEqual(cookie, removed)); + assertNotNull(removed, "Cookie " + cookie.getName()); + assertTrue(Cookies.isEqual(cookie, removed), "Cookie " + cookie.getName() + " matches"); } - Assert.assertTrue("no cookies left "+asString(cookieMap),cookieMap.isEmpty()); - } - - /** - * make cookie map more readable - * @param cookieMap cookie map - * @return string - */ - private static String asString(Map<String, Cookie> cookieMap) - { - StringBuilder sb=new StringBuilder(); - sb.append('{'); - for (Map.Entry<String, Cookie> e : cookieMap.entrySet()) { - sb.append(e.getKey()).append('=').append(asString(e.getValue())); - sb.append(","); - } - sb.append('}'); - return sb.toString(); - } - - /** - * make cookie more readable - * @param c cookie - * @return string - */ - private static String asString(Cookie c) - { - StringBuilder sb=new StringBuilder(); - sb.append('['); - sb.append("name=").append(c.getName()).append(','); - sb.append("value=").append(c.getValue()).append(','); - sb.append("maxAge=").append(c.getMaxAge()); - sb.append(']'); - return sb.toString(); + assertTrue(cookieMap.isEmpty(), "no cookies left " + asString(cookieMap)); } /** * check last response cookies - * @param cookies cookies + * + * @param cookies + * cookies */ - private void lastResponseShouldHaveTheseCookies(Cookie...cookies) { + private void lastResponseShouldHaveTheseCookies(Cookie... cookies) + { listShouldMatchAll(tester.getLastResponse().getCookies(), cookies); } - + /** * response should not have any cookies */ @@ -420,7 +480,7 @@ public class WicketTesterCookieTest extends WicketTestCase { listShouldMatchAll(tester.getLastResponse().getCookies()); } - + /** * response should not have any cookies */ @@ -428,7 +488,7 @@ public class WicketTesterCookieTest extends WicketTestCase { listShouldMatchAll(tester.getResponse().getCookies()); } - + /** * request should not have any cookies */ @@ -436,25 +496,5 @@ public class WicketTesterCookieTest extends WicketTestCase { requestShouldHaveTheseCookies(); } - - /** - * create a cookie map based on cookie name - * @param cookies cookie list - * @return as map - * @throws RuntimeException if more than one cookie with the same name - */ - private static Map<String,Cookie> cookiesFromList(List<Cookie> cookies) { - Map<String, Cookie> ret = new LinkedHashMap<String, Cookie>(); - for (Cookie cookie : cookies) - { - Cookie oldValue = ret.put(cookie.getName(), cookie); - if (oldValue != null) - { - throw new RuntimeException(String.format("Cookie with name '%s' ('%s') already in map %s", - cookie.getName(), asString(oldValue), asString(ret))); - } - } - return ret; - } } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessBase.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessBase.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessBase.java index 18ef601..fb62b82 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessBase.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessBase.java @@ -16,6 +16,8 @@ */ package org.apache.wicket.util.tester; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.apache.wicket.Component; import org.apache.wicket.MarkupContainer; import org.apache.wicket.ajax.AjaxRequestTarget; @@ -27,12 +29,12 @@ import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.model.IModel; import org.apache.wicket.util.resource.IResourceStream; import org.apache.wicket.util.resource.StringResourceStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * https://issues.apache.org/jira/browse/WICKET-5426 */ -public abstract class WicketTesterLazyIsPageStatelessBase extends WicketTestCase +abstract class WicketTesterLazyIsPageStatelessBase extends WicketTestCase { /** * The page must be stateless because the stateful component @@ -41,7 +43,7 @@ public abstract class WicketTesterLazyIsPageStatelessBase extends WicketTestCase * @throws Exception */ @Test - public void isStateless() throws Exception + void isStateless() throws Exception { tester.startPage(MyPage.class); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessOnePassTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessOnePassTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessOnePassTest.java index 8787dc4..1bfd770 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessOnePassTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessOnePassTest.java @@ -23,7 +23,7 @@ import org.apache.wicket.settings.RequestCycleSettings; /** * https://issues.apache.org/jira/browse/WICKET-5426 */ -public class WicketTesterLazyIsPageStatelessOnePassTest extends WicketTesterLazyIsPageStatelessBase +class WicketTesterLazyIsPageStatelessOnePassTest extends WicketTesterLazyIsPageStatelessBase { @Override protected WebApplication newApplication() http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToBufferTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToBufferTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToBufferTest.java index 6a41fe6..c7f3c48 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToBufferTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToBufferTest.java @@ -25,7 +25,7 @@ import org.apache.wicket.protocol.http.WebApplication; import org.apache.wicket.settings.RequestCycleSettings; import org.apache.wicket.util.resource.IResourceStream; import org.apache.wicket.util.resource.StringResourceStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * https://issues.apache.org/jira/browse/WICKET-5426 @@ -54,7 +54,7 @@ public class WicketTesterLazyIsPageStatelessRedirectToBufferTest extends WicketT * @throws Exception */ @Test - public void statelessListenerInvoked() throws Exception + void statelessListenerInvoked() throws Exception { tester.startPage(StatelessListenerPage.class); tester.assertRenderedPage(StatelessListenerPage.class); @@ -67,7 +67,7 @@ public class WicketTesterLazyIsPageStatelessRedirectToBufferTest extends WicketT public static class StatelessListenerPage extends MyPage { - public StatelessListenerPage() + public StatelessListenerPage() { super(); add(new StatelessForm("statelessForm") http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToRenderTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToRenderTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToRenderTest.java index 0f228e5..5cec01a 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToRenderTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterLazyIsPageStatelessRedirectToRenderTest.java @@ -23,7 +23,7 @@ import org.apache.wicket.settings.RequestCycleSettings; /** * https://issues.apache.org/jira/browse/WICKET-5426 */ -public class WicketTesterLazyIsPageStatelessRedirectToRenderTest extends WicketTesterLazyIsPageStatelessBase +class WicketTesterLazyIsPageStatelessRedirectToRenderTest extends WicketTesterLazyIsPageStatelessBase { @Override protected WebApplication newApplication() http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterSessionCreationTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterSessionCreationTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterSessionCreationTest.java index 225570b..efda451 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterSessionCreationTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterSessionCreationTest.java @@ -16,14 +16,16 @@ */ package org.apache.wicket.util.tester; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.Locale; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * WICKET-1215 */ -public class WicketTesterSessionCreationTest extends WicketTestCase +class WicketTesterSessionCreationTest extends WicketTestCase { private static Locale EXPECTED = Locale.FRENCH; @@ -32,7 +34,7 @@ public class WicketTesterSessionCreationTest extends WicketTestCase * WicketTester recreates session after setting attributes on it */ @Test - public void wicket1215() + void wicket1215() { tester.getSession().setLocale(EXPECTED); tester.startPage(LocalePage.class); @@ -45,7 +47,7 @@ public class WicketTesterSessionCreationTest extends WicketTestCase private static final long serialVersionUID = 1L; /***/ - public LocalePage() + public LocalePage() { assertEquals(EXPECTED, getSession().getLocale()); } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterSessionInvalidateTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterSessionInvalidateTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterSessionInvalidateTest.java index da14cec..ce207f4 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterSessionInvalidateTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterSessionInvalidateTest.java @@ -16,6 +16,9 @@ */ package org.apache.wicket.util.tester; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + import org.apache.wicket.MarkupContainer; import org.apache.wicket.markup.IMarkupResourceStreamProvider; import org.apache.wicket.markup.html.WebPage; @@ -23,18 +26,18 @@ import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.util.resource.IResourceStream; import org.apache.wicket.util.resource.StringResourceStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** */ -public class WicketTesterSessionInvalidateTest extends WicketTestCase +class WicketTesterSessionInvalidateTest extends WicketTestCase { /** * https://issues.apache.org/jira/browse/WICKET-3212 */ @Test - public void sessionInvalidate() + void sessionInvalidate() { tester.startPage(MyPage.class); @@ -61,7 +64,7 @@ public class WicketTesterSessionInvalidateTest extends WicketTestCase * * @param pageParameters */ - public MyPage(PageParameters pageParameters) + public MyPage(PageParameters pageParameters) { super(pageParameters); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java index 33ea646..1d967f1 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/WicketTesterTest.java @@ -16,10 +16,17 @@ */ package org.apache.wicket.util.tester; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.List; import java.util.Locale; import java.util.concurrent.atomic.AtomicBoolean; - import javax.servlet.http.HttpServletResponse; import org.apache.wicket.Component; @@ -43,7 +50,6 @@ import org.apache.wicket.markup.ComponentTag; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Button; -import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.FormComponent; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.link.Link; @@ -75,22 +81,22 @@ import org.apache.wicket.util.tester.apps_1.ViewBook; import org.apache.wicket.util.tester.apps_6.LinkPage; import org.apache.wicket.util.tester.apps_6.ResultPage; import org.apache.wicket.util.tester.apps_8.ComponentFeedbackResourceTestingPage; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @see WicketTesterCookieTest for cookie related test * @author Juergen Donnerstag */ -public class WicketTesterTest extends WicketTestCase +class WicketTesterTest extends WicketTestCase { private boolean eventExecuted; /** * @throws Exception */ - @Before - public void before() throws Exception + @BeforeEach + void before() throws Exception { eventExecuted = false; } @@ -106,7 +112,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void viewBook() throws Exception + void viewBook() throws Exception { Book mockBook = new Book("xxId", "xxName"); Page page = new ViewBook(mockBook); @@ -123,7 +129,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void createBook_validateFail() throws Exception + void createBook_validateFail() throws Exception { Session.get().setLocale(Locale.US); // fix locale tester.startPage(CreateBook.class); @@ -145,7 +151,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void createBook_validatePass() throws Exception + void createBook_validatePass() throws Exception { tester.startPage(CreateBook.class); @@ -169,7 +175,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void bookmarkableLink() throws Exception + void bookmarkableLink() throws Exception { // for WebPage without default constructor, I define a TestPageSource to // let the page be instatiated lately. @@ -186,7 +192,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void clickLink_setResponsePageClass() throws Exception + void clickLink_setResponsePageClass() throws Exception { tester.startPage(LinkPage.class); tester.assertRenderedPage(LinkPage.class); @@ -201,7 +207,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void clickLink_setResponsePage() throws Exception + void clickLink_setResponsePage() throws Exception { tester.startPage(LinkPage.class); tester.assertRenderedPage(LinkPage.class); @@ -216,7 +222,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void clickLink_ajaxLink_setResponsePageClass() throws Exception + void clickLink_ajaxLink_setResponsePageClass() throws Exception { tester.startPage(LinkPage.class); tester.assertRenderedPage(LinkPage.class); @@ -233,13 +239,13 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void clickLink_ajaxLink_notEnabled() throws Exception + void clickLink_ajaxLink_notEnabled() throws Exception { tester.startPage(LinkPage.class); tester.assertRenderedPage(LinkPage.class); - tester.getComponentFromLastRenderedPage("ajaxLinkWithSetResponsePageClass").setEnabled( - false); + tester.getComponentFromLastRenderedPage("ajaxLinkWithSetResponsePageClass") + .setEnabled(false); try { tester.clickLink("ajaxLinkWithSetResponsePageClass"); @@ -257,13 +263,13 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void executeAjaxEvent_componentNotEnabled() throws Exception + void executeAjaxEvent_componentNotEnabled() throws Exception { tester.startPage(LinkPage.class); tester.assertRenderedPage(LinkPage.class); - tester.getComponentFromLastRenderedPage("ajaxLinkWithSetResponsePageClass").setEnabled( - false); + tester.getComponentFromLastRenderedPage("ajaxLinkWithSetResponsePageClass") + .setEnabled(false); try { tester.executeAjaxEvent("ajaxLinkWithSetResponsePageClass", "click"); @@ -281,13 +287,13 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void assertEnabled() throws Exception + void assertEnabled() throws Exception { tester.startPage(LinkPage.class); tester.assertRenderedPage(LinkPage.class); - tester.getComponentFromLastRenderedPage("ajaxLinkWithSetResponsePageClass").setEnabled( - false); + tester.getComponentFromLastRenderedPage("ajaxLinkWithSetResponsePageClass") + .setEnabled(false); try { tester.assertEnabled("ajaxLinkWithSetResponsePageClass"); @@ -305,7 +311,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void assertDisabled() throws Exception + void assertDisabled() throws Exception { tester.startPage(LinkPage.class); tester.assertRenderedPage(LinkPage.class); @@ -329,7 +335,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void assertRequired() throws Exception + void assertRequired() throws Exception { tester.startPage(CreateBook.class); tester.assertRenderedPage(CreateBook.class); @@ -337,7 +343,8 @@ public class WicketTesterTest extends WicketTestCase // test #1: "id" is required by default tester.assertRequired("createForm:id"); - FormComponent<?> bookId = (FormComponent<?>)tester.getComponentFromLastRenderedPage("createForm:id"); + FormComponent<?> bookId = (FormComponent<?>)tester + .getComponentFromLastRenderedPage("createForm:id"); try { // test #2: set it manually to not required @@ -365,7 +372,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void clickLink_ajaxLink_setResponsePage() throws Exception + void clickLink_ajaxLink_setResponsePage() throws Exception { tester.startPage(LinkPage.class); tester.assertRenderedPage(LinkPage.class); @@ -380,7 +387,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void clickLink_ajaxFallbackLink_setResponsePageClass() throws Exception + void clickLink_ajaxFallbackLink_setResponsePageClass() throws Exception { tester.startPage(LinkPage.class); tester.assertRenderedPage(LinkPage.class); @@ -395,7 +402,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void clickLink_ajaxFallbackLink_setResponsePage() throws Exception + void clickLink_ajaxFallbackLink_setResponsePage() throws Exception { tester.startPage(LinkPage.class); tester.assertRenderedPage(LinkPage.class); @@ -410,7 +417,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void clickLink_ajaxSubmitLink_setResponsePage() throws Exception + void clickLink_ajaxSubmitLink_setResponsePage() throws Exception { tester.startPage(LinkPage.class); tester.assertRenderedPage(LinkPage.class); @@ -425,7 +432,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void pageConstructor() throws Exception + void pageConstructor() throws Exception { Book mockBook = new Book("xxId", "xxName"); Page page = new ViewBook(mockBook); @@ -443,7 +450,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void constructorAndInnerPage() throws Exception + void constructorAndInnerPage() throws Exception { tester.startPage(new MockInnerClassPage()); @@ -457,7 +464,7 @@ public class WicketTesterTest extends WicketTestCase * */ @Test - public void assertComponentOnAjaxResponse() + void assertComponentOnAjaxResponse() { final Page page = new MockPageWithLink(); AjaxLink<Void> ajaxLink = new AjaxLink<Void>(MockPageWithLink.LINK_ID) @@ -507,7 +514,7 @@ public class WicketTesterTest extends WicketTestCase * encoded. */ @Test - public void assertComponentOnAjaxResponse_encoding() + void assertComponentOnAjaxResponse_encoding() { final IModel<String> labelModel = new IModel<String>() { @@ -567,7 +574,7 @@ public class WicketTesterTest extends WicketTestCase * Test that the executeAjaxEvent on the WicketTester works. */ @Test - public void executeAjaxEvent() + void executeAjaxEvent() { // Setup mocks final MockPageWithOneComponent page = new MockPageWithOneComponent(); @@ -600,7 +607,7 @@ public class WicketTesterTest extends WicketTestCase * Test that the clickLink works when submitting a form with a checkgroup inside. */ @Test - public void clickLink_ajaxSubmitLink_checkGroup() + void clickLink_ajaxSubmitLink_checkGroup() { tester.startPage(MockPageWithFormAndCheckGroup.class); @@ -613,7 +620,7 @@ public class WicketTesterTest extends WicketTestCase * components WICKET-3053 */ @Test - public void clickLink_ajaxSubmitLink_preservesFormComponentValues() + void clickLink_ajaxSubmitLink_preservesFormComponentValues() { tester.startPage(MockPageAjaxSubmitLinkSubmitsWholeForm.class); @@ -650,12 +657,13 @@ public class WicketTesterTest extends WicketTestCase * Test that the executeAjaxEvent "submits" the form if the event is a AjaxFormSubmitBehavior. */ @Test - public void executeAjaxEvent_ajaxFormSubmitLink() + void executeAjaxEvent_ajaxFormSubmitLink() { tester.startPage(MockPageWithFormAndAjaxFormSubmitBehavior.class); // Get the page - MockPageWithFormAndAjaxFormSubmitBehavior page = (MockPageWithFormAndAjaxFormSubmitBehavior)tester.getLastRenderedPage(); + MockPageWithFormAndAjaxFormSubmitBehavior page = (MockPageWithFormAndAjaxFormSubmitBehavior)tester + .getLastRenderedPage(); Pojo pojo = page.getPojo(); @@ -670,8 +678,9 @@ public class WicketTesterTest extends WicketTestCase // Execute the ajax event tester.executeAjaxEvent(MockPageWithFormAndAjaxFormSubmitBehavior.EVENT_COMPONENT, "click"); - assertTrue("AjaxFormSubmitBehavior.onSubmit() has not been executed in " + - MockPageWithFormAndAjaxFormSubmitBehavior.class, page.isExecuted()); + assertTrue(page.isExecuted(), + "AjaxFormSubmitBehavior.onSubmit() has not been executed in " + + MockPageWithFormAndAjaxFormSubmitBehavior.class); assertEquals("Mock name", ((TextField<?>)tester.getComponentFromLastRenderedPage("form:name")).getValue()); @@ -688,14 +697,15 @@ public class WicketTesterTest extends WicketTestCase * */ @Test - public void submittingFormWithAjaxEventSubmitsFormValues() + void submittingFormWithAjaxEventSubmitsFormValues() { tester.startPage(MockPageWithFormAndAjaxFormSubmitBehavior.class); FormTester form = tester.newFormTester("form"); form.setValue("name", "New name"); tester.executeAjaxEvent(MockPageWithFormAndAjaxFormSubmitBehavior.EVENT_COMPONENT, "click"); - MockPageWithFormAndAjaxFormSubmitBehavior page = (MockPageWithFormAndAjaxFormSubmitBehavior)tester.getLastRenderedPage(); + MockPageWithFormAndAjaxFormSubmitBehavior page = (MockPageWithFormAndAjaxFormSubmitBehavior)tester + .getLastRenderedPage(); Pojo pojo = page.getPojo(); assertEquals("New name", pojo.getName()); } @@ -704,7 +714,7 @@ public class WicketTesterTest extends WicketTestCase * */ @Test - public void redirectWithPageParameters() + void redirectWithPageParameters() { tester.startPage(MockPageParameterPage.class); @@ -724,7 +734,7 @@ public class WicketTesterTest extends WicketTestCase * parameters */ @Test - public void setQueryParameter() + void setQueryParameter() { tester.getRequest().setParameter("p1", "v1"); @@ -739,11 +749,12 @@ public class WicketTesterTest extends WicketTestCase * query parameters */ @Test - public void setQueryParameterWhenRequestHasAnQueryUrl() + void setQueryParameterWhenRequestHasAnQueryUrl() { PageParameters parameters = new PageParameters(); parameters.set("q_1", "q_1_value"); - IPageProvider testPageProvider = new PageProvider(MockPageParametersAware.class, parameters); + IPageProvider testPageProvider = new PageProvider(MockPageParametersAware.class, + parameters); IRequestHandler pageRequestHandler = new BookmarkablePageRequestHandler(testPageProvider); Url url = tester.getApplication().getRootRequestMapper().mapHandler(pageRequestHandler); tester.getRequest().setParameter("q_2", "q_2_value"); @@ -752,20 +763,23 @@ public class WicketTesterTest extends WicketTestCase tester.processRequest(); MockPageParametersAware page = (MockPageParametersAware)tester.getLastRenderedPage(); - assertEquals("q_1_value", page.getLastQueryParameters().getParameterValue("q_1").toString()); - assertEquals("q_2_value", page.getLastQueryParameters().getParameterValue("q_2").toString()); + assertEquals("q_1_value", + page.getLastQueryParameters().getParameterValue("q_1").toString()); + assertEquals("q_2_value", + page.getLastQueryParameters().getParameterValue("q_2").toString()); } /** * Asserting that multiple parameters added in request and PageParameters get processed */ @Test - public void setMultiValueQueryParameter() + void setMultiValueQueryParameter() { PageParameters parameters = new PageParameters(); parameters.add("q_1", "q_1_value_1"); parameters.add("q_1", "q_1_value_2"); - IPageProvider testPageProvider = new PageProvider(MockPageParametersAware.class, parameters); + IPageProvider testPageProvider = new PageProvider(MockPageParametersAware.class, + parameters); IRequestHandler pageRequestHandler = new BookmarkablePageRequestHandler(testPageProvider); Url url = tester.getApplication().getRootRequestMapper().mapHandler(pageRequestHandler); tester.getRequest().addParameter("q_2", "q_2_value_1"); @@ -788,7 +802,7 @@ public class WicketTesterTest extends WicketTestCase * Asserting the parameters set by user in request get processed when submitting a form */ @Test - public void parametersOnFormSubmit() + void parametersOnFormSubmit() { tester.startPage(MockPageParametersAware.class); @@ -802,14 +816,15 @@ public class WicketTesterTest extends WicketTestCase MockPageParametersAware page = (MockPageParametersAware)tester.getLastRenderedPage(); assertEquals("v1", page.getLastPostParameters().getParameterValue("textfield").toString()); assertEquals("p_1_value", page.getLastPostParameters().getParameterValue("p_1").toString()); - assertEquals("q_1_value", page.getLastQueryParameters().getParameterValue("q_1").toString()); + assertEquals("q_1_value", + page.getLastQueryParameters().getParameterValue("q_1").toString()); } /** * Asserting the parameters set by user on request get processed when submitting a form */ @Test - public void multiValueParametersOnFormSubmit() + void multiValueParametersOnFormSubmit() { tester.startPage(MockPageParametersAware.class); @@ -823,25 +838,29 @@ public class WicketTesterTest extends WicketTestCase MockPageParametersAware page = (MockPageParametersAware)tester.getLastRenderedPage(); assertEquals("v1", page.getLastPostParameters().getParameterValue("textfield").toString()); assertEquals("p_1_value", page.getLastPostParameters().getParameterValue("p_1").toString()); - assertEquals("q_1_value", page.getLastQueryParameters().getParameterValue("q_1").toString()); + assertEquals("q_1_value", + page.getLastQueryParameters().getParameterValue("q_1").toString()); } /** * Loading of page markup resource should not be allowed */ - @Test(expected = PackageResourceBlockedException.class) - public void loadPageMarkupTemplate() + @Test + void loadPageMarkupTemplate() { String url = "wicket/resource/" + BlockedResourceLinkPage.class.getName() + "/" + BlockedResourceLinkPage.class.getSimpleName() + ".html"; - tester.executeUrl(url); + + assertThrows(PackageResourceBlockedException.class, () -> { + tester.executeUrl(url); + }); } /** * WICKET-280 Allow to access html resources (non-page markup templates) */ @Test - public void loadNonPageMarkupTemplate() + void loadNonPageMarkupTemplate() { String url = "wicket/resource/" + BlockedResourceLinkPage.class.getName() + "/test.html"; tester.executeUrl(url); @@ -853,21 +872,21 @@ public class WicketTesterTest extends WicketTestCase * (resource not found) */ @Test - public void clickResourceLinkWithSomeCommaAppendedUrl() + void clickResourceLinkWithSomeCommaAppendedUrl() { String url = "wicket/resource/" + BlockedResourceLinkPage.class.getName() + "/" + BlockedResourceLinkPage.class.getSimpleName() + ".html,xml"; tester.getRequest().setURL(url); - assertFalse("Comma separated extensions are not supported and wont find any resource", - tester.processRequest()); + assertFalse(tester.processRequest(), + "Comma separated extensions are not supported and wont find any resource"); } /** * Toggle submit button to disabled state. */ @Test - public void toggleButtonEnabledState() + void toggleButtonEnabledState() { tester.startPage(MockFormPage.class); Component submit = tester.getComponentFromLastRenderedPage("form:submit"); @@ -880,7 +899,7 @@ public class WicketTesterTest extends WicketTestCase * Toggle submit button to enabled when text field validates. */ @Test - public void toggleAjaxFormButton() + void toggleAjaxFormButton() { tester.startPage(new MockAjaxFormPage()); Button submit = getSubmitButton(); @@ -902,7 +921,7 @@ public class WicketTesterTest extends WicketTestCase * Test for WICKET-3123 */ @Test - public void sessionBinding() + void sessionBinding() { Session session = tester.getSession(); assertTrue(session.isTemporary()); @@ -927,11 +946,10 @@ public class WicketTesterTest extends WicketTestCase * <a href="https://issues.apache.org/jira/browse/WICKET-3543">WICKET-3543</a> */ @Test - public void startResourceReference() + void startResourceReference() { - tester.startResourceReference(tester.getApplication() - .getJavaScriptLibrarySettings() - .getWicketAjaxReference()); + tester.startResourceReference( + tester.getApplication().getJavaScriptLibrarySettings().getWicketAjaxReference()); // verify that a random string from that resource is in the response tester.assertContains("getAjaxBaseUrl"); } @@ -940,7 +958,7 @@ public class WicketTesterTest extends WicketTestCase * <a href="https://issues.apache.org/jira/browse/WICKET-3543">WICKET-3543</a> */ @Test - public void startResource() + void startResource() { tester.startResource(tester.getApplication() .getJavaScriptLibrarySettings() @@ -956,7 +974,7 @@ public class WicketTesterTest extends WicketTestCase * @throws Exception */ @Test - public void assertRenderedPageErrorMessage() throws Exception + void assertRenderedPageErrorMessage() throws Exception { tester.startPage(MockPageParametersAware.class); tester.assertRenderedPage(MockPageParametersAware.class); @@ -970,7 +988,7 @@ public class WicketTesterTest extends WicketTestCase * https://issues.apache.org/jira/browse/WICKET-3913 */ @Test - public void startPanelGoesToAnotherPage() + void startPanelGoesToAnotherPage() { tester.startComponentInPage(new MockPanelWithLink("testPanel") { @@ -992,7 +1010,7 @@ public class WicketTesterTest extends WicketTestCase * https://issues.apache.org/jira/browse/WICKET-3940 */ @Test - public void rerenderComponentInPage() + void rerenderComponentInPage() { tester.startComponentInPage(new Label("testLabel")); tester.startPage(tester.getLastRenderedPage()); @@ -1003,10 +1021,11 @@ public class WicketTesterTest extends WicketTestCase * permission anymore */ @Test - public void rerenderNotAllowed() + void rerenderNotAllowed() { tester.setExposeExceptions(false); - class YesNoPageAuthorizationStrategy extends IAuthorizationStrategy.AllowAllAuthorizationStrategy + class YesNoPageAuthorizationStrategy + extends IAuthorizationStrategy.AllowAllAuthorizationStrategy { private boolean allowed = true; @@ -1033,9 +1052,8 @@ public class WicketTesterTest extends WicketTestCase tester.assertRenderedPage(DummyHomePage.class); strategy.allowed = false; tester.startPage(start); - tester.assertRenderedPage(tester.getApplication() - .getApplicationSettings() - .getAccessDeniedPage()); + tester.assertRenderedPage( + tester.getApplication().getApplicationSettings().getAccessDeniedPage()); } /** @@ -1044,7 +1062,7 @@ public class WicketTesterTest extends WicketTestCase * Clicking on ResourceLink should deliver the resource content */ @Test - public void clickResourceLinkWithResource() + void clickResourceLinkWithResource() { MockPageWithLink page = new MockPageWithLink(); String content = "content"; @@ -1064,13 +1082,14 @@ public class WicketTesterTest extends WicketTestCase * Clicking on ResourceLink should deliver the resource reference's content */ @Test - public void clickResourceLinkWithResourceReference() + void clickResourceLinkWithResourceReference() { MockPageWithLink page = new MockPageWithLink(); String content = "content"; final ByteArrayResource resource = new ByteArrayResource("text/plain", content.getBytes(), - "fileName.txt"); - ResourceReference reference = new ResourceReference(WicketTesterTest.class, "resourceLinkWithResourceReferenceTest") + "fileName.txt"); + ResourceReference reference = new ResourceReference(WicketTesterTest.class, + "resourceLinkWithResourceReferenceTest") { @Override public IResource getResource() @@ -1093,7 +1112,7 @@ public class WicketTesterTest extends WicketTestCase * return only the component's markup, without the autogenerated markup for the page */ @Test - public void renderOnlyComponentsMarkup() + void renderOnlyComponentsMarkup() { tester.startComponentInPage(new Label("label", "content") { @@ -1112,7 +1131,7 @@ public class WicketTesterTest extends WicketTestCase } @Test - public void catchExternalRedirect() throws Exception + void catchExternalRedirect() throws Exception { class RedirectPage extends WebPage { @@ -1128,7 +1147,7 @@ public class WicketTesterTest extends WicketTestCase } @Test - public void catchExternalRedirectFailure() throws Exception + void catchExternalRedirectFailure() throws Exception { class RedirectPage extends WebPage { @@ -1153,35 +1172,26 @@ public class WicketTesterTest extends WicketTestCase } @Test - public void dontCatchInternalRedirect() throws Exception + void dontCatchInternalRedirect() throws Exception { class RedirectPage extends WebPage { @Override protected void onConfigure() { - throw new RedirectToUrlException("wicket/bookmarkable/" + - CreateBook.class.getName()); + throw new RedirectToUrlException( + "wicket/bookmarkable/" + CreateBook.class.getName()); } } tester.startPage(new RedirectPage()); tester.assertRenderedPage(CreateBook.class); } - public static class AlwaysRedirectPage extends WebPage - { - public AlwaysRedirectPage() - { - // redirects to another web server on the same computer - throw new RedirectToUrlException("http://localhost:4333/"); - } - } - /** * https://issues.apache.org/jira/browse/WICKET-4610 */ @Test - public void redirectToAbsoluteUrlTest() + void redirectToAbsoluteUrlTest() { tester.setFollowRedirects(false); tester.startPage(AlwaysRedirectPage.class); @@ -1193,7 +1203,7 @@ public class WicketTesterTest extends WicketTestCase * WICKET-5017 */ @Test - public void formSubmitSendsFormInputInRequest() + void formSubmitSendsFormInputInRequest() { final AtomicBoolean ajaxButtonSubmitted = new AtomicBoolean(false); final AtomicBoolean ajaxSubmitLinkSubmitted = new AtomicBoolean(false); @@ -1241,29 +1251,31 @@ public class WicketTesterTest extends WicketTestCase * https://issues.apache.org/jira/browse/WICKET-5128 */ @Test - public void renderComponentRelativeErrorMessage() + void renderComponentRelativeErrorMessage() { tester.startPage(new ComponentFeedbackResourceTestingPage()); Component label = tester.getComponentFromLastRenderedPage("label"); - tester.assertComponentFeedbackMessage(label, "error.msg", null, new ExactLevelFeedbackMessageFilter(FeedbackMessage.ERROR)); + tester.assertComponentFeedbackMessage(label, "error.msg", null, + new ExactLevelFeedbackMessageFilter(FeedbackMessage.ERROR)); } /** * https://issues.apache.org/jira/browse/WICKET-5128 */ @Test - public void renderComponentRelativeInfoMessage() + void renderComponentRelativeInfoMessage() { tester.startPage(new ComponentFeedbackResourceTestingPage()); Component label = tester.getComponentFromLastRenderedPage("label"); - tester.assertComponentFeedbackMessage(label, "info.msg", null, new ExactLevelFeedbackMessageFilter(FeedbackMessage.INFO)); + tester.assertComponentFeedbackMessage(label, "info.msg", null, + new ExactLevelFeedbackMessageFilter(FeedbackMessage.INFO)); } /** * WICKET-5389 reuse WicketTester after preceeding exception */ @Test - public void reuseAfterException() + void reuseAfterException() { try { @@ -1282,12 +1294,12 @@ public class WicketTesterTest extends WicketTestCase tester.startPage(new MockPageParameterPage(new PageParameters())); } - + /** * https://issues.apache.org/jira/browse/WICKET-5665 */ @Test - public void assertInvisibleComponentInAjaxResponse() + void assertInvisibleComponentInAjaxResponse() { MockPageWithLinkAndLabel page = new MockPageWithLinkAndLabel(); final Label label = new Label(MockPageWithLinkAndLabel.LABEL_ID, "Some text"); @@ -1317,7 +1329,8 @@ public class WicketTesterTest extends WicketTestCase * https://issues.apache.org/jira/browse/WICKET-6062 */ @Test - public void renewSessionIdAfterInvalidation() { + void renewSessionIdAfterInvalidation() + { tester.getApplication().setSessionStoreProvider(HttpSessionStore::new); tester.getSession().bind(); String firstId = tester.getSession().getId(); @@ -1329,7 +1342,7 @@ public class WicketTesterTest extends WicketTestCase } @Test - public void assertComponentInEnclosureInAjaxResponse() + void assertComponentInEnclosureInAjaxResponse() { MockPageWithLabelInEnclosure page = new MockPageWithLabelInEnclosure(); AjaxLink<Void> testLink = page.getSelfRefreshingAjaxLink(); @@ -1339,4 +1352,13 @@ public class WicketTesterTest extends WicketTestCase tester.assertComponentOnAjaxResponse(testLink); } + + public static class AlwaysRedirectPage extends WebPage + { + public AlwaysRedirectPage() + { + // redirects to another web server on the same computer + throw new RedirectToUrlException("http://localhost:4333/"); + } + } } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_1/CreateBook.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_1/CreateBook.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_1/CreateBook.java index 673d7c5..ed52918 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_1/CreateBook.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_1/CreateBook.java @@ -53,7 +53,7 @@ public class CreateBook extends WebPage * * @param id */ - public CreateForm(String id) + CreateForm(String id) { super(id); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_2/Test.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_2/Test.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_2/Test.java index 3124a4c..fc9a5b0 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_2/Test.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_2/Test.java @@ -24,13 +24,13 @@ import org.apache.wicket.util.tester.WicketTestCase; * * @author Juergen Donnerstag */ -public class Test extends WicketTestCase +class Test extends WicketTestCase { /** * */ - @org.junit.Test - public void testRedirect() + @org.junit.jupiter.api.Test + void testRedirect() { final IAuthorizationStrategy authorizationStrategy = new SimplePageAuthorizationStrategy( RedirectPage.class, LoginPage.class) @@ -42,9 +42,8 @@ public class Test extends WicketTestCase } }; - tester.getApplication() - .getSecuritySettings() - .setAuthorizationStrategy(authorizationStrategy); + tester.getApplication().getSecuritySettings().setAuthorizationStrategy( + authorizationStrategy); tester.startPage(RedirectPage.class); tester.assertRenderedPage(LoginPage.class); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_3/FormTesterTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_3/FormTesterTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_3/FormTesterTest.java index d5b9741..ff65101 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_3/FormTesterTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_3/FormTesterTest.java @@ -16,6 +16,11 @@ */ package org.apache.wicket.util.tester.apps_3; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Arrays; import java.util.List; @@ -23,14 +28,13 @@ import org.apache.wicket.WicketRuntimeException; import org.apache.wicket.util.tester.FormTester; import org.apache.wicket.util.tester.WicketTestCase; import org.apache.wicket.util.tester.apps_1.Book; -import org.junit.Before; -import org.junit.Test; - +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Ingram Chen */ -public class FormTesterTest extends WicketTestCase +class FormTesterTest extends WicketTestCase { private Book[] books; @@ -41,8 +45,8 @@ public class FormTesterTest extends WicketTestCase /** * */ - @Before - public void before() + @BeforeEach + void before() { books = new Book[] { new Book("1", "book1"), new Book("2", "book2"), new Book("3", "book3"), new Book("4", "book4") }; @@ -55,7 +59,7 @@ public class FormTesterTest extends WicketTestCase * @throws Exception */ @Test - public void singleChoice() throws Exception + void singleChoice() throws Exception { assertSame(books[1], choicePage.dropDownChoice); assertSame(books[3], choicePage.listChoice); @@ -76,7 +80,7 @@ public class FormTesterTest extends WicketTestCase * @throws Exception */ @Test - public void singleChoice_toggle() throws Exception + void singleChoice_toggle() throws Exception { assertSame(books[1], choicePage.dropDownChoice); assertSame(null, choicePage.radioGroup); @@ -93,7 +97,7 @@ public class FormTesterTest extends WicketTestCase * @throws Exception */ @Test - public void singleChoiceComponentNotAllowSelectMuliple() throws Exception + void singleChoiceComponentNotAllowSelectMuliple() throws Exception { try { @@ -118,7 +122,7 @@ public class FormTesterTest extends WicketTestCase * @throws Exception */ @Test - public void selectMultiple() throws Exception + void selectMultiple() throws Exception { assertBooksEquals(new Book[0], choicePage.listMultipleChoice); assertBooksEquals(new Book[0], choicePage.checkBoxMultipleChoice); @@ -138,7 +142,7 @@ public class FormTesterTest extends WicketTestCase * @throws Exception */ @Test - public void multipleChoiceComponent_cumulate() throws Exception + void multipleChoiceComponent_cumulate() throws Exception { assertBooksEquals(new Book[0], choicePage.listMultipleChoice); assertBooksEquals(new Book[0], choicePage.checkGroup); @@ -166,7 +170,7 @@ public class FormTesterTest extends WicketTestCase * @throws Exception */ @Test - public void multipleButtonSubmit() throws Exception + void multipleButtonSubmit() throws Exception { formTester.submit(); @@ -184,7 +188,7 @@ public class FormTesterTest extends WicketTestCase * Tests proper initialization. */ @Test - public void initialValues() + void initialValues() { assertInitialValues(); formTester.submit(); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_4/FormTesterTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_4/FormTesterTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_4/FormTesterTest.java index 61da3f7..8a4b12e 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_4/FormTesterTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_4/FormTesterTest.java @@ -16,25 +16,28 @@ */ package org.apache.wicket.util.tester.apps_4; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.List; import org.apache.wicket.feedback.FeedbackMessage; import org.apache.wicket.util.tester.FormTester; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Test; - +import org.junit.jupiter.api.Test; /** * @author Ingram Chen */ -public class FormTesterTest extends WicketTestCase +class FormTesterTest extends WicketTestCase { /** * @throws Exception */ @Test - public void test_1() throws Exception + void test_1() throws Exception { tester.startPage(EmailPage.class); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxLinkClickTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxLinkClickTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxLinkClickTest.java index 8077100..cf9a8e5 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxLinkClickTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxLinkClickTest.java @@ -16,6 +16,10 @@ */ package org.apache.wicket.util.tester.apps_5; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Optional; import org.apache.wicket.Page; @@ -23,16 +27,15 @@ import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxFallbackLink; import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Before; -import org.junit.Test; - +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test that the clickLink method also works with AjaxLinks * * @author Frank Bille */ -public class AjaxLinkClickTest extends WicketTestCase +class AjaxLinkClickTest extends WicketTestCase { private boolean linkClicked; private AjaxRequestTarget ajaxRequestTarget; @@ -40,8 +43,8 @@ public class AjaxLinkClickTest extends WicketTestCase /** * Make sure that our test flags are reset between every test. */ - @Before - public void before() + @BeforeEach + void before() { linkClicked = false; ajaxRequestTarget = null; @@ -51,7 +54,7 @@ public class AjaxLinkClickTest extends WicketTestCase * Test that an AjaxLink's onClick method is actually invoked. */ @Test - public void testBasicAjaxLinkClick() + void testBasicAjaxLinkClick() { // Create a link, which we test is actually invoked final AjaxLink<Void> ajaxLink = new AjaxLink<Void>("ajaxLink") @@ -82,7 +85,7 @@ public class AjaxLinkClickTest extends WicketTestCase * AjaxRequestTarget is not null. */ @Test - public void testAjaxFallbackLinkClick() + void testAjaxFallbackLinkClick() { final Page page = new MockPageWithLink(); @@ -110,7 +113,7 @@ public class AjaxLinkClickTest extends WicketTestCase * AjaxRequestTarget. */ @Test - public void testFallbackLinkWithAjaxDisabled() + void testFallbackLinkWithAjaxDisabled() { final Page page = new MockPageWithLink(); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxSubmitLinkClickTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxSubmitLinkClickTest.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxSubmitLinkClickTest.java index 6c1bec8..d482026 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxSubmitLinkClickTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_5/AjaxSubmitLinkClickTest.java @@ -16,29 +16,30 @@ */ package org.apache.wicket.util.tester.apps_5; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink; -import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.util.tester.WicketTestCase; import org.apache.wicket.util.tester.apps_5.MockPageWithFormAndLink.MockPojo; -import org.junit.Before; -import org.junit.Test; - +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Test that the clickLink method works with AjaxSubmitLinks * * @author Frank Bille */ -public class AjaxSubmitLinkClickTest extends WicketTestCase +class AjaxSubmitLinkClickTest extends WicketTestCase { private boolean linkClicked; /** * */ - @Before - public void before() + @BeforeEach + void before() { linkClicked = false; } @@ -47,7 +48,7 @@ public class AjaxSubmitLinkClickTest extends WicketTestCase * */ @Test - public void testClickLinkInsideForm_ajaxSubmitLink() + void testClickLinkInsideForm_ajaxSubmitLink() { MockPojo mockPojo = new MockPageWithFormAndLink.MockPojo(); mockPojo.setName("Mock name"); @@ -92,7 +93,7 @@ public class AjaxSubmitLinkClickTest extends WicketTestCase * */ @Test - public void testClickLink_ajaxSubmitLink() + void testClickLink_ajaxSubmitLink() { MockPojo mockPojo = new MockPageWithFormAndLink.MockPojo(); mockPojo.setName("Mock name"); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_7/TestHomePage.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_7/TestHomePage.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_7/TestHomePage.java index 13fd28d..1246034 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_7/TestHomePage.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_7/TestHomePage.java @@ -17,16 +17,16 @@ package org.apache.wicket.util.tester.apps_7; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Simple test using the WicketTester */ -public class TestHomePage extends WicketTestCase +class TestHomePage extends WicketTestCase { /** */ @Test - public void testAjaxSubmitWhileAnotherButtonIsNotVisible() + void testAjaxSubmitWhileAnotherButtonIsNotVisible() { // start and render the test page tester.startPage(HomePage.class); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_7/WicketApplication.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_7/WicketApplication.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_7/WicketApplication.java index b415adf..e5ab674 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_7/WicketApplication.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_7/WicketApplication.java @@ -24,7 +24,7 @@ import org.apache.wicket.protocol.http.WebApplication; * * @see com.mycompany.Start#main(String[]) */ -public class WicketApplication extends WebApplication +class WicketApplication extends WebApplication { /** * Constructor http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_8/TestResourceProvidingLabel.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_8/TestResourceProvidingLabel.java b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_8/TestResourceProvidingLabel.java index 3858cb8..b3a30ca 100644 --- a/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_8/TestResourceProvidingLabel.java +++ b/wicket-core/src/test/java/org/apache/wicket/util/tester/apps_8/TestResourceProvidingLabel.java @@ -22,7 +22,7 @@ import org.apache.wicket.markup.html.basic.Label; * A simple Label that renders some Feedback Messages. * @author Martin Dilger */ -public class TestResourceProvidingLabel extends Label +class TestResourceProvidingLabel extends Label { public TestResourceProvidingLabel(String id) { http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/validation/CompoundValidatorTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/validation/CompoundValidatorTest.java b/wicket-core/src/test/java/org/apache/wicket/validation/CompoundValidatorTest.java index 22091e5..5e5fe50 100644 --- a/wicket-core/src/test/java/org/apache/wicket/validation/CompoundValidatorTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/validation/CompoundValidatorTest.java @@ -18,20 +18,20 @@ package org.apache.wicket.validation; import org.apache.wicket.Component; import org.apache.wicket.validation.validator.RangeValidator; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; /** * Test for {@link CompoundValidator}. */ -public class CompoundValidatorTest +class CompoundValidatorTest { /** * WICKET-6482 delegate to nested behaviors */ @SuppressWarnings("unchecked") @Test - public void delegate() { + void delegate() { CompoundValidator<String> compound = new CompoundValidator<>(); compound.add(new IValidator<String>() http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/validation/ValidationErrorTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/validation/ValidationErrorTest.java b/wicket-core/src/test/java/org/apache/wicket/validation/ValidationErrorTest.java index 824b591..496aad1 100644 --- a/wicket-core/src/test/java/org/apache/wicket/validation/ValidationErrorTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/validation/ValidationErrorTest.java @@ -16,28 +16,27 @@ */ package org.apache.wicket.validation; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.Serializable; import java.util.Map; import org.apache.wicket.markup.html.form.ValidationErrorFeedback; -import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * {@link ValidationError} related tests * * @author igor */ -public class ValidationErrorTest +class ValidationErrorTest { /** * tests standard key values */ @Test - public void standardKeys() + void standardKeys() { ValidationError e = new ValidationError(); e.addKey(new TestValidator()); @@ -77,12 +76,12 @@ public class ValidationErrorTest } @Test - public void calculateMessageWithoutKeys() + void calculateMessageWithoutKeys() { String message = "foo message"; ValidationError error = new ValidationError(message); Serializable errorMessage = error.getErrorMessage(new TestMessageSource()); - assertThat(errorMessage, Matchers.instanceOf(ValidationErrorFeedback.class)); + assertThat(errorMessage).isInstanceOf(ValidationErrorFeedback.class); ValidationErrorFeedback vef = (ValidationErrorFeedback) errorMessage; assertEquals(message, vef.getMessage()); } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/validation/ValidatorBehaviorTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/validation/ValidatorBehaviorTest.java b/wicket-core/src/test/java/org/apache/wicket/validation/ValidatorBehaviorTest.java index ea8093b..0973203 100644 --- a/wicket-core/src/test/java/org/apache/wicket/validation/ValidatorBehaviorTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/validation/ValidatorBehaviorTest.java @@ -16,6 +16,10 @@ */ package org.apache.wicket.validation; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.apache.wicket.Component; import org.apache.wicket.MarkupContainer; import org.apache.wicket.behavior.Behavior; @@ -30,21 +34,21 @@ import org.apache.wicket.util.resource.IResourceStream; import org.apache.wicket.util.resource.StringResourceStream; import org.apache.wicket.util.tester.FormTester; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests validator work as validators and behaviors * * @author igor */ -public class ValidatorBehaviorTest extends WicketTestCase +class ValidatorBehaviorTest extends WicketTestCase { /** * Tests validators are treated as behaviors */ @Test - public void actAsBehavior() + void actAsBehavior() { TestPage page = new TestPage(); @@ -67,7 +71,7 @@ public class ValidatorBehaviorTest extends WicketTestCase * https://issues.apache.org/jira/browse/WICKET-5897 */ @Test - public void disabledValidator() + void disabledValidator() { TestPage page = new TestPage(); page.name.add(new DisabledValidator()); @@ -87,7 +91,7 @@ public class ValidatorBehaviorTest extends WicketTestCase * Tests validators are treated as validators */ @Test - public void actAsValidator() + void actAsValidator() { TestPage page = new TestPage(); @@ -205,7 +209,7 @@ public class ValidatorBehaviorTest extends WicketTestCase /** * Construct. */ - public TestPage() + TestPage() { Form<Void> form = new Form<>("form"); add(form);
