http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInConstructorPanel.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInConstructorPanel.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInConstructorPanel.java index d96fa89..07cf77c 100644 --- a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInConstructorPanel.java +++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInConstructorPanel.java @@ -19,7 +19,7 @@ package org.apache.wicket.component.replacewith; /** * A panel that uses #replaceWith in #onBeforeRender */ -public class ReplaceInConstructorPanel extends BaseReplaceWithPanel +class ReplaceInConstructorPanel extends BaseReplaceWithPanel { public ReplaceInConstructorPanel(String id) {
http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnBeforeRenderPanel.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnBeforeRenderPanel.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnBeforeRenderPanel.java index 26998e6..c0aa2ea 100644 --- a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnBeforeRenderPanel.java +++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnBeforeRenderPanel.java @@ -19,7 +19,7 @@ package org.apache.wicket.component.replacewith; /** * A panel that uses #replaceWith in #onBeforeRender */ -public class ReplaceInOnBeforeRenderPanel extends BaseReplaceWithPanel +class ReplaceInOnBeforeRenderPanel extends BaseReplaceWithPanel { public ReplaceInOnBeforeRenderPanel(String id) { http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnConfigurePanel.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnConfigurePanel.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnConfigurePanel.java index d5fa364..836ba4b 100644 --- a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnConfigurePanel.java +++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnConfigurePanel.java @@ -19,7 +19,7 @@ package org.apache.wicket.component.replacewith; /** * A panel that uses #replaceWith in #onBeforeRender */ -public class ReplaceInOnConfigurePanel extends BaseReplaceWithPanel +class ReplaceInOnConfigurePanel extends BaseReplaceWithPanel { public ReplaceInOnConfigurePanel(String id) { http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnInitializePanel.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnInitializePanel.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnInitializePanel.java index a89edbd..83c481b 100644 --- a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnInitializePanel.java +++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceInOnInitializePanel.java @@ -19,7 +19,7 @@ package org.apache.wicket.component.replacewith; /** * A panel that uses #replaceWith in #onInitialize */ -public class ReplaceInOnInitializePanel extends BaseReplaceWithPanel +class ReplaceInOnInitializePanel extends BaseReplaceWithPanel { public ReplaceInOnInitializePanel(String id) { http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceWithTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceWithTest.java b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceWithTest.java index 71a2e31..437fc2e 100644 --- a/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceWithTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/component/replacewith/ReplaceWithTest.java @@ -16,24 +16,23 @@ */ package org.apache.wicket.component.replacewith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; /** * Tests for Component#replaceWith() method */ -public class ReplaceWithTest extends WicketTestCase +class ReplaceWithTest extends WicketTestCase { - @Rule - public ExpectedException expectedException = ExpectedException.none(); /** * https://issues.apache.org/jira/browse/WICKET-5417 */ @Test - public void replaceWithInOnInitialize() + void replaceWithInOnInitialize() { HomePage page = new HomePage(); page.add(new ReplaceInOnInitializePanel("panel")); @@ -46,7 +45,7 @@ public class ReplaceWithTest extends WicketTestCase * https://issues.apache.org/jira/browse/WICKET-5417 */ @Test - public void replaceWithInOnBeforeRender() + void replaceWithInOnBeforeRender() { HomePage page = new HomePage(); page.add(new ReplaceInOnBeforeRenderPanel("panel")); @@ -59,7 +58,7 @@ public class ReplaceWithTest extends WicketTestCase * https://issues.apache.org/jira/browse/WICKET-5417 */ @Test - public void replaceWithInOnConfigure() + void replaceWithInOnConfigure() { HomePage page = new HomePage(); page.add(new ReplaceInOnConfigurePanel("panel")); @@ -72,14 +71,16 @@ public class ReplaceWithTest extends WicketTestCase * https://issues.apache.org/jira/browse/WICKET-5417 */ @Test - public void replaceWithInConstructor() + void replaceWithInConstructor() { HomePage page = new HomePage(); - expectedException.expect(IllegalStateException.class); - expectedException. - expectMessage("This method can only be called on a component that has already been added to its parent."); + Exception e = assertThrows(IllegalStateException.class, () -> { + page.add(new ReplaceInConstructorPanel("panel")); + }); - page.add(new ReplaceInConstructorPanel("panel")); + assertEquals( + "This method can only be called on a component that has already been added to its parent.", + e.getMessage()); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/core/request/handler/ListenerRequestHandlerTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/core/request/handler/ListenerRequestHandlerTest.java b/wicket-core/src/test/java/org/apache/wicket/core/request/handler/ListenerRequestHandlerTest.java index b8bd401..23a4e4b 100644 --- a/wicket-core/src/test/java/org/apache/wicket/core/request/handler/ListenerRequestHandlerTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/core/request/handler/ListenerRequestHandlerTest.java @@ -16,7 +16,10 @@ */ package org.apache.wicket.core.request.handler; -import static org.hamcrest.Matchers.is; +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 static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.text.ParseException; @@ -32,7 +35,6 @@ import org.apache.wicket.markup.IMarkupFragment; import org.apache.wicket.markup.IMarkupResourceStreamProvider; import org.apache.wicket.markup.Markup; import org.apache.wicket.markup.html.WebPage; -import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.html.link.StatelessLink; import org.apache.wicket.request.Url; import org.apache.wicket.request.mapper.parameter.PageParameters; @@ -41,7 +43,7 @@ import org.apache.wicket.util.resource.IResourceStream; import org.apache.wicket.util.resource.ResourceStreamNotFoundException; import org.apache.wicket.util.resource.StringResourceStream; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link ListenerRequestHandler} @@ -53,20 +55,18 @@ public class ListenerRequestHandlerTest extends WicketTestCase * WICKET-5466 */ @Test - public void removedComponent() + void removedComponent() { // non-existing component on fresh page is ignored PageAndComponentProvider freshPage = new PageAndComponentProvider(DummyPage.class, null, "foo"); - new ListenerRequestHandler(freshPage).respond(tester - .getRequestCycle()); + new ListenerRequestHandler(freshPage).respond(tester.getRequestCycle()); // non-existing component on old page fails PageAndComponentProvider oldPage = new PageAndComponentProvider(new DummyPage(), "foo"); try { - new ListenerRequestHandler(oldPage) - .respond(tester.getRequestCycle()); + new ListenerRequestHandler(oldPage).respond(tester.getRequestCycle()); fail(); } catch (WicketRuntimeException ex) @@ -81,7 +81,7 @@ public class ListenerRequestHandlerTest extends WicketTestCase * @throws Exception */ @Test - public void recreateThePageWhenListenereInterfaceIsExecutedOnExpiredPage() throws Exception + void recreateThePageWhenListenereInterfaceIsExecutedOnExpiredPage() throws Exception { tester.getApplication().mountPage("ajaxLink", AjaxLinkExpirePage.class); AjaxLinkExpirePage page = tester.startPage(AjaxLinkExpirePage.class); @@ -97,11 +97,11 @@ public class ListenerRequestHandlerTest extends WicketTestCase Page lastRenderedPage = tester.getLastRenderedPage(); int lastRenderedPageId = lastRenderedPage.getPageId(); - assertTrue("A new page must be create ", lastRenderedPageId > initialPageId); + assertTrue(lastRenderedPageId > initialPageId, "A new page must be create "); } - private void executeAjaxUrlWithLastBaseUrl(Url url) throws IOException, - ResourceStreamNotFoundException, ParseException + private void executeAjaxUrlWithLastBaseUrl(Url url) + throws IOException, ResourceStreamNotFoundException, ParseException { tester.getRequest().setUrl(url); tester.getRequest().addHeader("Wicket-Ajax-BaseURL", @@ -111,6 +111,43 @@ public class ListenerRequestHandlerTest extends WicketTestCase } /** + * Testcase for WICKET-4185 + */ + @Test + void isPageInstanceCreatedOnClassLinks() + { + PageAndComponentProvider provider = new PageAndComponentProvider(Page.class, "link"); + ListenerRequestHandler handler = new ListenerRequestHandler(provider); + assertFalse(handler.isPageInstanceCreated(), "A new page must be create "); + } + + @Test + void executeStatelessLinkInAFreshPage() + { + tester.startPage(StatelessPage.class); + + tester.clickLink("statelessLink"); + + StatelessPage page = (StatelessPage)tester.getLastRenderedPage(); + assertTrue(page.invoked); + assertTrue(page.executedInAnFreshPage); + } + + @Test + void executeStatelessLinkInAFreshPageAtASegment() + { + tester.getApplication().getRootRequestMapperAsCompound().add( + new MountedMapper("/segment", TemporarilyStateful.class)); + tester.startPage(TemporarilyStateful.class); + + tester.clickLink("statelessLink"); + + TemporarilyStateful page = (TemporarilyStateful)tester.getLastRenderedPage(); + assertTrue(page.invoked); + assertTrue(page.executedInAnFreshPage); + } + + /** * Test page for #recreateThePageWhenListenereInterfaceIsExecutedOnExpiredPage() */ public static class AjaxLinkExpirePage extends WebPage implements IMarkupResourceStreamProvider @@ -147,47 +184,10 @@ public class ListenerRequestHandlerTest extends WicketTestCase } - /** - * Testcase for WICKET-4185 - */ - @Test - public void isPageInstanceCreatedOnClassLinks() - { - PageAndComponentProvider provider = new PageAndComponentProvider(Page.class, "link"); - ListenerRequestHandler handler = new ListenerRequestHandler(provider); - assertFalse("Handler should not report a page instance is available ", - handler.isPageInstanceCreated()); - } - - @Test - public void executeStatelessLinkInAFreshPage() - { - tester.startPage(StatelessPage.class); - - tester.clickLink("statelessLink"); - - StatelessPage page = (StatelessPage)tester.getLastRenderedPage(); - assertThat(page.invoked, is(true)); - assertThat(page.executedInAnFreshPage, is(true)); - } - - @Test - public void executeStatelessLinkInAFreshPageAtASegment() - { - tester.getApplication().getRootRequestMapperAsCompound() .add(new MountedMapper("/segment", TemporarilyStateful.class)); - tester.startPage(TemporarilyStateful.class); - - tester.clickLink("statelessLink"); - - TemporarilyStateful page = (TemporarilyStateful)tester.getLastRenderedPage(); - assertThat(page.invoked, is(true)); - assertThat(page.executedInAnFreshPage, is(true)); - } - public static class StatelessPage extends WebPage { - public boolean invoked; - public boolean executedInAnFreshPage; + boolean invoked; + boolean executedInAnFreshPage; private boolean initialState = true; public StatelessPage(PageParameters pageParameters) @@ -206,8 +206,7 @@ public class ListenerRequestHandlerTest extends WicketTestCase @Override public IMarkupFragment getMarkup() { - return Markup.of( - "<html><body><a wicket:id=\"statelessLink\"></a></body></html>"); + return Markup.of("<html><body><a wicket:id=\"statelessLink\"></a></body></html>"); } @Override http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapperTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapperTest.java b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapperTest.java index b91873b..3af1c62 100644 --- a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapperTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractBookmarkableMapperTest.java @@ -16,6 +16,8 @@ */ package org.apache.wicket.core.request.mapper; +import static org.junit.jupiter.api.Assertions.assertThrows; + import org.apache.wicket.MockPage; import org.apache.wicket.Page; import org.apache.wicket.RestartResponseAtInterceptPageException; @@ -28,13 +30,12 @@ import org.apache.wicket.request.Url; import org.apache.wicket.request.mapper.info.PageInfo; import org.apache.wicket.util.tester.WicketTestCase; import org.apache.wicket.util.tester.WicketTesterLazyIsPageStatelessRedirectToBufferTest.EmptyPage; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author pedrosans */ -public class AbstractBookmarkableMapperTest extends WicketTestCase +class AbstractBookmarkableMapperTest extends WicketTestCase { private static final int NOT_RENDERED_COUNT = 2; @@ -51,8 +52,8 @@ public class AbstractBookmarkableMapperTest extends WicketTestCase { super.init(); - getSecuritySettings().setAuthorizationStrategy( - new AbstractPageAuthorizationStrategy() + getSecuritySettings() + .setAuthorizationStrategy(new AbstractPageAuthorizationStrategy() { @Override protected <T extends Page> boolean isPageAuthorized(Class<T> pageClass) @@ -67,31 +68,34 @@ public class AbstractBookmarkableMapperTest extends WicketTestCase } }; } - + /** * <a href="https://issues.apache.org/jira/browse/WICKET-4932">WICKET-4932</a> */ - @Test(expected = PageExpiredException.class) - public void itFailsToProcessAnExpiredPageIfShouldNotRecreateMountedPagesAfterExpiry() + @Test + void itFailsToProcessAnExpiredPageIfShouldNotRecreateMountedPagesAfterExpiry() { - tester.getApplication().getPageSettings().setRecreateBookmarkablePagesAfterExpiry(false); - AbstractBookmarkableMapperStub mapper = new AbstractBookmarkableMapperStub(); - mapper.processHybrid(new PageInfo(EXPIRED_ID), MockPage.class, null, NOT_RENDERED_COUNT); - Assert.fail("it shouldn't process expired pages if the app was flagged to not recreated mounted pages after expiry"); + assertThrows(PageExpiredException.class, () -> { + tester.getApplication().getPageSettings().setRecreateBookmarkablePagesAfterExpiry( + false); + AbstractBookmarkableMapperStub mapper = new AbstractBookmarkableMapperStub(); + mapper.processHybrid(new PageInfo(EXPIRED_ID), MockPage.class, null, + NOT_RENDERED_COUNT); + }); } - + /** * <a href="https://issues.apache.org/jira/browse/WICKET-5734">WICKET-5734</a> */ @Test - public void testProcessHybridWithAuthorizationException() throws Exception + void testProcessHybridWithAuthorizationException() throws Exception { AbstractBookmarkableMapperStub mapper = new AbstractBookmarkableMapperStub(); mapper.processHybrid(new PageInfo(), EmptyPage.class, null, 0); } - + /** */ - public class AbstractBookmarkableMapperStub extends AbstractBookmarkableMapper + class AbstractBookmarkableMapperStub extends AbstractBookmarkableMapper { @Override http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractMapperTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractMapperTest.java b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractMapperTest.java index d2022a8..5e68178 100644 --- a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractMapperTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractMapperTest.java @@ -16,29 +16,30 @@ */ package org.apache.wicket.core.request.mapper; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.nio.charset.Charset; import java.util.Locale; import org.apache.wicket.request.Request; import org.apache.wicket.request.Url; import org.apache.wicket.request.component.IRequestablePage; -import org.junit.Assert; /** * @author Matej Knopp */ -public abstract class AbstractMapperTest extends Assert +abstract class AbstractMapperTest { /** * Construct. */ - public AbstractMapperTest() + AbstractMapperTest() { } - protected TestMapperContext context = new TestMapperContext(); + TestMapperContext context = new TestMapperContext(); - protected Request getRequest(final Url url) + Request getRequest(final Url url) { return new Request() { @@ -74,7 +75,7 @@ public abstract class AbstractMapperTest extends Assert }; } - protected void checkPage(IRequestablePage page, int id) + void checkPage(IRequestablePage page, int id) { assertEquals(id, page.getPageId()); } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperOwnTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperOwnTest.java b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperOwnTest.java index 1345687..104d2f9 100644 --- a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperOwnTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperOwnTest.java @@ -16,20 +16,21 @@ */ package org.apache.wicket.core.request.mapper; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.apache.wicket.request.IRequestHandler; import org.apache.wicket.request.Request; import org.apache.wicket.request.Url; import org.apache.wicket.resource.ResourceUtil; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for AbstractResourceReferenceMapper's own methods */ -public class AbstractResourceReferenceMapperOwnTest extends Assert +class AbstractResourceReferenceMapperOwnTest { @Test - public void testEscapeAttributesSeparator() throws Exception + void testEscapeAttributesSeparator() throws Exception { AbstractResourceReferenceMapper mapper = new Mapper(); CharSequence escaped = ResourceUtil.escapeAttributesSeparator("my-style~is~~cool"); @@ -37,7 +38,7 @@ public class AbstractResourceReferenceMapperOwnTest extends Assert } @Test - public void testUnescapeAttributesSeparator() throws Exception + void testUnescapeAttributesSeparator() throws Exception { AbstractResourceReferenceMapper mapper = new Mapper(); CharSequence escaped = ResourceUtil.unescapeAttributesSeparator("my~style~~is~~~~cool"); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperTest.java b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperTest.java index da486dc..ee66792 100644 --- a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/AbstractResourceReferenceMapperTest.java @@ -20,7 +20,7 @@ import java.util.Locale; import org.apache.wicket.request.resource.IResource; import org.apache.wicket.request.resource.ResourceReference; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; /** * @author Matej Knopp @@ -30,11 +30,11 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper /** * Construct. */ - public AbstractResourceReferenceMapperTest() + AbstractResourceReferenceMapperTest() { } - protected final IResource resource1 = new IResource() + final IResource resource1 = new IResource() { private static final long serialVersionUID = 1L; @@ -44,7 +44,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected final IResource resource2 = new IResource() + final IResource resource2 = new IResource() { private static final long serialVersionUID = 1L; @@ -54,7 +54,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected final IResource resource3 = new IResource() + final IResource resource3 = new IResource() { private static final long serialVersionUID = 1L; @@ -64,7 +64,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected final IResource resource4 = new IResource() + final IResource resource4 = new IResource() { private static final long serialVersionUID = 1L; @@ -74,7 +74,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected final IResource resource5 = new IResource() + final IResource resource5 = new IResource() { private static final long serialVersionUID = 1L; @@ -84,7 +84,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected final IResource resource6 = new IResource() + final IResource resource6 = new IResource() { private static final long serialVersionUID = 1L; @@ -94,9 +94,9 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected String CLASS_NAME = AbstractResourceReferenceMapperTest.class.getName(); + String CLASS_NAME = AbstractResourceReferenceMapperTest.class.getName(); - protected ResourceReference reference1 = new ResourceReference( + ResourceReference reference1 = new ResourceReference( AbstractResourceReferenceMapperTest.class, "reference1", null, null, null) { private static final long serialVersionUID = 1L; @@ -108,7 +108,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected ResourceReference reference1_a = new ResourceReference( + private ResourceReference reference1_a = new ResourceReference( AbstractResourceReferenceMapperTest.class, "reference1", Locale.ENGLISH, null, null) { private static final long serialVersionUID = 1L; @@ -120,7 +120,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected ResourceReference reference1_b = new ResourceReference( + private ResourceReference reference1_b = new ResourceReference( AbstractResourceReferenceMapperTest.class, "reference1", null, "style", null) { private static final long serialVersionUID = 1L; @@ -132,7 +132,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected ResourceReference reference2 = new ResourceReference( + ResourceReference reference2 = new ResourceReference( AbstractResourceReferenceMapperTest.class, "reference2/name2", new Locale("en", "en"), null, null) { @@ -145,7 +145,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected ResourceReference reference2_a = new ResourceReference( + private ResourceReference reference2_a = new ResourceReference( AbstractResourceReferenceMapperTest.class, "reference2/name2", new Locale("en", "en"), "style", null) { @@ -158,7 +158,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected ResourceReference reference3 = new ResourceReference( + ResourceReference reference3 = new ResourceReference( AbstractResourceReferenceMapperTest.class, "reference3", null, "style", null) { private static final long serialVersionUID = 1L; @@ -170,7 +170,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected ResourceReference reference4 = new ResourceReference( + ResourceReference reference4 = new ResourceReference( AbstractResourceReferenceMapperTest.class, "reference4", Locale.ENGLISH, "style", null) { private static final long serialVersionUID = 1L; @@ -182,7 +182,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected ResourceReference reference5 = new ResourceReference( + ResourceReference reference5 = new ResourceReference( AbstractResourceReferenceMapperTest.class, "reference5", Locale.ENGLISH, null, "variation") { private static final long serialVersionUID = 1L; @@ -194,7 +194,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - protected ResourceReference reference6 = new ResourceReference( + private ResourceReference reference6 = new ResourceReference( AbstractResourceReferenceMapperTest.class, "reference6", Locale.ENGLISH, "style", "variation") { @@ -207,7 +207,7 @@ public abstract class AbstractResourceReferenceMapperTest extends AbstractMapper } }; - @Before + @BeforeEach public void before() throws Exception { context.getResourceReferenceRegistry().registerResourceReference(reference1); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/BasicResourceReferenceMapperTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/BasicResourceReferenceMapperTest.java b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/BasicResourceReferenceMapperTest.java index 00e3734..def27a4 100644 --- a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/BasicResourceReferenceMapperTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/BasicResourceReferenceMapperTest.java @@ -16,8 +16,9 @@ */ package org.apache.wicket.core.request.mapper; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.Matchers.is; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.Serializable; import java.util.Locale; @@ -41,12 +42,12 @@ import org.apache.wicket.util.ValueProvider; import org.apache.wicket.util.lang.Args; import org.apache.wicket.util.resource.IResourceStream; import org.apache.wicket.util.resource.StringResourceStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Matej Knopp */ -public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceMapperTest +class BasicResourceReferenceMapperTest extends AbstractResourceReferenceMapperTest { private static final Supplier<IResourceCachingStrategy> NO_CACHING = new ValueProvider<>( NoOpResourceCachingStrategy.INSTANCE); @@ -65,11 +66,11 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode1() + void decode1() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference1"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource1, h.getResource()); assertEquals(0, h.getPageParameters().getIndexedCount()); @@ -80,16 +81,16 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode1A() + void decode1A() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference1?en"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + // assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); // TODO use hamcrest or assertj ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource1, h.getResource()); assertEquals(Locale.ENGLISH, h.getLocale()); - assertEquals(null, h.getStyle()); - assertEquals(null, h.getVariation()); + assertNull(h.getStyle()); + assertNull(h.getVariation()); assertEquals(0, h.getPageParameters().getIndexedCount()); assertEquals(0, h.getPageParameters().getNamedKeys().size()); } @@ -98,16 +99,16 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode2() + void decode2() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference1?p1=v1&p2=v2"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource1, h.getResource()); - assertEquals(null, h.getLocale()); - assertEquals(null, h.getStyle()); - assertEquals(null, h.getVariation()); + assertNull(h.getLocale()); + assertNull(h.getStyle()); + assertNull(h.getVariation()); assertEquals(0, h.getPageParameters().getIndexedCount()); assertEquals("v1", h.getPageParameters().get("p1").toString()); assertEquals("v2", h.getPageParameters().get("p2").toString()); @@ -117,16 +118,16 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode2A() + void decode2A() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference1?-style&p1=v1&p2=v2"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource1, h.getResource()); - assertEquals(null, h.getLocale()); + assertNull(h.getLocale()); assertEquals("style", h.getStyle()); - assertEquals(null, h.getVariation()); + assertNull(h.getVariation()); assertEquals(0, h.getPageParameters().getIndexedCount()); assertEquals("v1", h.getPageParameters().get("p1").toString()); assertEquals("v2", h.getPageParameters().get("p2").toString()); @@ -136,16 +137,17 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode3() + void decode3() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference2/name2?en_EN"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource2, h.getResource()); assertEquals(new Locale("en", "en"), h.getLocale()); - assertEquals(null, h.getStyle()); - assertEquals(null, h.getVariation()); + assertNull(h.getStyle()); + assertNull(h.getVariation()); assertEquals(0, h.getPageParameters().getIndexedCount()); assertEquals(0, h.getPageParameters().getNamedKeys().size()); } @@ -154,16 +156,16 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode3A() + void decode3A() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference2/name2?en_EN-style"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource2, h.getResource()); assertEquals(new Locale("en", "en"), h.getLocale()); assertEquals("style", h.getStyle()); - assertEquals(null, h.getVariation()); + assertNull(h.getVariation()); assertEquals(0, h.getPageParameters().getIndexedCount()); assertEquals(0, h.getPageParameters().getNamedKeys().size()); } @@ -172,7 +174,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode3B() + void decode3B() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference2/name2"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); @@ -183,17 +185,17 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode4() + void decode4() { Url url = Url .parse("wicket/resource/" + CLASS_NAME + "/reference2/name2?en_EN&p1=v1&p2=v2"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource2, h.getResource()); assertEquals(new Locale("en", "en"), h.getLocale()); - assertEquals(null, h.getStyle()); - assertEquals(null, h.getVariation()); + assertNull(h.getStyle()); + assertNull(h.getVariation()); assertEquals("v1", h.getPageParameters().get("p1").toString()); assertEquals("v2", h.getPageParameters().get("p2").toString()); } @@ -202,16 +204,16 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode5() + void decode5() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference3?-style"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource3, h.getResource()); - assertEquals(null, h.getLocale()); + assertNull(h.getLocale()); assertEquals("style", h.getStyle()); - assertEquals(null, h.getVariation()); + assertNull(h.getVariation()); assertEquals(0, h.getPageParameters().getIndexedCount()); assertEquals(0, h.getPageParameters().getNamedKeys().size()); } @@ -220,16 +222,16 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode6() + void decode6() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference3?-style&p1=v1&p2=v2"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource3, h.getResource()); - assertEquals(null, h.getLocale()); + assertNull(h.getLocale()); assertEquals("style", h.getStyle()); - assertEquals(null, h.getVariation()); + assertNull(h.getVariation()); assertEquals(0, h.getPageParameters().getIndexedCount()); assertEquals("v1", h.getPageParameters().get("p1").toString()); assertEquals("v2", h.getPageParameters().get("p2").toString()); @@ -240,16 +242,16 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode7() + void decode7() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference4?en-style"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource4, h.getResource()); assertEquals(Locale.ENGLISH, h.getLocale()); assertEquals("style", h.getStyle()); - assertEquals(null, h.getVariation()); + assertNull(h.getVariation()); assertEquals(0, h.getPageParameters().getIndexedCount()); assertEquals(0, h.getPageParameters().getNamedKeys().size()); } @@ -258,7 +260,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode7A() + void decode7A() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference4?sk"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); @@ -269,16 +271,16 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode8() + void decode8() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference4?en-style&p1=v1&p2=v2"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource4, h.getResource()); assertEquals(Locale.ENGLISH, h.getLocale()); assertEquals("style", h.getStyle()); - assertEquals(null, h.getVariation()); + assertNull(h.getVariation()); assertEquals(0, h.getPageParameters().getIndexedCount()); assertEquals("v1", h.getPageParameters().get("p1").toString()); assertEquals("v2", h.getPageParameters().get("p2").toString()); @@ -288,16 +290,16 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode9() + void decode9() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference5?en--variation&p1=v1&p2=v2"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource5, h.getResource()); assertEquals(Locale.ENGLISH, h.getLocale()); - assertEquals(null, h.getStyle()); + assertNull(h.getStyle()); assertEquals("variation", h.getVariation()); assertEquals(0, h.getPageParameters().getIndexedCount()); assertEquals("v1", h.getPageParameters().get("p1").toString()); @@ -308,12 +310,12 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void decode10() + void decode10() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/reference6?en-style-variation&p1=v1&p2=v2"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ResourceReferenceRequestHandler.class)); + assertThat(handler).isInstanceOf(ResourceReferenceRequestHandler.class); ResourceReferenceRequestHandler h = (ResourceReferenceRequestHandler)handler; assertEquals(resource6, h.getResource()); assertEquals(Locale.ENGLISH, h.getLocale()); @@ -328,18 +330,18 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * https://issues.apache.org/jira/browse/WICKET-5673 */ @Test - public void decode11() + void decode11() { Url url = Url.parse("wicket/resource/com.example.Scope/"); int score = encoder.getCompatibilityScore(getRequest(url)); - assertThat(score, is(-1)); + assertEquals(-1, score); } /** * */ @Test - public void encode1() + void encode1() { ResourceReferenceRequestHandler handler = new ResourceReferenceRequestHandler(reference1, null); @@ -351,7 +353,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void encode2() + void encode2() { PageParameters parameters = new PageParameters(); parameters.set(0, "X"); @@ -368,7 +370,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void encode3() + void encode3() { ResourceReferenceRequestHandler handler = new ResourceReferenceRequestHandler(reference2, null); @@ -380,7 +382,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void encode4() + void encode4() { PageParameters parameters = new PageParameters(); parameters.set(0, "X"); @@ -398,7 +400,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void encode5() + void encode5() { ResourceReferenceRequestHandler handler = new ResourceReferenceRequestHandler(reference3, null); @@ -410,7 +412,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void encode6() + void encode6() { PageParameters parameters = new PageParameters(); parameters.set(0, "X"); @@ -428,7 +430,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void encode7() + void encode7() { ResourceReferenceRequestHandler handler = new ResourceReferenceRequestHandler(reference4, null); @@ -440,7 +442,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void encode8() + void encode8() { PageParameters parameters = new PageParameters(); parameters.set(0, "X"); @@ -458,7 +460,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * Tests request to url encoding when style is null but variation is not */ @Test - public void encode9() + void encode9() { ResourceReferenceRequestHandler handler = new ResourceReferenceRequestHandler(reference5, null); @@ -471,7 +473,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void versionStringInResourceFilename() + void versionStringInResourceFilename() { final IStaticCacheableResource resource = new IStaticCacheableResource() { @@ -565,7 +567,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * @param version * static version string to deliver for all queries resources */ - public AlphaDigitResourceVersion(String version) + AlphaDigitResourceVersion(String version) { this.version = Args.notNull(version, "version"); } @@ -587,7 +589,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * */ @Test - public void requestWithEmptyFilename() + void requestWithEmptyFilename() { Url url = Url.parse("wicket/resource/" + CLASS_NAME + "/"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); @@ -598,7 +600,7 @@ public class BasicResourceReferenceMapperTest extends AbstractResourceReferenceM * Tests <a href="https://issues.apache.org/jira/browse/WICKET-3918">WICKET-3918</a>. */ @Test - public void wicket3918() + void wicket3918() { Url url = Url .parse("wicket/resource/org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow/res/"); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/BookmarkableMapperTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/BookmarkableMapperTest.java b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/BookmarkableMapperTest.java index b08ca4c..0482352 100644 --- a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/BookmarkableMapperTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/BookmarkableMapperTest.java @@ -16,9 +16,12 @@ */ package org.apache.wicket.core.request.mapper; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.Matchers.is; +import static org.assertj.core.api.Assertions.assertThat; +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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.charset.Charset; import java.util.Locale; @@ -39,12 +42,12 @@ import org.apache.wicket.request.component.IRequestableComponent; import org.apache.wicket.request.component.IRequestablePage; import org.apache.wicket.request.mapper.parameter.INamedParameters; import org.apache.wicket.request.mapper.parameter.PageParameters; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Matej Knopp */ -public class BookmarkableMapperTest extends AbstractMapperTest +class BookmarkableMapperTest extends AbstractMapperTest { private final BookmarkableMapper encoder = new BookmarkableMapper() @@ -68,12 +71,12 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void decode1() + void decode1() { Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(RenderPageRequestHandler.class)); + assertThat(handler).isInstanceOf(RenderPageRequestHandler.class); IRequestablePage page = ((RenderPageRequestHandler)handler).getPage(); assertEquals(PAGE_CLASS_NAME, page.getClass().getName()); assertEquals(0, page.getPageParameters().getIndexedCount()); @@ -84,7 +87,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * https://issues.apache.org/jira/browse/WICKET-5500 */ @Test - public void decodePageClassWithPathParameters() + void decodePageClassWithPathParameters() { Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + ";something=else"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); @@ -100,12 +103,11 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void decode2() + void decode2() { Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/indexed1?a=b&b=c"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - - assertThat(handler, instanceOf(RenderPageRequestHandler.class)); + assertThat(handler).isInstanceOf(RenderPageRequestHandler.class); IRequestablePage page = ((RenderPageRequestHandler)handler).getPage(); assertEquals(PAGE_CLASS_NAME, page.getClass().getName()); @@ -126,12 +128,12 @@ public class BookmarkableMapperTest extends AbstractMapperTest * nor in the query string) so the resolved page is assumed to be valid. */ @Test - public void decode3() + void decode3() { Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + "?15"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(RenderPageRequestHandler.class)); + assertThat(handler).isInstanceOf(RenderPageRequestHandler.class); IRequestablePage page = ((RenderPageRequestHandler)handler).getPage(); checkPage(page, 15); } @@ -151,12 +153,12 @@ public class BookmarkableMapperTest extends AbstractMapperTest * then Wicket will create a new page that will show product=24 */ @Test - public void decode4() + void decode4() { Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/i1/i2?15&a=b&b=c"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(RenderPageRequestHandler.class)); + assertThat(handler).isInstanceOf(RenderPageRequestHandler.class); RenderPageRequestHandler h = (RenderPageRequestHandler) handler; ((PageProvider) h.getPageProvider()).setPageSource(context); IRequestablePage page = h.getPage(); @@ -172,12 +174,12 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void decode5() + void decode5() { Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + "?15--foo-bar"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ListenerRequestHandler.class)); + assertThat(handler).isInstanceOf(ListenerRequestHandler.class); ListenerRequestHandler h = (ListenerRequestHandler)handler; @@ -192,13 +194,13 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void decode6() + void decode6() { Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/i1/i2?15--foo-bar&a=b&b=c"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ListenerRequestHandler.class)); + assertThat(handler).isInstanceOf(ListenerRequestHandler.class); ListenerRequestHandler h = (ListenerRequestHandler)handler; IRequestablePage page = h.getPage(); @@ -216,13 +218,13 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void decode7() + void decode7() { Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + "?15-ILinkListener.4-foo-bar"); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ListenerRequestHandler.class)); + assertThat(handler).isInstanceOf(ListenerRequestHandler.class); ListenerRequestHandler h = (ListenerRequestHandler)handler; @@ -237,7 +239,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void decode8() + void decode8() { Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/i1/i2?15-5.ILinkListener-foo-bar&a=b&b=c"); @@ -246,7 +248,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertThat(handler, instanceOf(ListenerRequestHandler.class)); + assertThat(handler).isInstanceOf(ListenerRequestHandler.class); ListenerRequestHandler h = (ListenerRequestHandler)handler; IRequestablePage page = h.getPage(); @@ -256,29 +258,30 @@ public class BookmarkableMapperTest extends AbstractMapperTest /** * */ - @Test(expected = StalePageException.class) - public void decode9() + @Test + void decode9() { - Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME - + "/i1/i2?15-5.ILinkListener-foo-bar&a=b&b=c"); - - context.setNextPageRenderCount(6); - IRequestHandler handler = encoder.mapRequest(getRequest(url)); - - ((IPageRequestHandler)handler).getPage(); + assertThrows(StalePageException.class, () -> { + Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME + + "/i1/i2?15-5.ILinkListener-foo-bar&a=b&b=c"); + + context.setNextPageRenderCount(6); + IRequestHandler handler = encoder.mapRequest(getRequest(url)); + ((IPageRequestHandler)handler).getPage(); + }); } /** * WICKET-2993 */ @Test - public void decode10() + void decode10() { // use String.class but any other non-Page will do the job as well Url url = Url.parse("wicket/bookmarkable/" + String.class.getName()); IRequestHandler handler = encoder.mapRequest(getRequest(url)); - assertNull("A non-page class should not create a request handler!", handler); + assertNull(handler, "A non-page class should not create a request handler!"); } /** @@ -291,7 +294,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * {@link org.apache.wicket.core.request.mapper.IMapperContext#getBookmarkableIdentifier()} */ @Test - public void decode11() + void decode11() { final Url url = Url.parse(context.getBookmarkableIdentifier() + "/" + PAGE_CLASS_NAME); @@ -333,8 +336,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest }; IRequestHandler handler = encoder.mapRequest(request); - assertNotNull("A handler should be resolved for relative url to a bookmarkable page!", - handler); + assertNotNull(handler, "A handler should be resolved for relative url to a bookmarkable page!"); IRequestablePage page = ((IPageRequestHandler)handler).getPage(); assertEquals(page.getClass().getName(), PAGE_CLASS_NAME); @@ -350,7 +352,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * {@link org.apache.wicket.core.request.mapper.IMapperContext#getPageIdentifier()} */ @Test - public void decode12() + void decode12() { final Url url = Url.parse(context.getBookmarkableIdentifier() + "/" + PAGE_CLASS_NAME); @@ -391,8 +393,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest }; IRequestHandler handler = encoder.mapRequest(request); - assertNotNull("A handler should be resolved for relative url to a page instance url!", - handler); + assertNotNull(handler, "A handler should be resolved for relative url to a page instance url!"); IRequestablePage page = ((IPageRequestHandler)handler).getPage(); assertEquals(page.getClass().getName(), PAGE_CLASS_NAME); @@ -408,7 +409,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * {@link org.apache.wicket.core.request.mapper.IMapperContext#getPageIdentifier()} */ @Test - public void decode13() + void decode13() { final Url url = Url.parse(context.getBookmarkableIdentifier() + "/" + PAGE_CLASS_NAME); @@ -448,8 +449,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest }; IRequestHandler handler = encoder.mapRequest(request); - assertNotNull("A handler should be resolved for relative url to a bookmarkable page url!", - handler); + assertNotNull(handler, "A handler should be resolved for relative url to a bookmarkable page url!"); IRequestablePage page = ((IPageRequestHandler)handler).getPage(); assertEquals(page.getClass().getName(), PAGE_CLASS_NAME); @@ -459,43 +459,43 @@ public class BookmarkableMapperTest extends AbstractMapperTest * https://issues.apache.org/jira/browse/WICKET-5673 */ @Test - public void decode14() + void decode14() { Url url = Url.parse("wicket/bookmarkable/"); int score = encoder.getCompatibilityScore(getRequest(url)); - assertThat(score, is(0)); + assertEquals(0, score); } /** * https://issues.apache.org/jira/browse/WICKET-5996 */ @Test - public void decode15() + void decode15() { Url url = Url.parse("wicket/bookmarkable"); final AbstractBookmarkableMapper.UrlInfo urlInfo = encoder.parseRequest(getRequest(url)); - assertThat(urlInfo, is(nullValue())); + assertNull(urlInfo); } /** * https://issues.apache.org/jira/browse/WICKET-5996 */ @Test - public void decode16() + void decode16() { Url url = Url.parse("wicket/bookmarkable/"); final AbstractBookmarkableMapper.UrlInfo urlInfo = encoder.parseRequest(getRequest(url)); - assertThat(urlInfo, is(nullValue())); + assertNull(urlInfo); } /** * */ @Test - public void encode1() + void encode1() { PageProvider provider = new PageProvider(MockPage.class, new PageParameters()); provider.setPageSource(context); @@ -508,7 +508,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void encode2() + void encode2() { PageParameters parameters = new PageParameters(); parameters.set(0, "i1"); @@ -526,7 +526,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void encode3() + void encode3() { PageParameters parameters = new PageParameters(); parameters.set(0, "i1"); @@ -546,7 +546,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void encode4() + void encode4() { MockPage page = new MockPage(15); page.getPageParameters().set(0, "i1"); @@ -566,7 +566,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void encode5() + void encode5() { MockPage page = new MockPage(15); page.getPageParameters().set(0, "i1"); @@ -591,7 +591,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void encode6() + void encode6() { MockPage page = new MockPage(15); page.getPageParameters().set(0, "i1"); @@ -618,7 +618,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void encode7() + void encode7() { MockPage page = new MockPage(15); page.getPageParameters().set(0, "i1"); @@ -645,7 +645,7 @@ public class BookmarkableMapperTest extends AbstractMapperTest * */ @Test - public void encode8() + void encode8() { MockPage page = new MockPage(15); page.setBookmarkable(true); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/CryptoMapperTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/CryptoMapperTest.java b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/CryptoMapperTest.java index 58e5a6d..17d2273 100644 --- a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/CryptoMapperTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/CryptoMapperTest.java @@ -16,7 +16,13 @@ */ package org.apache.wicket.core.request.mapper; -import static org.hamcrest.CoreMatchers.instanceOf; +import static org.assertj.core.api.Assertions.assertThat; +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.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.function.Supplier; @@ -51,16 +57,17 @@ import org.apache.wicket.util.crypt.ICryptFactory; import org.apache.wicket.util.string.StringValue; import org.apache.wicket.util.string.Strings; import org.apache.wicket.util.tester.WicketTester; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Tests for {@link CryptoMapper} */ -public class CryptoMapperTest extends AbstractMapperTest +class CryptoMapperTest extends AbstractMapperTest { - private static final String PLAIN_BOOKMARKABLE_URL = "wicket/bookmarkable/" + Page2.class.getName(); + private static final String PLAIN_BOOKMARKABLE_URL = "wicket/bookmarkable/" + + Page2.class.getName(); private static final String ENCRYPTED_BOOKMARKABLE_URL = "L7ExSNbPC4sb6TPJDblCAopL53TWmZP5y7BQEaJSJAC05HXod5M5U7gT2yNT0lK5L6L09ZAOoZkGyUhseyPrC4S5tqUUrV6zipc4_Ni877EmwR8AyCyA-A/L7E59/5y7f2"; private static final String PLAIN_PAGE_INSTANCE_URL = "wicket/page?5"; private static final String ENCRYPTED_PAGE_INSTANCE_URL = "fyBfZ9p6trOhokHCzsQS6Q/fyBce"; @@ -70,13 +77,23 @@ public class CryptoMapperTest extends AbstractMapperTest private WicketTester tester; + private static IRequestHandler unwrapRequestHandlerDelegate(IRequestHandler handler) + { + while (handler instanceof IRequestHandlerDelegate) + { + handler = ((IRequestHandlerDelegate)handler).getDelegateHandler(); + } + + return handler; + } + /** * Creates the {@link CryptoMapper} * * @throws Exception */ - @Before - public void before() throws Exception + @BeforeEach + void before() throws Exception { tester = new WicketTester(HomePage.class); @@ -105,8 +122,8 @@ public class CryptoMapperTest extends AbstractMapperTest /** * @throws Exception */ - @After - public void after() throws Exception + @AfterEach + void after() throws Exception { tester.destroy(); } @@ -115,13 +132,13 @@ public class CryptoMapperTest extends AbstractMapperTest * Tests that the home page is requestable. */ @Test - public void homePage() + void homePage() { IRequestHandler requestHandler = mapper.mapRequest(getRequest(Url.parse(""))); - assertNotNull("Unable to map request for home page", requestHandler); + assertNotNull(requestHandler, "Unable to map request for home page"); requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class)); - RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler; + assertThat(requestHandler).isInstanceOf(RenderPageRequestHandler.class); + RenderPageRequestHandler handler = (RenderPageRequestHandler)requestHandler; assertSame(tester.getApplication().getHomePage(), handler.getPageClass()); } @@ -129,10 +146,11 @@ public class CryptoMapperTest extends AbstractMapperTest * Verifies that the home page can be reached with non-encrypted query parameters. * https://issues.apache.org/jira/browse/WICKET-4345 * - * Also, test that the URL for the home page with non-encrypted parameters is not encrypted, to avoid unnecessary redirects. + * Also, test that the URL for the home page with non-encrypted parameters is not encrypted, to + * avoid unnecessary redirects. */ @Test - public void homePageWithNonEncryptedQueryParameters() + void homePageWithNonEncryptedQueryParameters() { String expectedEncrypted = "?namedKey1=namedValue1"; PageParameters expectedParameters = new PageParameters(); @@ -149,23 +167,26 @@ public class CryptoMapperTest extends AbstractMapperTest assertNotNull(requestHandler); requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class)); - RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler; + assertThat(requestHandler).isInstanceOf(RenderPageRequestHandler.class); + RenderPageRequestHandler handler = (RenderPageRequestHandler)requestHandler; assertEquals(tester.getApplication().getHomePage(), handler.getPageClass()); StringValue queryParam = handler.getPageParameters().get("namedKey1"); assertEquals("namedValue1", queryParam.toOptionalString()); } /** - * Tests that we do not allow unencrypted URLs to IRequestListeners on the home page, like: ?0-0.ILinkListener-link + * Tests that we do not allow unencrypted URLs to IRequestListeners on the home page, like: + * ?0-0.ILinkListener-link */ @Test - public void homePageForceEncryptionOfRequestListener() + void homePageForceEncryptionOfRequestListener() { - PageAndComponentProvider provider = new PageAndComponentProvider(tester.getApplication().getHomePage(), "link"); + PageAndComponentProvider provider = new PageAndComponentProvider( + tester.getApplication().getHomePage(), "link"); IRequestHandler requestHandler = new BookmarkableListenerRequestHandler(provider); Url plainUrl = mapper.getDelegateMapper().mapHandler(requestHandler); - assertTrue("Plain URL for home page has segments: " + plainUrl.toString(), plainUrl.getSegments().isEmpty()); + assertTrue(plainUrl.getSegments().isEmpty(), + "Plain URL for home page has segments: " + plainUrl.toString()); assertNull(mapper.mapRequest(getRequest(plainUrl))); } @@ -173,10 +194,10 @@ public class CryptoMapperTest extends AbstractMapperTest * Tests that URLs for bookmarkable pages are encrypted. */ @Test - public void bookmarkablePageEncrypt() + void bookmarkablePageEncrypt() { - IRequestHandler renderPage2BookmarkableHandler = new RenderPageRequestHandler(new PageProvider( - Page2.class, new PageParameters())); + IRequestHandler renderPage2BookmarkableHandler = new RenderPageRequestHandler( + new PageProvider(Page2.class, new PageParameters())); Url plainTextUrl = mapper.getDelegateMapper().mapHandler(renderPage2BookmarkableHandler); @@ -187,10 +208,11 @@ public class CryptoMapperTest extends AbstractMapperTest } /** - * Tests that encrypted URLs for bookmarkable pages are decrypted and passed to the wrapped mapper. + * Tests that encrypted URLs for bookmarkable pages are decrypted and passed to the wrapped + * mapper. */ @Test - public void bookmarkablePageDecrypt() + void bookmarkablePageDecrypt() { Request request = getRequest(Url.parse(ENCRYPTED_BOOKMARKABLE_URL)); IRequestHandler requestHandler = mapper.mapRequest(request); @@ -198,23 +220,24 @@ public class CryptoMapperTest extends AbstractMapperTest assertNotNull(requestHandler); requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class)); + assertThat(requestHandler).isInstanceOf(RenderPageRequestHandler.class); - RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler; + RenderPageRequestHandler handler = (RenderPageRequestHandler)requestHandler; assertEquals(Page2.class, handler.getPageClass()); } /** * https://issues.apache.org/jira/browse/WICKET-6131 * - * Tests that encrypted URLs for bookmarkable pages are decrypted and passed to the wrapped mapper. - * Extra segments should be ignored. + * Tests that encrypted URLs for bookmarkable pages are decrypted and passed to the wrapped + * mapper. Extra segments should be ignored. */ @Test - public void bookmarkablePageDecrypt2() + void bookmarkablePageDecrypt2() { String encryptedExtraSegments = "/i87b7/i87b7"; - Request request = getRequest(Url.parse(ENCRYPTED_BOOKMARKABLE_URL + encryptedExtraSegments)); + Request request = getRequest( + Url.parse(ENCRYPTED_BOOKMARKABLE_URL + encryptedExtraSegments)); IRequestHandler requestHandler = mapper.mapRequest(request); assertNotNull(requestHandler); @@ -222,16 +245,16 @@ public class CryptoMapperTest extends AbstractMapperTest assertTrue(requestHandler instanceof RenderPageRequestHandler); - RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler; + RenderPageRequestHandler handler = (RenderPageRequestHandler)requestHandler; assertEquals(Page2.class, handler.getPageClass()); } /** - * Tests that encrypted URLs for bookmarkable pages are decrypted and passed to the wrapped mapper when there is more than - * one cryptomapper installed. + * Tests that encrypted URLs for bookmarkable pages are decrypted and passed to the wrapped + * mapper when there is more than one cryptomapper installed. */ @Test - public void bookmarkablePageDecryptMultipleCryptoMapper() + void bookmarkablePageDecryptMultipleCryptoMapper() { Request request = getRequest(Url.parse(ENCRYPTED_BOOKMARKABLE_URL)); @@ -241,9 +264,9 @@ public class CryptoMapperTest extends AbstractMapperTest assertNotNull(requestHandler); requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class)); + assertThat(requestHandler).isInstanceOf(RenderPageRequestHandler.class); - RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler; + RenderPageRequestHandler handler = (RenderPageRequestHandler)requestHandler; assertEquals(Page2.class, handler.getPageClass()); } @@ -251,9 +274,10 @@ public class CryptoMapperTest extends AbstractMapperTest * Tests that plain text URLs to bookmarkable pages are not mapped. */ @Test - public void bookmarkablePageForceEncryption() + void bookmarkablePageForceEncryption() { - IRequestHandler requestHandler = mapper.mapRequest(getRequest(Url.parse(PLAIN_BOOKMARKABLE_URL))); + IRequestHandler requestHandler = mapper + .mapRequest(getRequest(Url.parse(PLAIN_BOOKMARKABLE_URL))); assertNull(requestHandler); } @@ -262,14 +286,14 @@ public class CryptoMapperTest extends AbstractMapperTest * wicket/bookmarkable/my.package.page?0-0.ILinkListener-link */ @Test - public void bookmarkablePageForceEncryptionOfRequestListener() + void bookmarkablePageForceEncryptionOfRequestListener() { PageAndComponentProvider provider = new PageAndComponentProvider(Page2.class, "link"); IRequestHandler requestHandler = new BookmarkableListenerRequestHandler(provider); Url plainUrl = mapper.getDelegateMapper().mapHandler(requestHandler); - assertTrue("Plain text request listener URL for bookmarkable page does not start with: " - + PLAIN_BOOKMARKABLE_URL + ": " + plainUrl.toString(), - plainUrl.toString().startsWith(PLAIN_BOOKMARKABLE_URL)); + assertTrue(plainUrl.toString().startsWith(PLAIN_BOOKMARKABLE_URL), + "Plain text request listener URL for bookmarkable page does not start with: " + + PLAIN_BOOKMARKABLE_URL + ": " + plainUrl.toString()); assertNull(mapper.mapRequest(getRequest(plainUrl))); } @@ -277,12 +301,13 @@ public class CryptoMapperTest extends AbstractMapperTest * Tests that URLs for page instances are encrypted (/wicket/page?5) */ @Test - public void pageInstanceEncrypt() + void pageInstanceEncrypt() { MockPage page = new MockPage(5); IRequestHandler requestHandler = new RenderPageRequestHandler(new PageProvider(page)); - assertEquals(PLAIN_PAGE_INSTANCE_URL, mapper.getDelegateMapper().mapHandler(requestHandler).toString()); + assertEquals(PLAIN_PAGE_INSTANCE_URL, + mapper.getDelegateMapper().mapHandler(requestHandler).toString()); assertEquals(ENCRYPTED_PAGE_INSTANCE_URL, mapper.mapHandler(requestHandler).toString()); } @@ -290,15 +315,16 @@ public class CryptoMapperTest extends AbstractMapperTest * Make sure that encrypted page instance URLs are decrypted and the correct handler resolved. */ @Test - public void pageInstanceDecrypt() + void pageInstanceDecrypt() { - IRequestHandler requestHandler = mapper.mapRequest(getRequest(Url.parse(ENCRYPTED_PAGE_INSTANCE_URL))); + IRequestHandler requestHandler = mapper + .mapRequest(getRequest(Url.parse(ENCRYPTED_PAGE_INSTANCE_URL))); assertNotNull(requestHandler); requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class)); - RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler; + assertThat(requestHandler).isInstanceOf(RenderPageRequestHandler.class); + RenderPageRequestHandler handler = (RenderPageRequestHandler)requestHandler; assertEquals(5, handler.getPageId().intValue()); } @@ -306,7 +332,7 @@ public class CryptoMapperTest extends AbstractMapperTest * Make sure that encrypted page instance URLs are decrypted and the correct handler resolved. */ @Test - public void pageInstanceDecryptMultipleCryptoMapper() + void pageInstanceDecryptMultipleCryptoMapper() { IRequestHandler requestHandler = new CryptoMapper(mapper, tester.getApplication()) .mapRequest(getRequest(Url.parse(ENCRYPTED_PAGE_INSTANCE_URL))); @@ -314,8 +340,8 @@ public class CryptoMapperTest extends AbstractMapperTest assertNotNull(requestHandler); requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class)); - RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler; + assertThat(requestHandler).isInstanceOf(RenderPageRequestHandler.class); + RenderPageRequestHandler handler = (RenderPageRequestHandler)requestHandler; assertEquals(5, handler.getPageId().intValue()); } @@ -323,7 +349,7 @@ public class CryptoMapperTest extends AbstractMapperTest * Tests that plain text requests to a page instance URL are not mapped. */ @Test - public void pageInstanceForceEncryption() + void pageInstanceForceEncryption() { assertNull(mapper.mapRequest(getRequest(Url.parse(PLAIN_PAGE_INSTANCE_URL)))); } @@ -332,9 +358,10 @@ public class CryptoMapperTest extends AbstractMapperTest * Tests that mounted pages are still accessible through their mounted URL. */ @Test - public void mountedPage() + void mountedPage() { - IRequestHandler requestHandler = new RenderPageRequestHandler(new PageProvider(Page1.class)); + IRequestHandler requestHandler = new RenderPageRequestHandler( + new PageProvider(Page1.class)); assertEquals(MOUNTED_URL, mapper.mapHandler(requestHandler).toString()); @@ -344,20 +371,21 @@ public class CryptoMapperTest extends AbstractMapperTest requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class)); + assertThat(requestHandler).isInstanceOf(RenderPageRequestHandler.class); - assertEquals(Page1.class, ((RenderPageRequestHandler) requestHandler).getPageClass()); + assertEquals(Page1.class, ((RenderPageRequestHandler)requestHandler).getPageClass()); } /** * Tests that PageComponentInfo parameters are encrypted on Mounted pages */ @Test - public void mountedPageRequestListenerParameter() + void mountedPageRequestListenerParameter() { final String componentPath = "link"; - PageAndComponentProvider provider = new PageAndComponentProvider(Page1.class, componentPath); + PageAndComponentProvider provider = new PageAndComponentProvider(Page1.class, + componentPath); IRequestHandler requestHandler = new ListenerRequestHandler(provider); Url plainUrl = mapper.getDelegateMapper().mapHandler(requestHandler); @@ -381,7 +409,7 @@ public class CryptoMapperTest extends AbstractMapperTest if (Strings.isEmpty(qp.getValue())) { PageComponentInfo pci = PageComponentInfo.parse(qp.getName()); - assertNull("PageComponentInfo query parameter not encrypted", pci); + assertNull(pci, "PageComponentInfo query parameter not encrypted"); } } @@ -391,14 +419,15 @@ public class CryptoMapperTest extends AbstractMapperTest requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(ListenerRequestHandler.class)); + assertThat(requestHandler).isInstanceOf(ListenerRequestHandler.class); - ListenerRequestHandler handler = (ListenerRequestHandler) requestHandler; + ListenerRequestHandler handler = (ListenerRequestHandler)requestHandler; assertEquals(componentPath, handler.getComponentPath()); assertEquals(Page1.class, handler.getPageClass()); /* - * We anticipate that sometimes multiple cryptomappers will be used. It should still work in these situations. + * We anticipate that sometimes multiple cryptomappers will be used. It should still work in + * these situations. */ requestHandler = new CryptoMapper(mapper, tester.getApplication()) .mapRequest(getRequest(encryptedUrl)); @@ -407,9 +436,9 @@ public class CryptoMapperTest extends AbstractMapperTest requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(ListenerRequestHandler.class)); + assertThat(requestHandler).isInstanceOf(ListenerRequestHandler.class); - handler = (ListenerRequestHandler) requestHandler; + handler = (ListenerRequestHandler)requestHandler; assertEquals(componentPath, handler.getComponentPath()); assertEquals(Page1.class, handler.getPageClass()); } @@ -418,24 +447,23 @@ public class CryptoMapperTest extends AbstractMapperTest * Tests that the compatability score is correctly calculated from wrapped mapper. */ @Test - public void compatabilityScore() + void compatabilityScore() { - int delegateHomePageScore = mapper.getDelegateMapper().getCompatibilityScore( - getRequest(Url.parse(""))); - int cryptoHomePageScore = mapper.getCompatibilityScore( - getRequest(Url.parse(""))); + int delegateHomePageScore = mapper.getDelegateMapper() + .getCompatibilityScore(getRequest(Url.parse(""))); + int cryptoHomePageScore = mapper.getCompatibilityScore(getRequest(Url.parse(""))); assertEquals(delegateHomePageScore, cryptoHomePageScore); - int delegateBookmarkableScore = mapper.getDelegateMapper().getCompatibilityScore( - getRequest(Url.parse(PLAIN_BOOKMARKABLE_URL))); - int cryptoBookmarkableScore = mapper.getCompatibilityScore( - getRequest(Url.parse(ENCRYPTED_BOOKMARKABLE_URL))); + int delegateBookmarkableScore = mapper.getDelegateMapper() + .getCompatibilityScore(getRequest(Url.parse(PLAIN_BOOKMARKABLE_URL))); + int cryptoBookmarkableScore = mapper + .getCompatibilityScore(getRequest(Url.parse(ENCRYPTED_BOOKMARKABLE_URL))); assertEquals(delegateBookmarkableScore, cryptoBookmarkableScore); - int delegatePageInstanceScore = mapper.getDelegateMapper().getCompatibilityScore( - getRequest(Url.parse(PLAIN_PAGE_INSTANCE_URL))); - int cryptoPageInstanceScore = mapper.getCompatibilityScore( - getRequest(Url.parse(ENCRYPTED_PAGE_INSTANCE_URL))); + int delegatePageInstanceScore = mapper.getDelegateMapper() + .getCompatibilityScore(getRequest(Url.parse(PLAIN_PAGE_INSTANCE_URL))); + int cryptoPageInstanceScore = mapper + .getCompatibilityScore(getRequest(Url.parse(ENCRYPTED_PAGE_INSTANCE_URL))); assertEquals(delegatePageInstanceScore, cryptoPageInstanceScore); } @@ -443,7 +471,7 @@ public class CryptoMapperTest extends AbstractMapperTest * Test a failed decrypt, WICKET-4139 */ @Test - public void decryptFailed() + void decryptFailed() { String encrypted = "style.css"; @@ -456,7 +484,7 @@ public class CryptoMapperTest extends AbstractMapperTest * Tests that named and indexed parameters are properly (en|de)crypted */ @Test - public void pageParameters() + void pageParameters() { String expectedEncrypted = "L7ExSNbPC4sb6TPJDblCAopL53TWmZP5y7BQEaJSJAC05HXod5M5U7gT2yNT0lK5L6L09ZAOoZkGyUhseyPrC4S5tqUUrV6zipc4_Ni877FDOOoE5C_Cd7YCyK1xSScpVhno6LeBz2wiu5oWyf7hB1RKcv6zkhEBmbx8vU7K7-e4xe1_LO8Y3fhEjMSQyU9BVh7Uz4HKzkR2OxFo5LaDzQ/L7E59/yPr6a/5L6ae/OxF2c"; @@ -474,9 +502,9 @@ public class CryptoMapperTest extends AbstractMapperTest IRequestHandler requestHandler = mapper.mapRequest(request); assertNotNull(requestHandler); requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(RenderPageRequestHandler.class)); + assertThat(requestHandler).isInstanceOf(RenderPageRequestHandler.class); - RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler; + RenderPageRequestHandler handler = (RenderPageRequestHandler)requestHandler; assertEquals(Page2.class, handler.getPageClass()); PageParameters actualParameters = handler.getPageParameters(); assertEquals(expectedParameters, actualParameters); @@ -486,7 +514,7 @@ public class CryptoMapperTest extends AbstractMapperTest * UrlResourceReferences, WICKET-5319 */ @Test - public void urlResourceReference() + void urlResourceReference() { UrlResourceReference resource = new UrlResourceReference( Url.parse("http://wicket.apache.org/")); @@ -499,7 +527,7 @@ public class CryptoMapperTest extends AbstractMapperTest * Relative ResourceReferences, WICKET-3514 */ @Test - public void resourceReference() + void resourceReference() { PackageResourceReference resource = new PackageResourceReference(getClass(), "crypt/crypt.txt"); @@ -511,8 +539,8 @@ public class CryptoMapperTest extends AbstractMapperTest assertNotNull(requestHandler); requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(ResourceReferenceRequestHandler.class)); - ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler) requestHandler; + assertThat(requestHandler).isInstanceOf(ResourceReferenceRequestHandler.class); + ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler)requestHandler; assertEquals(getClass(), handler.getResourceReference().getScope()); assertEquals("crypt/crypt.txt", handler.getResourceReference().getName()); @@ -522,7 +550,7 @@ public class CryptoMapperTest extends AbstractMapperTest * Relative ResourceReferences, WICKET-3514 */ @Test - public void resourceReferenceWithModifiedSegments() + void resourceReferenceWithModifiedSegments() { PackageResourceReference resource = new PackageResourceReference(getClass(), "crypt/crypt.txt"); @@ -536,8 +564,8 @@ public class CryptoMapperTest extends AbstractMapperTest assertNotNull(requestHandler); requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(ResourceReferenceRequestHandler.class)); - ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler) requestHandler; + assertThat(requestHandler).isInstanceOf(ResourceReferenceRequestHandler.class); + ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler)requestHandler; assertEquals(getClass(), handler.getResourceReference().getScope()); assertEquals("crypt/modified-crypt.txt", handler.getResourceReference().getName()); @@ -547,7 +575,7 @@ public class CryptoMapperTest extends AbstractMapperTest * Relative ResourceReferences, WICKET-3514 */ @Test - public void resourceReferenceWithMoreSegments() + void resourceReferenceWithMoreSegments() { PackageResourceReference resource = new PackageResourceReference(getClass(), "crypt/crypt.txt"); @@ -562,7 +590,7 @@ public class CryptoMapperTest extends AbstractMapperTest assertNotNull(requestHandler); requestHandler = unwrapRequestHandlerDelegate(requestHandler); - ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler) requestHandler; + ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler)requestHandler; assertEquals(getClass(), handler.getResourceReference().getScope()); assertEquals("crypt/more/more-crypt.txt", handler.getResourceReference().getName()); @@ -572,7 +600,7 @@ public class CryptoMapperTest extends AbstractMapperTest * Relative ResourceReferences, WICKET-3514 */ @Test - public void resourceReferenceWithLessSegments() + void resourceReferenceWithLessSegments() { PackageResourceReference resource = new PackageResourceReference(getClass(), "crypt/crypt.txt"); @@ -587,8 +615,8 @@ public class CryptoMapperTest extends AbstractMapperTest assertNotNull(requestHandler); requestHandler = unwrapRequestHandlerDelegate(requestHandler); - assertThat(requestHandler, instanceOf(ResourceReferenceRequestHandler.class)); - ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler) requestHandler; + assertThat(requestHandler).isInstanceOf(ResourceReferenceRequestHandler.class); + ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler)requestHandler; assertEquals(getClass(), handler.getResourceReference().getScope()); assertEquals("less-crypt.txt", handler.getResourceReference().getName()); @@ -598,7 +626,7 @@ public class CryptoMapperTest extends AbstractMapperTest * Additional parameters, WICKET-4923 */ @Test - public void additionalParameters() + void additionalParameters() { MockPage page = new MockPage(); IRequestableComponent c = page.get("foo:bar"); @@ -612,16 +640,17 @@ public class CryptoMapperTest extends AbstractMapperTest IRequestHandler requestHandler = mapper.mapRequest(request); - assertThat(requestHandler, instanceOf(RequestSettingRequestHandler.class)); + assertThat(requestHandler).isInstanceOf(RequestSettingRequestHandler.class); - assertEquals("foo", ((RequestSettingRequestHandler) requestHandler).getRequest() - .getUrl() - .getQueryParameterValue("q") - .toString()); + assertEquals("foo", + ((RequestSettingRequestHandler)requestHandler).getRequest() + .getUrl() + .getQueryParameterValue("q") + .toString()); } @Test - public void markedEncryptedUrlDecrypt() + void markedEncryptedUrlDecrypt() { mapper.setMarkEncryptedUrls(true); Request request = getRequest(Url.parse("crypt." + ENCRYPTED_BOOKMARKABLE_URL)); @@ -632,29 +661,23 @@ public class CryptoMapperTest extends AbstractMapperTest assertTrue(requestHandler instanceof RenderPageRequestHandler); - RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler; + RenderPageRequestHandler handler = (RenderPageRequestHandler)requestHandler; assertEquals(Page2.class, handler.getPageClass()); } - @Test(expected = PageExpiredException.class) - public void expiredMarkedEncryptedUrlThrowsPageExpiredException() + @Test + void expiredMarkedEncryptedUrlThrowsPageExpiredException() { mapper.setMarkEncryptedUrls(true); - Url encryptedUrl = mapper.mapHandler(new RenderPageRequestHandler(new PageProvider(Page2.class))); + Url encryptedUrl = mapper + .mapHandler(new RenderPageRequestHandler(new PageProvider(Page2.class))); assertTrue(encryptedUrl.getSegments().get(0).startsWith("crypt.")); encryptedUrl.getSegments().remove(0); encryptedUrl.getSegments().add(0, "crypt.no decryptable"); - mapper.mapRequest(getRequest(encryptedUrl)); - } - private static IRequestHandler unwrapRequestHandlerDelegate(IRequestHandler handler) - { - while (handler instanceof IRequestHandlerDelegate) - { - handler = ((IRequestHandlerDelegate) handler).getDelegateHandler(); - } - - return handler; + assertThrows(PageExpiredException.class, () -> { + mapper.mapRequest(getRequest(encryptedUrl)); + }); } /** @@ -664,14 +687,15 @@ public class CryptoMapperTest extends AbstractMapperTest { public HomePage() { - add(new Link<Void>("link") { + add(new Link<Void>("link") + { @Override public void onClick() { } }); } - + @Override public IMarkupFragment getMarkup() { @@ -686,14 +710,15 @@ public class CryptoMapperTest extends AbstractMapperTest { public Page1() { - add(new Link<Void>("link") { + add(new Link<Void>("link") + { @Override public void onClick() { } }); } - + @Override public IMarkupFragment getMarkup() { @@ -708,14 +733,15 @@ public class CryptoMapperTest extends AbstractMapperTest { public Page2() { - add(new Link<Void>("link") { + add(new Link<Void>("link") + { @Override public void onClick() { } }); } - + @Override public IMarkupFragment getMarkup() {