http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/CsrfPreventionRequestCycleListenerTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/CsrfPreventionRequestCycleListenerTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/CsrfPreventionRequestCycleListenerTest.java index 9882bd6..3fd010e 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/CsrfPreventionRequestCycleListenerTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/CsrfPreventionRequestCycleListenerTest.java @@ -17,6 +17,8 @@ package org.apache.wicket.protocol.http; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import javax.servlet.http.HttpServletRequest; @@ -26,20 +28,20 @@ import org.apache.wicket.request.IRequestHandler; import org.apache.wicket.request.component.IRequestablePage; import org.apache.wicket.request.http.WebRequest; 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 cases for the CsrfPreventionRequestCycleListener. FirstPage has a link that when clicked * should render SecondPage. */ -public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase +class CsrfPreventionRequestCycleListenerTest extends WicketTestCase { /** * Sets up the test cases. Installs the CSRF listener and renders the FirstPage. */ - @Before - public void startWithFirstPageRender() + @BeforeEach + void startWithFirstPageRender() { WebApplication application = tester.getApplication(); @@ -59,7 +61,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests that disabling the CSRF listener doesn't check Origin headers. */ @Test - public void disabledListenerDoesntCheckAnything() + void disabledListenerDoesntCheckAnything() { csrfEnabled = false; tester.clickLink("link"); @@ -70,7 +72,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests that disabling the CSRF listener doesn't check Origin headers. */ @Test - public void disabledListenerDoesntCheckMismatchedOrigin() + void disabledListenerDoesntCheckMismatchedOrigin() { csrfEnabled = false; tester.addRequestHeader(WebRequest.HEADER_ORIGIN, "http://malicioussite.com/"); @@ -81,7 +83,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests the default setting of aborting a missing Origin. */ @Test - public void withoutOriginAllowed() + void withoutOriginAllowed() { csrfListener.setNoOriginAction(CsrfAction.ALLOW); tester.addRequestHeader(WebRequest.HEADER_ORIGIN, null); @@ -91,7 +93,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests the alternative action of suppressing a request without Origin header */ @Test - public void withoutOriginSuppressed() + void withoutOriginSuppressed() { csrfListener.setNoOriginAction(CsrfAction.SUPPRESS); tester.addRequestHeader(WebRequest.HEADER_ORIGIN, null); @@ -102,7 +104,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests the alternative action of aborting a request without Origin header */ @Test - public void withoutOriginAborted() + void withoutOriginAborted() { csrfListener.setNoOriginAction(CsrfAction.ABORT); tester.addRequestHeader(WebRequest.HEADER_ORIGIN, null); @@ -112,7 +114,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests when the Origin header matches the request. */ @Test - public void matchingOriginsAllowed() + void matchingOriginsAllowed() { csrfListener.setConflictingOriginAction(CsrfAction.ALLOW); tester.addRequestHeader(WebRequest.HEADER_ORIGIN, "http://localhost/"); @@ -125,7 +127,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests when the default action is changed to ALLOW when origins conflict. */ @Test - public void conflictingOriginsAllowed() + void conflictingOriginsAllowed() { csrfListener.setConflictingOriginAction(CsrfAction.ALLOW); tester.addRequestHeader(WebRequest.HEADER_ORIGIN, "http://example.com/"); @@ -138,7 +140,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests when the default action is changed to SUPPRESS when origins conflict. */ @Test - public void conflictingOriginsSuppressed() + void conflictingOriginsSuppressed() { tester.addRequestHeader(WebRequest.HEADER_ORIGIN, "http://example.com/"); csrfListener.setConflictingOriginAction(CsrfAction.SUPPRESS); @@ -151,7 +153,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests the default action to ABORT when origins conflict. */ @Test - public void conflictingOriginsAborted() + void conflictingOriginsAborted() { tester.addRequestHeader(WebRequest.HEADER_ORIGIN, "http://example.com/"); @@ -162,7 +164,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests custom error code/message when the default action is ABORT. */ @Test - public void conflictingOriginsAbortedWith401Unauhorized() + void conflictingOriginsAbortedWith401Unauhorized() { setErrorCode(401); setErrorMessage("NOT AUTHORIZED"); @@ -177,7 +179,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests whitelisting for conflicting origins. */ @Test - public void conflictingButWhitelistedOriginAllowed() + void conflictingButWhitelistedOriginAllowed() { csrfListener.setConflictingOriginAction(CsrfAction.ALLOW); csrfListener.addAcceptedOrigin("example.com"); @@ -191,7 +193,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests whitelisting with conflicting subdomain origin. */ @Test - public void conflictingButWhitelistedSubdomainOriginAllowed() + void conflictingButWhitelistedSubdomainOriginAllowed() { csrfListener.addAcceptedOrigin("example.com"); csrfListener.setConflictingOriginAction(CsrfAction.ALLOW); @@ -209,7 +211,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase * {@link CsrfPreventionRequestCycleListener#isChecked(IRequestablePage)}) */ @Test - public void conflictingOriginPageNotCheckedAllowed() + void conflictingOriginPageNotCheckedAllowed() { tester.addRequestHeader(WebRequest.HEADER_ORIGIN, "http://example.com/"); csrfListener.setConflictingOriginAction(CsrfAction.ABORT); @@ -225,7 +227,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests overriding the onSuppressed method for a conflicting origin. */ @Test - public void conflictingOriginSuppressedCallsCustomHandler() + void conflictingOriginSuppressedCallsCustomHandler() { // redirect to third page to ensure we are not suppressed to the first page, nor that the // request was not suppressed and the second page was rendered erroneously @@ -251,7 +253,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests overriding the onAllowed method for a conflicting origin. */ @Test - public void conflictingOriginAllowedCallsCustomHandler() + void conflictingOriginAllowedCallsCustomHandler() { // redirect to third page to ensure we are not suppressed to the first page, nor that the // request was not allowed and the second page was rendered erroneously @@ -277,7 +279,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests overriding the onAborted method for a conflicting origin. */ @Test - public void conflictingOriginAbortedCallsCustomHandler() + void conflictingOriginAbortedCallsCustomHandler() { // redirect to third page to ensure we are not suppressed to the first page, nor that the // request was not aborted and the second page was rendered erroneously @@ -308,7 +310,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests whether a different port, but same scheme and hostname is considered a conflict. */ @Test - public void differentPortOriginAborted() + void differentPortOriginAborted() { tester.addRequestHeader(WebRequest.HEADER_ORIGIN, "http://localhost:8080"); csrfListener.setConflictingOriginAction(CsrfAction.ABORT); @@ -320,7 +322,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests whether a different scheme, but same port and hostname is considered a conflict. */ @Test - public void differentSchemeOriginAborted() + void differentSchemeOriginAborted() { tester.addRequestHeader(WebRequest.HEADER_ORIGIN, "https://localhost"); csrfListener.setConflictingOriginAction(CsrfAction.ABORT); @@ -332,7 +334,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests whether only the hostname is considered when matching the Origin header. */ @Test - public void longerOriginAllowed() + void longerOriginAllowed() { tester.addRequestHeader(WebRequest.HEADER_ORIGIN, "http://localhost/supercalifragilisticexpialidocious"); csrfListener.setConflictingOriginAction(CsrfAction.ABORT); @@ -345,7 +347,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests whether AJAX Links are checked through the CSRF listener */ @Test - public void simulatedCsrfAttackThroughAjaxIsPrevented() + void simulatedCsrfAttackThroughAjaxIsPrevented() { csrfListener.setConflictingOriginAction(CsrfAction.ABORT); @@ -365,7 +367,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests whether AJAX Links are checked through the CSRF listener */ @Test - public void simulatedCsrfAttackIsSuppressed() + void simulatedCsrfAttackIsSuppressed() { csrfListener.setConflictingOriginAction(CsrfAction.SUPPRESS); @@ -386,7 +388,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** Tests whether form submits are checked through the CSRF listener */ @Test - public void simulatedCsrfAttackOnFormIsSuppressed() + void simulatedCsrfAttackOnFormIsSuppressed() { csrfListener.setConflictingOriginAction(CsrfAction.SUPPRESS); @@ -445,7 +447,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase csrfListener.setErrorCode(errorCode); } - private void setCustomRequestHandlerCheck(Predicate<IRequestHandler> check) + void setCustomRequestHandlerCheck(Predicate<IRequestHandler> check) { this.customRequestHandlerCheck = check; } @@ -471,12 +473,12 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase this.suppressHandler = suppressHandler; } - private void setWhitelistHandler(Runnable whitelistHandler) + void setWhitelistHandler(Runnable whitelistHandler) { this.whitelistHandler = whitelistHandler; } - private void setMatchedHandler(Runnable matchedHandler) + void setMatchedHandler(Runnable matchedHandler) { this.matchedHandler = matchedHandler; } @@ -508,7 +510,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase if (!aborted) throw new AssertionError("Request was not aborted"); - assertThat("Response error code", tester.getLastResponse().getStatus(), is(errorCode)); + assertEquals(errorCode, tester.getLastResponse().getStatus(), "Response error code"); assertThat("Response error message", tester.getLastResponse().getErrorMessage(), is(errorMessage)); } @@ -534,7 +536,7 @@ public class CsrfPreventionRequestCycleListenerTest extends WicketTestCase /** * Asserts that the origins were checked and found non-conflicting. */ - private void assertOriginsCheckedButNotConflicting() + void assertOriginsCheckedButNotConflicting() { if (aborted) throw new AssertionError("Origin was checked and aborted");
http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponseTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponseTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponseTest.java index 1383b4b..cb01b2f 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponseTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/HeaderBufferingWebResponseTest.java @@ -16,24 +16,26 @@ */ package org.apache.wicket.protocol.http; -import org.apache.wicket.mock.MockWebResponse; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; +import org.apache.wicket.mock.MockWebResponse; +import org.junit.jupiter.api.Test; /** * Test for {@link HeaderBufferingWebResponse}. * * @author svenmeier */ -public class HeaderBufferingWebResponseTest extends Assert +class HeaderBufferingWebResponseTest { /** * WICKET-4927 */ @Test - public void additionalHeaderAfterWrittenContent() + void additionalHeaderAfterWrittenContent() { MockWebResponse originalResponse = new MockWebResponse(); @@ -55,7 +57,7 @@ public class HeaderBufferingWebResponseTest extends Assert /** */ @Test - public void resetAfterWrittenContent() + void resetAfterWrittenContent() { MockWebResponse originalResponse = new MockWebResponse(); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/ModifyCookiePageTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/ModifyCookiePageTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/ModifyCookiePageTest.java index 58f3843..768da40 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/ModifyCookiePageTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/ModifyCookiePageTest.java @@ -16,23 +16,25 @@ */ package org.apache.wicket.protocol.http; -import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import java.util.List; import javax.servlet.http.Cookie; import org.apache.wicket.protocol.http.mock.MockHttpServletResponse; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** */ -public class ModifyCookiePageTest extends WicketTestCase +class ModifyCookiePageTest extends WicketTestCase { /** * testSetCookieWithinLinkListener() */ @Test - public void testSetCookieWithinLinkListener() + void testSetCookieWithinLinkListener() { // render page tester.startPage(ModifyCookiePage.class); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/RequestLoggerLiveSessionsTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/RequestLoggerLiveSessionsTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/RequestLoggerLiveSessionsTest.java index edbc552..96bbe04 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/RequestLoggerLiveSessionsTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/RequestLoggerLiveSessionsTest.java @@ -16,28 +16,29 @@ */ package org.apache.wicket.protocol.http; -import org.apache.wicket.util.SlowTests; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; import java.util.Random; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.wicket.util.WicketTestTag; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + /** * Test for https://issues.apache.org/jira/browse/WICKET-6169 */ -@Category(SlowTests.class) -public class RequestLoggerLiveSessionsTest +@Tag(WicketTestTag.SLOW) +class RequestLoggerLiveSessionsTest { private final RequestLogger requestLogger = new RequestLogger(); private final ArrayList<String> sessionIds = new ArrayList<>(); @Test - public void concurrentModification() { + void concurrentModification() { SessionCreateThread sct = new SessionCreateThread(); SessionDestroyThread sdt = new SessionDestroyThread(); sct.start(); @@ -63,7 +64,7 @@ public class RequestLoggerLiveSessionsTest sdt.interrupt(); if (nullPointerExceptionThrown.get()) { - Assert.fail("The test should not fail with NullPointerException"); + fail("The test should not fail with NullPointerException"); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java index 4c41951..80da4ed 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/RequestUtilsTest.java @@ -16,27 +16,28 @@ */ package org.apache.wicket.protocol.http; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.nio.charset.Charset; import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; import org.apache.wicket.request.mapper.parameter.PageParameters; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * * @author Johan */ -public class RequestUtilsTest extends Assert +class RequestUtilsTest { - public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8"); + private static final Charset UTF_8_CHARSET = Charset.forName("UTF-8"); /** * */ @Test - public void doubleDotsMiddle() + void doubleDotsMiddle() { assertEquals("/a/b", RequestUtils.removeDoubleDots("/a/b/../b")); assertEquals("a/b", RequestUtils.removeDoubleDots("a/b/../b")); @@ -47,7 +48,7 @@ public class RequestUtilsTest extends Assert * */ @Test - public void doubleDotsEnd() + void doubleDotsEnd() { assertEquals("/a/b", RequestUtils.removeDoubleDots("/a/b/c/..")); assertEquals("a/b", RequestUtils.removeDoubleDots("a/b/c/..")); @@ -57,7 +58,7 @@ public class RequestUtilsTest extends Assert * */ @Test - public void doubleDotsStart() + void doubleDotsStart() { assertEquals("/../a/b", RequestUtils.removeDoubleDots("/../a/b")); assertEquals("../a/b", RequestUtils.removeDoubleDots("../a/b")); @@ -67,7 +68,7 @@ public class RequestUtilsTest extends Assert * */ @Test - public void emptyDoubleDots() + void emptyDoubleDots() { assertEquals("", RequestUtils.removeDoubleDots("")); } @@ -76,7 +77,7 @@ public class RequestUtilsTest extends Assert * */ @Test - public void oneDoubleDots() + void oneDoubleDots() { assertEquals("..", RequestUtils.removeDoubleDots("..")); assertEquals("../", RequestUtils.removeDoubleDots("../")); @@ -87,7 +88,7 @@ public class RequestUtilsTest extends Assert * */ @Test - public void toAbsolutePath() + void toAbsolutePath() { assertEquals(RequestUtils.toAbsolutePath("http://aif.ru/test/test", "../blah/zzz"), "http://aif.ru/blah/zzz"); @@ -109,7 +110,7 @@ public class RequestUtilsTest extends Assert * WICKET-4664 - remove leading ? if present */ @Test - public void removeLeadingQuestionMark_simpleParam() + void removeLeadingQuestionMark_simpleParam() { final PageParameters params = new PageParameters(); RequestUtils.decodeParameters("?key=value", params, UTF_8_CHARSET); @@ -120,7 +121,7 @@ public class RequestUtilsTest extends Assert * WICKET-4664 - remove leading ? if present */ @Test - public void removeLeadingQuestionMark_simpleParamWithoutValueAndAnotherParam() + void removeLeadingQuestionMark_simpleParamWithoutValueAndAnotherParam() { final PageParameters params = new PageParameters(); RequestUtils.decodeParameters("?123&key=value", params, UTF_8_CHARSET); @@ -132,7 +133,7 @@ public class RequestUtilsTest extends Assert * WICKET-4664 - remove leading ? if present */ @Test - public void removeLeadingQuestionMark_simpleParamWithoutValue() + void removeLeadingQuestionMark_simpleParamWithoutValue() { final PageParameters params = new PageParameters(); RequestUtils.decodeParameters("?123", params, UTF_8_CHARSET); @@ -143,7 +144,7 @@ public class RequestUtilsTest extends Assert * */ @Test - public void decodeParam_simpleParam_noQuestionMark() + void decodeParam_simpleParam_noQuestionMark() { final PageParameters params = new PageParameters(); RequestUtils.decodeParameters("key=value", params, UTF_8_CHARSET); @@ -154,7 +155,7 @@ public class RequestUtilsTest extends Assert * */ @Test - public void decodeParam_simpleParamWithoutValueAndAnotherParam_NoQuestionMark() + void decodeParam_simpleParamWithoutValueAndAnotherParam_NoQuestionMark() { final PageParameters params = new PageParameters(); RequestUtils.decodeParameters("123&key=value", params, UTF_8_CHARSET); @@ -166,7 +167,7 @@ public class RequestUtilsTest extends Assert * */ @Test - public void decodeParam_simpleParamWithoutValue_NoQuestionMark() + void decodeParam_simpleParamWithoutValue_NoQuestionMark() { final PageParameters params = new PageParameters(); RequestUtils.decodeParameters("123", params, UTF_8_CHARSET); @@ -175,7 +176,7 @@ public class RequestUtilsTest extends Assert @Test - public void charset() throws Exception + void charset() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(null, null, null); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/ResponseIOExceptionTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/ResponseIOExceptionTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/ResponseIOExceptionTest.java index 7c93956..44088a8 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/ResponseIOExceptionTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/ResponseIOExceptionTest.java @@ -16,10 +16,9 @@ */ package org.apache.wicket.protocol.http; -import static org.hamcrest.CoreMatchers.instanceOf; +import static org.assertj.core.api.Assertions.assertThat; import java.net.SocketException; - import javax.servlet.http.HttpServletResponse; import org.apache.wicket.protocol.http.servlet.ResponseIOException; @@ -33,24 +32,22 @@ import org.apache.wicket.request.handler.EmptyRequestHandler; import org.apache.wicket.request.resource.ResourceStreamResource; import org.apache.wicket.util.resource.StringResourceStream; import org.apache.wicket.util.tester.WicketTester; -import org.junit.After; -import org.junit.Assert; -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; /** * @author Pedro Santos */ -public class ResponseIOExceptionTest extends Assert +class ResponseIOExceptionTest { private WicketTester tester; /** * @throws Exception */ - @Before - public void before() throws Exception + @BeforeEach + void before() throws Exception { tester = new WicketTester() { @@ -66,8 +63,8 @@ public class ResponseIOExceptionTest extends Assert /** * @throws Exception */ - @After - public void after() throws Exception + @AfterEach + void after() throws Exception { tester.destroy(); } @@ -76,13 +73,12 @@ public class ResponseIOExceptionTest extends Assert * WICKET-3570 */ @Test - public void giveUpRespondingOnIOExceptions() + void giveUpRespondingOnIOExceptions() { TestRequestCycleListener testRequestCycleListener = new TestRequestCycleListener(); tester.getApplication().getRequestCycleListeners().add(testRequestCycleListener); tester.startResource(new ResourceStreamResource(new StringResourceStream("asdf"))); - assertThat(testRequestCycleListener.lastExceptionRequestHandlerResolved, - instanceOf(EmptyRequestHandler.class)); + assertThat(testRequestCycleListener.lastExceptionRequestHandlerResolved).isInstanceOf(EmptyRequestHandler.class); } static class TestRequestCycleListener implements IRequestCycleListener @@ -100,15 +96,15 @@ public class ResponseIOExceptionTest extends Assert /** * Mock response simulating connection lost problems. */ - public static class ProblematicResponse extends ServletWebResponse + static class ProblematicResponse extends ServletWebResponse { /** * @param webRequest * @param httpServletResponse */ - public ProblematicResponse(ServletWebRequest webRequest, - HttpServletResponse httpServletResponse) + ProblematicResponse(ServletWebRequest webRequest, + HttpServletResponse httpServletResponse) { super(webRequest, httpServletResponse); } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/SessionDestroyTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/SessionDestroyTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/SessionDestroyTest.java index 51ba825..0eee65c 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/SessionDestroyTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/SessionDestroyTest.java @@ -16,7 +16,7 @@ */ package org.apache.wicket.protocol.http; -import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; @@ -27,15 +27,15 @@ import java.util.Locale; import org.apache.wicket.mock.MockWebRequest; import org.apache.wicket.request.Url; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class SessionDestroyTest extends WicketTestCase +class SessionDestroyTest extends WicketTestCase { /** * https://issues.apache.org/jira/browse/WICKET-6310 */ @Test - public void whenSessionIsDestroyed_thenItShouldResetItsState() + void whenSessionIsDestroyed_thenItShouldResetItsState() { final Locale locale = Locale.ENGLISH; MockWebRequest request = new MockWebRequest(Url.parse("/")) @@ -51,20 +51,20 @@ public class SessionDestroyTest extends WicketTestCase // initially #invalidateNow() (and destroy()) are not called verify(session, never()).invalidateNow(); - assertThat(session.isSessionInvalidated(), is(false)); + assertEquals(false, session.isSessionInvalidated()); // schedule invalidation session.invalidate(); // the invalidation will happen on #detach(), so #destroy() is still not called verify(session, never()).invalidateNow(); - assertThat(session.isSessionInvalidated(), is(true)); + assertEquals(true, session.isSessionInvalidated()); session.detach(); // the session has been detached so #destroy() has been called and 'sessionInvalidated' is reset verify(session, times(1)).invalidateNow(); - assertThat(session.isSessionInvalidated(), is(false)); + assertEquals(false, session.isSessionInvalidated()); // no matter how many times #detach() is called #destroy() should not be called session.detach(); @@ -72,7 +72,7 @@ public class SessionDestroyTest extends WicketTestCase session.detach(); session.detach(); verify(session, times(1)).invalidateNow(); - assertThat(session.isSessionInvalidated(), is(false)); + assertEquals(false, session.isSessionInvalidated()); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/StoredResponsesMapTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/StoredResponsesMapTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/StoredResponsesMapTest.java index d28bbd9..f525314 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/StoredResponsesMapTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/StoredResponsesMapTest.java @@ -16,24 +16,28 @@ */ package org.apache.wicket.protocol.http; +import static org.junit.jupiter.api.Assertions.assertEquals; +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.security.SecureRandom; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.apache.wicket.util.SlowTests; +import org.apache.wicket.util.WicketTestTag; import org.apache.wicket.util.time.Duration; import org.apache.wicket.util.time.Time; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * @see <a href="https://issues.apache.org/jira/browse/WICKET-3209">WICKET-3209</a> */ -@Category(SlowTests.class) -public class StoredResponsesMapTest extends Assert +@Tag(WicketTestTag.SLOW) +class StoredResponsesMapTest { /** * Verifies that {@link StoredResponsesMap} will expire the oldest entry if it is older than 2 @@ -42,7 +46,7 @@ public class StoredResponsesMapTest extends Assert * @throws Exception */ @Test - public void entriesLife2Seconds() throws Exception + void entriesLife2Seconds() throws Exception { StoredResponsesMap map = new StoredResponsesMap(1000, Duration.seconds(2)); assertEquals(0, map.size()); @@ -60,7 +64,7 @@ public class StoredResponsesMapTest extends Assert * @throws Exception */ @Test - public void getExpiredValue() throws Exception + void getExpiredValue() throws Exception { Time start = Time.now(); Duration timeout = Duration.milliseconds(50); @@ -69,7 +73,7 @@ public class StoredResponsesMapTest extends Assert map.put("1", new BufferedWebResponse(null)); assertEquals(1, map.size()); TimeUnit.MILLISECONDS.sleep(timeout.getMilliseconds() * 2); // sleep for twice longer than the timeout - assertTrue("The timeout has passed.", Time.now().subtract(start).compareTo(timeout) == 1); + assertTrue(Time.now().subtract(start).compareTo(timeout) == 1, "The timeout has passed."); Object value = map.get("1"); assertNull(value); } @@ -77,11 +81,14 @@ public class StoredResponsesMapTest extends Assert /** * Verifies that {@link StoredResponsesMap} can have only {@link BufferedWebResponse} values */ - @Test(expected = IllegalArgumentException.class) - public void cannotPutArbitraryValue() + @Test + void cannotPutArbitraryValue() { StoredResponsesMap map = new StoredResponsesMap(1000, Duration.days(1)); - map.put("1", new Object()); + assertThrows(IllegalArgumentException.class, () -> { + map.put("1", new Object()); + }); + } /** @@ -89,14 +96,11 @@ public class StoredResponsesMapTest extends Assert * * Tries to simulate heavy load on the {@link StoredResponsesMap} by putting many entries and * removing randomly them. - * - * The test is disabled by default because it is slow (~ 30secs). Enable it when we have - * categorized tests ({@link Category}) and run slow ones only at Apache CI servers - * + * * @throws InterruptedException */ @Test - public void heavyLoad() throws InterruptedException + void heavyLoad() throws InterruptedException { final int numberOfThreads = 100; final int iterations = 1000; http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebApplicationTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebApplicationTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebApplicationTest.java index ba6b175..951f64b 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebApplicationTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebApplicationTest.java @@ -16,12 +16,16 @@ */ package org.apache.wicket.protocol.http; +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 static org.junit.jupiter.api.Assertions.fail; + import java.nio.charset.Charset; import java.util.Enumeration; import java.util.Iterator; import java.util.Locale; import java.util.Map; - import javax.servlet.http.HttpServletRequest; import org.apache.wicket.mock.MockRequestParameters; @@ -35,26 +39,79 @@ import org.apache.wicket.request.mapper.CompoundRequestMapper; import org.apache.wicket.request.mapper.ICompoundRequestMapper; import org.apache.wicket.request.mapper.IRequestMapperDelegate; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test WebApplication */ -public class WebApplicationTest extends WicketTestCase +class WebApplicationTest extends WicketTestCase { private static final String MOUNT_PATH_1 = "mount/path/1"; private static final String MOUNT_PATH_2 = "mount/path/2"; private static final String MOUNT_PATH_3 = "mount/path/3"; private static final String MOUNT_PATH_4 = "mount/path/4"; + private static Request createMockRequest(String path) + { + final Url url = Url.parse(path); + + return new Request() + { + @Override + public Url getUrl() + { + return url; + } + + @Override + public Url getClientUrl() + { + return url; + } + + @Override + public Locale getLocale() + { + return null; + } + + @Override + public Charset getCharset() + { + return null; + } + + @Override + public Object getContainerRequest() + { + return null; + } + }; + } + + private static int getCompoundRequestMapperSize(ICompoundRequestMapper compound) + { + int retv = 0; + + for (Iterator<IRequestMapper> it = compound.iterator(); it.hasNext();) + { + it.next(); + retv++; + } + + return retv; + } + /** * WICKET-6260 */ @Test - public void testBodyNotReadBeforeApplicationSetsCharacterEncoding() throws Exception { + void testBodyNotReadBeforeApplicationSetsCharacterEncoding() throws Exception + { WebApplication application = tester.getApplication(); - HttpServletRequest request = new MockHttpServletRequest(application, null, null) { + HttpServletRequest request = new MockHttpServletRequest(application, null, null) + { @Override public Map<String, String[]> getParameterMap() { @@ -94,7 +151,7 @@ public class WebApplicationTest extends WicketTestCase // character encoding not set yet request.setCharacterEncoding(null); - application.createWebRequest(request , "/"); + application.createWebRequest(request, "/"); assertEquals("UTF-8", request.getCharacterEncoding()); } @@ -103,7 +160,7 @@ public class WebApplicationTest extends WicketTestCase * Test basic unmounting from a compound mapper. */ @Test - public void testUnmountSimple() + void testUnmountSimple() { CompoundRequestMapper compound = new CompoundRequestMapper(); @@ -117,23 +174,27 @@ public class WebApplicationTest extends WicketTestCase tester.getApplication().unmount(MOUNT_PATH_1); - assertEquals("Compound size should be 3", 3, getCompoundRequestMapperSize(compound)); + assertEquals(3, getCompoundRequestMapperSize(compound), "Compound size should be 3"); - assertNull("Mount path 1 should not be mounted", - tester.getApplication().getRootRequestMapper().mapRequest(createMockRequest(MOUNT_PATH_1))); + assertNull(tester.getApplication().getRootRequestMapper().mapRequest( + createMockRequest(MOUNT_PATH_1)), "Mount path 1 should not be mounted"); - assertTrue("Mount path 2 should match", - tester.getApplication().getRootRequestMapper().mapRequest(createMockRequest(MOUNT_PATH_2)) instanceof EmptyRequestHandler); + assertTrue( + tester.getApplication().getRootRequestMapper().mapRequest( + createMockRequest(MOUNT_PATH_2)) instanceof EmptyRequestHandler, + "Mount path 2 should match"); - assertTrue("Mount path 3 should match", - tester.getApplication().getRootRequestMapper().mapRequest(createMockRequest(MOUNT_PATH_3)) instanceof EmptyRequestHandler); + assertTrue( + tester.getApplication().getRootRequestMapper().mapRequest( + createMockRequest(MOUNT_PATH_3)) instanceof EmptyRequestHandler, + "Mount path 3 should match"); } /** * See https://issues.apache.org/jira/browse/WICKET-5698 */ @Test - public void testUnmountComplex() + void testUnmountComplex() { CompoundRequestMapper nestedCompound = new CompoundRequestMapper(); @@ -153,84 +214,42 @@ public class WebApplicationTest extends WicketTestCase tester.getApplication().unmount(MOUNT_PATH_1); - assertEquals("Compound size should be 2", 2, getCompoundRequestMapperSize(nestedCompound)); - - assertNull("Mount path 1 should not be mounted", - tester.getApplication().getRootRequestMapper().mapRequest(createMockRequest(MOUNT_PATH_1))); + assertEquals(2, getCompoundRequestMapperSize(nestedCompound), "Compound size should be 2"); + assertNull(tester.getApplication().getRootRequestMapper().mapRequest( + createMockRequest(MOUNT_PATH_1)), "Mount path 1 should not be mounted"); - assertTrue("Mount path 2 should match", - tester.getApplication().getRootRequestMapper().mapRequest(createMockRequest(MOUNT_PATH_2)) instanceof EmptyRequestHandler); + assertTrue( + tester.getApplication().getRootRequestMapper().mapRequest( + createMockRequest(MOUNT_PATH_2)) instanceof EmptyRequestHandler, + "Mount path 2 should match"); - assertTrue("Mount path 3 should match", - tester.getApplication().getRootRequestMapper().mapRequest(createMockRequest(MOUNT_PATH_3)) instanceof EmptyRequestHandler); + assertTrue( + tester.getApplication().getRootRequestMapper().mapRequest( + createMockRequest(MOUNT_PATH_3)) instanceof EmptyRequestHandler, + "Mount path 3 should match"); - assertTrue("Mount path 4 should match", - tester.getApplication().getRootRequestMapper().mapRequest(createMockRequest(MOUNT_PATH_4)) instanceof EmptyRequestHandler); + assertTrue( + tester.getApplication().getRootRequestMapper().mapRequest( + createMockRequest(MOUNT_PATH_4)) instanceof EmptyRequestHandler, + "Mount path 4 should match"); tester.getApplication().unmount(MOUNT_PATH_3); - assertNull("Mount path 1 should not be mounted", - tester.getApplication().getRootRequestMapper().mapRequest(createMockRequest(MOUNT_PATH_1))); + assertNull(tester.getApplication().getRootRequestMapper().mapRequest( + createMockRequest(MOUNT_PATH_1)), "Mount path 1 should not be mounted"); - assertTrue("Mount path 2 should match", - tester.getApplication().getRootRequestMapper().mapRequest(createMockRequest(MOUNT_PATH_2)) instanceof EmptyRequestHandler); + assertTrue( + tester.getApplication().getRootRequestMapper().mapRequest( + createMockRequest(MOUNT_PATH_2)) instanceof EmptyRequestHandler, + "Mount path 2 should match"); - assertNull("Mount path 3 should not be mounted", - tester.getApplication().getRootRequestMapper().mapRequest(createMockRequest(MOUNT_PATH_3))); - - assertTrue("Mount path 4 should match", - tester.getApplication().getRootRequestMapper().mapRequest(createMockRequest(MOUNT_PATH_4)) instanceof EmptyRequestHandler); - } - - private static Request createMockRequest(String path) - { - final Url url = Url.parse(path); + assertNull(tester.getApplication().getRootRequestMapper().mapRequest( + createMockRequest(MOUNT_PATH_3)), "Mount path 3 should not be mounted"); - return new Request() - { - @Override - public Url getUrl() - { - return url; - } - - @Override - public Url getClientUrl() - { - return url; - } - - @Override - public Locale getLocale() - { - return null; - } - - @Override - public Charset getCharset() - { - return null; - } - - @Override - public Object getContainerRequest() - { - return null; - } - }; - } - - private static int getCompoundRequestMapperSize(ICompoundRequestMapper compound) - { - int retv = 0; - - for (Iterator<IRequestMapper> it = compound.iterator(); it.hasNext();) - { - it.next(); - retv++; - } - - return retv; + assertTrue( + tester.getApplication().getRootRequestMapper().mapRequest( + createMockRequest(MOUNT_PATH_4)) instanceof EmptyRequestHandler, + "Mount path 4 should match"); } private static class MountMapper implements IRequestMapper @@ -238,7 +257,7 @@ public class WebApplicationTest extends WicketTestCase private final String path; private final IRequestHandler handler; - public MountMapper(String path, EmptyRequestHandler handler) + MountMapper(String path, EmptyRequestHandler handler) { this.path = path; this.handler = handler; @@ -271,7 +290,7 @@ public class WebApplicationTest extends WicketTestCase { private final IRequestMapper delegate; - public SimpleRequestMapperDelegate(IRequestMapper delegate) + SimpleRequestMapperDelegate(IRequestMapper delegate) { this.delegate = delegate; } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java index 9152f0a..ba45ee5 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java @@ -16,35 +16,36 @@ */ package org.apache.wicket.protocol.http; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; +import org.apache.wicket.core.util.resource.WebExternalResourceStream; import org.apache.wicket.mock.MockApplication; import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; import org.apache.wicket.request.handler.resource.WebExternalResourceRequestHandler; import org.apache.wicket.util.io.Streams; -import org.apache.wicket.core.util.resource.WebExternalResourceStream; import org.apache.wicket.util.tester.WicketTester; -import org.junit.After; -import org.junit.Assert; -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; /** * Test WebExternalResourceRequestTarget and WebExternalResourceStream * * @author <a href="mailto:[email protected]">Jean-Baptiste Quenot</a> */ -public class WebExternalResourceTest extends Assert +class WebExternalResourceTest { private WicketTester tester; /** * @throws Exception */ - @Before - public void before() throws Exception + @BeforeEach + void before() throws Exception { File tempDir = new File("target/webapp"); tempDir.mkdir(); @@ -62,8 +63,8 @@ public class WebExternalResourceTest extends Assert } - @After - public void after() throws Exception + @AfterEach + void after() throws Exception { tester.destroy(); } @@ -73,7 +74,7 @@ public class WebExternalResourceTest extends Assert * @throws Exception */ @Test - public void webExternalResourceRequestTarget() throws Exception + void webExternalResourceRequestTarget() throws Exception { WebExternalResourceRequestHandler rt = new WebExternalResourceRequestHandler("/index.html"); tester.processRequest(rt); @@ -87,7 +88,7 @@ public class WebExternalResourceTest extends Assert */ // FIXME WebExternalResourceStream does not implement length() @Test - public void webExternalResource() throws Exception + void webExternalResource() throws Exception { WebExternalResourceStream resource = new WebExternalResourceStream("/index.html"); ResourceStreamRequestHandler rt = new ResourceStreamRequestHandler(resource); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebResponseExceptionsTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebResponseExceptionsTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebResponseExceptionsTest.java index 06298cf..bcfb644 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebResponseExceptionsTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebResponseExceptionsTest.java @@ -16,27 +16,29 @@ */ package org.apache.wicket.protocol.http; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.html.pages.PageExpiredErrorPage; import org.apache.wicket.settings.ExceptionSettings; import org.apache.wicket.settings.RequestCycleSettings; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Test; - +import org.junit.jupiter.api.Test; /** * Test exceptions thrown during request * * @author <a href="mailto:[email protected]">Jean-Baptiste Quenot</a> */ -public class WebResponseExceptionsTest extends WicketTestCase +class WebResponseExceptionsTest extends WicketTestCase { /** * Tests buffered exception error page. */ @Test - public void bufferedExceptionErrorPage() + void bufferedExceptionErrorPage() { tester.getApplication() .getRequestCycleSettings() @@ -51,7 +53,7 @@ public class WebResponseExceptionsTest extends WicketTestCase * Tests exception error page. */ @Test - public void exceptionErrorPage() + void exceptionErrorPage() { tester.getApplication() .getExceptionSettings() @@ -63,7 +65,7 @@ public class WebResponseExceptionsTest extends WicketTestCase * Tests page expired. */ @Test - public void expirePage() + void expirePage() { tester.startPage(TestExpirePage.class); String document = tester.getLastResponseAsString(); @@ -85,7 +87,7 @@ public class WebResponseExceptionsTest extends WicketTestCase * Tests internal error page. */ @Test - public void internalErrorPage() + void internalErrorPage() { tester.startPage(TestErrorPage.class); tester.setExposeExceptions(false); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebSessionTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebSessionTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebSessionTest.java index 23ac0b0..27b3e85 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebSessionTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WebSessionTest.java @@ -16,23 +16,24 @@ */ package org.apache.wicket.protocol.http; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.Locale; import org.apache.wicket.mock.MockWebRequest; import org.apache.wicket.request.Url; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Timo Rantalaiho */ -public class WebSessionTest extends Assert +class WebSessionTest { /** * testReadsLocaleFromRequestOnConstruction() */ @Test - public void readsLocaleFromRequestOnConstruction() + void readsLocaleFromRequestOnConstruction() { final Locale locale = Locale.TRADITIONAL_CHINESE; MockWebRequest request = new MockWebRequest(Url.parse("/")) http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java index 54141c4..c12737c 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java @@ -16,8 +16,16 @@ */ package org.apache.wicket.protocol.http; -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.Mockito.*; +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 static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.io.IOException; import java.io.InputStream; @@ -34,7 +42,6 @@ import java.util.TimeZone; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; - import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletContext; @@ -55,16 +62,14 @@ import org.apache.wicket.request.http.WebRequest; import org.apache.wicket.request.resource.AbstractResource; import org.apache.wicket.request.resource.DynamicImageResource; import org.apache.wicket.request.resource.IResource; -import org.apache.wicket.util.SlowTests; +import org.apache.wicket.util.WicketTestTag; import org.apache.wicket.util.file.WebXmlFile; import org.apache.wicket.util.string.Strings; import org.apache.wicket.util.tester.DummyHomePage; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; -import org.mockito.Matchers; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -72,7 +77,7 @@ import org.xml.sax.SAXException; /** */ -public class WicketFilterTest extends Assert +public class WicketFilterTest { private static WebApplication application; private final DateFormat headerDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z", @@ -81,8 +86,8 @@ public class WicketFilterTest extends Assert /** * @throws Exception */ - @After - public void after() throws Exception + @AfterEach + void after() throws Exception { if (application != null) { @@ -108,7 +113,7 @@ public class WicketFilterTest extends Assert * @throws Exception */ @Test - public void parsingOfAnnotatedServlet3FiltersWorks() throws Exception + void parsingOfAnnotatedServlet3FiltersWorks() throws Exception { FilterTestingConfig config = new FilterTestingConfig(); config.initParameters.clear(); @@ -118,19 +123,19 @@ public class WicketFilterTest extends Assert // creates an Application filter.init(config); - // get a reference to the application, so that @After is able to clean it up + // get a reference to the application, so that @AfterEach is able to clean it up application = filter.getApplication(); // assert that the filter path is not /web/*/ - assertThat(filter.getFilterPath(), is("web/")); + assertEquals("web/", filter.getFilterPath()); } /** * testFilterPath1() */ @Test - @Category(SlowTests.class) - public void filterPath1() + @Tag(WicketTestTag.SLOW) + void filterPath1() { InputStream in = WicketFilterTest.class.getResourceAsStream("web1.xml"); String filterPath = getFilterPath("FilterTestApplication", in); @@ -141,8 +146,8 @@ public class WicketFilterTest extends Assert * testFilterPath2() */ @Test - @Category(SlowTests.class) - public void filterPath2() + @Tag(WicketTestTag.SLOW) + void filterPath2() { InputStream in = WicketFilterTest.class.getResourceAsStream("web2.xml"); String filterPath = getFilterPath("FilterTestApplication", in); @@ -155,7 +160,7 @@ public class WicketFilterTest extends Assert * @throws ParseException */ @Test - public void notModifiedResponseIncludesExpiresHeader() throws IOException, ServletException, + void notModifiedResponseIncludesExpiresHeader() throws IOException, ServletException, ParseException { try @@ -198,12 +203,10 @@ public class WicketFilterTest extends Assert }); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatus()); String responseExpiresHeader = response.getHeader("Expires"); - assertNotNull("Expires header must be set on not modified response", - responseExpiresHeader); + assertNotNull(responseExpiresHeader, "Expires header must be set on not modified response"); Date responseExpires = headerDateFormat.parse(responseExpiresHeader); - assertTrue("Expected later than current date but was " + responseExpires, - responseExpires.after(new Date())); + assertTrue(responseExpires.after(new Date()), "Expected later than current date but was " + responseExpires); } finally { @@ -212,7 +215,7 @@ public class WicketFilterTest extends Assert } @Test - public void options() throws IOException, ServletException, ParseException + void options() throws IOException, ServletException, ParseException { try { @@ -305,11 +308,11 @@ public class WicketFilterTest extends Assert } } - private static class FilterTestingConfig implements FilterConfig + public static class FilterTestingConfig implements FilterConfig { private final Map<String, String> initParameters = new HashMap<>(); - public FilterTestingConfig() + public FilterTestingConfig() { initParameters.put(WicketFilter.APP_FACT_PARAM, FilterTestingApplicationFactory.class.getName()); @@ -346,7 +349,7 @@ public class WicketFilterTest extends Assert /** */ - public static class FilterTestingApplicationFactory implements IWebApplicationFactory + public static class FilterTestingApplicationFactory implements IWebApplicationFactory { @Override public WebApplication createApplication(WicketFilter filter) @@ -365,13 +368,13 @@ public class WicketFilterTest extends Assert * testCheckRedirect_1() */ @Test - public void checkRedirect_1() + void checkRedirect_1() { WicketFilter filter = new WicketFilter(); // Simulate url-pattern = "/*" and request = http://localhost:8080 => null == no redirect filter.setFilterPath(""); - assertNull("", filter.checkIfRedirectRequired("/", "")); + assertNull(filter.checkIfRedirectRequired("/", "")); } private static class CheckRedirectWorker implements Runnable @@ -381,8 +384,8 @@ public class WicketFilterTest extends Assert private final CountDownLatch finishLatch; private final AtomicInteger successCount; - public CheckRedirectWorker(WicketFilter filter, CountDownLatch startLatch, - CountDownLatch finishLatch, AtomicInteger successCount) + CheckRedirectWorker(WicketFilter filter, CountDownLatch startLatch, + CountDownLatch finishLatch, AtomicInteger successCount) { this.filter = filter; this.startLatch = startLatch; @@ -440,8 +443,8 @@ public class WicketFilterTest extends Assert { fail(); } - assertEquals("all threads finished", 0, finishLatch.getCount()); - assertEquals("all redirects correct", threadCount, successCount.get()); + assertEquals(0, finishLatch.getCount(), "all threads finished"); + assertEquals(threadCount, successCount.get(), "all threads finished"); } /** @@ -450,7 +453,7 @@ public class WicketFilterTest extends Assert * Runs 1000 times 8 simultaneous threads which try to initialize WicketFilter#filterPathLength */ @Test - public void repeatedParallelCheckRedirect() + void repeatedParallelCheckRedirect() { int threadCount = 8; int repeatCount = 1000; @@ -466,7 +469,7 @@ public class WicketFilterTest extends Assert * @throws Exception */ @Test - public void ignorePaths() throws Exception + void ignorePaths() throws Exception { application = spy(new MockApplication()); WicketFilter filter = new WicketFilter(); @@ -519,7 +522,7 @@ public class WicketFilterTest extends Assert * </p> */ @Test - public void canonicaliseFilterPath() + void canonicaliseFilterPath() { String s; http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketURLTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketURLTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketURLTest.java index 2098ec8..52e3158 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketURLTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/WicketURLTest.java @@ -16,21 +16,22 @@ */ package org.apache.wicket.protocol.http; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.apache.wicket.util.encoding.UrlDecoder; import org.apache.wicket.util.encoding.UrlEncoder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Doug Donohoe */ -public class WicketURLTest extends Assert +class WicketURLTest { /** * testPathEncoder() */ @Test - public void pathEncoder() + void pathEncoder() { assertEquals("+", UrlEncoder.PATH_INSTANCE.encode("+", "UTF-8")); assertEquals("%20", UrlEncoder.PATH_INSTANCE.encode(" ", "UTF-8")); @@ -40,7 +41,7 @@ public class WicketURLTest extends Assert * testQueryEncoder() */ @Test - public void queryEncoder() + void queryEncoder() { assertEquals("+", UrlEncoder.QUERY_INSTANCE.encode(" ", "UTF-8")); assertEquals("%2B", UrlEncoder.QUERY_INSTANCE.encode("+", "UTF-8")); @@ -50,7 +51,7 @@ public class WicketURLTest extends Assert * testPathDecoder() */ @Test - public void pathDecoder() + void pathDecoder() { assertEquals("+", UrlDecoder.PATH_INSTANCE.decode("+", "UTF-8")); assertEquals(" ", UrlDecoder.PATH_INSTANCE.decode("%20", "UTF-8")); @@ -60,7 +61,7 @@ public class WicketURLTest extends Assert * testQueryDecoder() */ @Test - public void queryDecoder() + void queryDecoder() { assertEquals(" ", UrlDecoder.QUERY_INSTANCE.decode("+", "UTF-8")); assertEquals("+", UrlDecoder.QUERY_INSTANCE.decode("%2B", "UTF-8")); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/CookiesTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/CookiesTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/CookiesTest.java index f9c8b2e..bdf87ec 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/CookiesTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/CookiesTest.java @@ -16,18 +16,20 @@ */ package org.apache.wicket.protocol.http.mock; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import javax.servlet.http.Cookie; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for Cookies helper class */ -public class CookiesTest extends Assert +class CookiesTest { @Test - public void testIsEqual() throws Exception + void testIsEqual() throws Exception { Cookie c1 = new Cookie("Name", "Value"); Cookie c2 = new Cookie("Name", "Value"); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequestTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequestTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequestTest.java index 5219518..640154e 100755 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequestTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletRequestTest.java @@ -16,26 +16,28 @@ */ package org.apache.wicket.protocol.http.mock; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; + import java.util.Enumeration; import java.util.Locale; - import javax.servlet.http.HttpSession; import org.apache.wicket.Session; import org.apache.wicket.request.Url; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import static org.hamcrest.Matchers.is; - /** * test features of {@link MockHttpServletRequest} */ -public class MockHttpServletRequestTest extends WicketTestCase +class MockHttpServletRequestTest extends WicketTestCase { @Test - public void setAbsoluteUrlWithHost() + void setAbsoluteUrlWithHost() { MockHttpServletRequest request = tester.getRequest(); assertEquals("http", request.getScheme()); @@ -59,7 +61,7 @@ public class MockHttpServletRequestTest extends WicketTestCase } @Test - public void setAbsoluteUrlWithoutHost() + void setAbsoluteUrlWithoutHost() { MockHttpServletRequest request = tester.getRequest(); assertEquals("http", request.getScheme()); @@ -83,7 +85,7 @@ public class MockHttpServletRequestTest extends WicketTestCase } @Test - public void setRelativeUrl() + void setRelativeUrl() { MockHttpServletRequest request = tester.getRequest(); assertEquals("http", request.getScheme()); @@ -110,7 +112,7 @@ public class MockHttpServletRequestTest extends WicketTestCase * WICKET-4664 - no query string returns null as per HttpServletRequest */ @Test - public void testNoQueryString_returnsNull() + void testNoQueryString_returnsNull() { MockHttpServletRequest request = tester.getRequest(); request.setURL("my/servlet/without/query/param"); @@ -120,43 +122,43 @@ public class MockHttpServletRequestTest extends WicketTestCase } @Test - public void getSessionFromNonMockHttpSession() + void getSessionFromNonMockHttpSession() { HttpSession httpSession = Mockito.mock(HttpSession.class); MockHttpServletRequest request = new MockHttpServletRequest(null, httpSession, null); - assertNull("MockHttpServletRequest knows how to work only with MockHttpSession", request.getSession(true)); - assertNull("MockHttpServletRequest knows how to work only with MockHttpSession", request.getSession(false)); + assertNull(request.getSession(true), "MockHttpServletRequest knows how to work only with MockHttpSession"); + assertNull(request.getSession(false), "MockHttpServletRequest knows how to work only with MockHttpSession"); } @Test - public void getSessionFalseFromMockHttpSession() + void getSessionFalseFromMockHttpSession() { HttpSession httpSession = new MockHttpSession(null); MockHttpServletRequest request = new MockHttpServletRequest(null, httpSession, null); - assertNull("HttpSession should not be created!", request.getSession(false)); + assertNull(request.getSession(false), "HttpSession should not be created!"); } @Test - public void getSessionDefaultFromMockHttpSession() + void getSessionDefaultFromMockHttpSession() { HttpSession httpSession = new MockHttpSession(null); MockHttpServletRequest request = new MockHttpServletRequest(null, httpSession, null); - assertSame("HttpSession should be created!", httpSession, request.getSession()); + assertSame(httpSession, request.getSession(), "HttpSession should be created!"); } @Test - public void getSessionTrueFromMockHttpSession() + void getSessionTrueFromMockHttpSession() { HttpSession httpSession = new MockHttpSession(null); MockHttpServletRequest request = new MockHttpServletRequest(null, httpSession, null); - assertSame("HttpSession should be created!", httpSession, request.getSession(true)); + assertSame(httpSession, request.getSession(true), "HttpSession should be created!"); } /** * https://issues.apache.org/jira/browse/WICKET-4481 */ @Test - public void setHeader() + void setHeader() { HttpSession httpSession = new MockHttpSession(null); MockHttpServletRequest request = new MockHttpServletRequest(null, httpSession, null); @@ -177,13 +179,13 @@ public class MockHttpServletRequestTest extends WicketTestCase } @Test - public void setLocale() { + void setLocale() { Session session = tester.getSession(); session.setLocale(Locale.US); tester.getRequest().setLocale(Locale.CANADA_FRENCH); session.invalidateNow(); - assertThat(tester.getSession().getLocale(), is(Locale.CANADA_FRENCH)); + assertEquals(Locale.CANADA_FRENCH, tester.getSession().getLocale()); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletResponseTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletResponseTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletResponseTest.java index 0fecf8e..990ea0d 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletResponseTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/mock/MockHttpServletResponseTest.java @@ -16,27 +16,28 @@ */ package org.apache.wicket.protocol.http.mock; -import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import java.util.List; import javax.servlet.http.Cookie; -import org.junit.After; -import org.junit.Assert; -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 MockHttpServletResponse} */ -public class MockHttpServletResponseTest extends Assert +class MockHttpServletResponseTest { private MockHttpServletResponse response; /** * Prepare */ - @Before - public void before() + @BeforeEach + void before() { response = new MockHttpServletResponse(null); } @@ -44,8 +45,8 @@ public class MockHttpServletResponseTest extends Assert /** * Clean up */ - @After - public void after() + @AfterEach + void after() { response = null; } @@ -54,7 +55,7 @@ public class MockHttpServletResponseTest extends Assert * Add a cookie */ @Test - public void addCookie() + void addCookie() { Cookie cookie = new Cookie("name", "value"); response.addCookie(cookie); @@ -76,7 +77,7 @@ public class MockHttpServletResponseTest extends Assert * https://issues.apache.org/jira/browse/WICKET-4292 */ @Test - public void addDuplicateCookie() + void addDuplicateCookie() { Cookie cookie1 = new Cookie("name", "value"); response.addCookie(cookie1); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategyTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategyTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategyTest.java index 98e1bf4..ead2b87 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategyTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/CryptedUrlWebRequestCodingStrategyTest.java @@ -16,6 +16,8 @@ */ package org.apache.wicket.protocol.http.request; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.Base64; import org.apache.wicket.core.request.mapper.CryptoMapper; @@ -27,12 +29,12 @@ import org.apache.wicket.request.mapper.CompoundRequestMapper; import org.apache.wicket.util.crypt.ICrypt; import org.apache.wicket.util.crypt.ICryptFactory; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Simple test using the WicketTester */ -public class CryptedUrlWebRequestCodingStrategyTest extends WicketTestCase +class CryptedUrlWebRequestCodingStrategyTest extends WicketTestCase { @Override @@ -57,7 +59,7 @@ public class CryptedUrlWebRequestCodingStrategyTest extends WicketTestCase * */ @Test - public void clientBidListPage() + void clientBidListPage() { WebPage page = new SimplePage(); WebPage p = (WebPage)tester.startPage(page); @@ -68,7 +70,7 @@ public class CryptedUrlWebRequestCodingStrategyTest extends WicketTestCase * testRenderMyPagePost() */ @Test - public void renderMyPagePost() + void renderMyPagePost() { // start and render the test page tester.startPage(HomePage.class); @@ -83,7 +85,7 @@ public class CryptedUrlWebRequestCodingStrategyTest extends WicketTestCase * testRenderMyPageGet() */ @Test - public void renderMyPageGet() + void renderMyPageGet() { // 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/protocol/http/request/WebClientInfoTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java index ca7089f..033e597 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/request/WebClientInfoTest.java @@ -16,30 +16,23 @@ */ package org.apache.wicket.protocol.http.request; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.util.Arrays; -import java.util.List; - import javax.servlet.http.HttpServletRequest; import org.apache.wicket.protocol.http.servlet.ServletWebRequest; import org.apache.wicket.request.cycle.RequestCycle; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; /** * Tests the WebClientInfo class */ -public class WebClientInfoTest +class WebClientInfoTest { private RequestCycle requestCycleMock; private ServletWebRequest webRequest; @@ -48,8 +41,8 @@ public class WebClientInfoTest /** * Prepare RequestCycle to be able to extract the remote address of the client */ - @Before - public void before() + @BeforeEach + void before() { requestCycleMock = mock(RequestCycle.class); @@ -64,13 +57,13 @@ public class WebClientInfoTest * Test X-Forwarded-For ip address extraction. */ @Test - public void testExtractFromXForwardedForHeader() + void testExtractFromXForwardedForHeader() { String expected = "127.0.0.1"; when(webRequest.getHeader("X-Forwarded-For")).thenReturn(expected); WebClientInfo clientInfo = new WebClientInfo(requestCycleMock, "No user agent"); String actual = clientInfo.getRemoteAddr(requestCycleMock); - assertThat(actual, is(equalTo(expected))); + assertEquals(expected, actual); Mockito.verifyZeroInteractions(servletRequest); } @@ -81,55 +74,55 @@ public class WebClientInfoTest * will resolve to some DNS service saying "'blah' domain is free. Buy it." */ @Test - @Ignore - public void testExtractFromContainerRequestUnknownXForwardedFor() + @Disabled + void testExtractFromContainerRequestUnknownXForwardedFor() { String expected = "10.17.37.8"; when(servletRequest.getRemoteAddr()).thenReturn(expected); when(webRequest.getHeader("X-Forwarded-For")).thenReturn("unknown"); WebClientInfo clientInfo = new WebClientInfo(requestCycleMock, "No user agent"); String actual = clientInfo.getRemoteAddr(requestCycleMock); - assertThat(actual, is(equalTo(expected))); + assertEquals(expected, actual); } /** * Test default ip address extraction for container request. */ @Test - public void testExtractFromContainerRequestNoXForwardedFor() + void testExtractFromContainerRequestNoXForwardedFor() { String expected = "10.17.37.8"; when(servletRequest.getRemoteAddr()).thenReturn(expected); WebClientInfo clientInfo = new WebClientInfo(requestCycleMock, "No user agent"); String actual = clientInfo.getRemoteAddr(requestCycleMock); - assertThat(actual, is(equalTo(expected))); + assertEquals(expected, actual); } /** * Test X-Forwarded-For ip address extraction when proxy chain is given. */ @Test - public void testExtractFromXForwardedForHeaderChainedIps() + void testExtractFromXForwardedForHeaderChainedIps() { String expected = "10.17.37.156"; when(servletRequest.getRemoteAddr()).thenReturn("10.17.1.1"); when(webRequest.getHeader("X-Forwarded-For")).thenReturn(expected + ", 10.17.37.1"); WebClientInfo clientInfo = new WebClientInfo(requestCycleMock, "No user agent"); String actual = clientInfo.getRemoteAddr(requestCycleMock); - assertThat(actual, is(equalTo(expected))); + assertEquals(expected, actual); } /** * Test X-Forwarded-For ipv6 address extraction. */ @Test - public void testExtractFromXForwardedForHeaderIPv6() + void testExtractFromXForwardedForHeaderIPv6() { String expected = "2001:db8::1428:57"; when(webRequest.getHeader("X-Forwarded-For")).thenReturn("2001:db8::1428:57"); WebClientInfo clientInfo = new WebClientInfo(requestCycleMock, "No user agent"); String actual = clientInfo.getRemoteAddr(requestCycleMock); - assertThat(actual, is(equalTo(expected))); + assertEquals(expected, actual); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/SecuredRemoteAddressRequestWrapperFactoryTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/SecuredRemoteAddressRequestWrapperFactoryTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/SecuredRemoteAddressRequestWrapperFactoryTest.java index dead915..1c3fb53 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/SecuredRemoteAddressRequestWrapperFactoryTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/SecuredRemoteAddressRequestWrapperFactoryTest.java @@ -16,21 +16,24 @@ */ package org.apache.wicket.protocol.http.servlet; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.apache.wicket.protocol.http.mock.MockHttpServletRequest; import org.apache.wicket.util.tester.WicketTestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * * @author Juergen Donnerstag */ -public class SecuredRemoteAddressRequestWrapperFactoryTest extends WicketTestCase +class SecuredRemoteAddressRequestWrapperFactoryTest extends WicketTestCase { /** * */ @Test - public void test1() + void test1() { SecuredRemoteAddressRequestWrapperFactory factory = new SecuredRemoteAddressRequestWrapperFactory(); MockHttpServletRequest request = tester.getRequest(); http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java index 33d9914..5033a20 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebRequestTest.java @@ -16,7 +16,9 @@ */ package org.apache.wicket.protocol.http.servlet; -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.fail; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -33,13 +35,12 @@ import org.apache.wicket.request.http.flow.AbortWithHttpErrorCodeException; import org.apache.wicket.util.resource.IResourceStream; import org.apache.wicket.util.resource.StringResourceStream; import org.apache.wicket.util.tester.WicketTester; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link ServletWebRequest} */ -public class ServletWebRequestTest extends Assert +class ServletWebRequestTest { /** @@ -48,7 +49,7 @@ public class ServletWebRequestTest extends Assert * returns just the request uri to the error page without the query string */ @Test - public void wicket3599() + void wicket3599() { MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null); httpRequest.setURL(httpRequest.getContextPath() + "/request/Uri"); @@ -71,7 +72,7 @@ public class ServletWebRequestTest extends Assert * <a href="https://issues.apache.org/jira/browse/WICKET-4168">WICKET-4168</a> */ @Test - public void testClientURLIsContextRelativeInErrorResponses() + void testClientURLIsContextRelativeInErrorResponses() { MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null); httpRequest.setURL(httpRequest.getContextPath() + "/request/Uri"); @@ -93,7 +94,7 @@ public class ServletWebRequestTest extends Assert * Relative Urls should be calculated against 'javax.servlet.forward.request_uri' */ @Test - public void parseForwardAttributes() + void parseForwardAttributes() { MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null); httpRequest.setURL(httpRequest.getContextPath() + "/request/Uri"); @@ -115,7 +116,7 @@ public class ServletWebRequestTest extends Assert * https://issues.apache.org/jira/browse/WICKET-4123 */ @Test - public void useCustomServletWebRequest() + void useCustomServletWebRequest() { WebApplication application = new WebApplication() { @@ -150,7 +151,7 @@ public class ServletWebRequestTest extends Assert * https://issues.apache.org/jira/browse/WICKET-4841 */ @Test - public void getClientUrlAjaxWithoutBaseUrl() + void getClientUrlAjaxWithoutBaseUrl() { MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null); @@ -173,7 +174,7 @@ public class ServletWebRequestTest extends Assert * returns just the request uri to the error page without the query string */ @Test - public void wicket5203() + void wicket5203() { String filterPath = "filterPath"; MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null); @@ -197,7 +198,7 @@ public class ServletWebRequestTest extends Assert * WICKET-5287 */ @Test - public void parseUrlWhichLooksLikeFullInItsContextRelativePart() + void parseUrlWhichLooksLikeFullInItsContextRelativePart() { String filterPath = "filterPath"; MockHttpServletRequest httpRequest = new MockHttpServletRequest(null, null, null); @@ -215,7 +216,7 @@ public class ServletWebRequestTest extends Assert private CustomRequestPage() { - assertThat(getRequest(), instanceOf(CustomServletWebRequest.class)); + assertThat(getRequest()).isInstanceOf(CustomServletWebRequest.class); } @Override @@ -228,7 +229,7 @@ public class ServletWebRequestTest extends Assert private static class CustomServletWebRequest extends ServletWebRequest { - public CustomServletWebRequest(HttpServletRequest httpServletRequest, String filterPrefix) + CustomServletWebRequest(HttpServletRequest httpServletRequest, String filterPrefix) { super(httpServletRequest, filterPrefix); } http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebResponseTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebResponseTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebResponseTest.java index 71626da..0dc54a8 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebResponseTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/ServletWebResponseTest.java @@ -16,6 +16,8 @@ */ package org.apache.wicket.protocol.http.servlet; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -23,7 +25,6 @@ import static org.mockito.Mockito.when; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -33,15 +34,13 @@ import org.apache.wicket.protocol.http.mock.MockHttpServletResponse; import org.apache.wicket.request.Url; import org.apache.wicket.request.UrlRenderer; import org.apache.wicket.request.cycle.RequestCycle; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; -import org.mockito.Matchers; /** * Tests for {@link ServletWebResponse} */ -public class ServletWebResponseTest extends Assert +class ServletWebResponseTest { /** @@ -52,7 +51,7 @@ public class ServletWebResponseTest extends Assert * @throws IOException */ @Test - public void sendRedirectAjax() throws IOException + void sendRedirectAjax() throws IOException { final String url = "./relative/path"; @@ -98,7 +97,7 @@ public class ServletWebResponseTest extends Assert * @throws IOException */ @Test - public void sendRedirect() throws IOException + void sendRedirect() throws IOException { final String url = "./relative/path"; @@ -124,7 +123,7 @@ public class ServletWebResponseTest extends Assert * WICKET-4934 DownloadLink uses wrong encoding for spaces/non-ASCII characters */ @Test - public void setDispositionHeader() + void setDispositionHeader() { ServletWebRequest webRequest = mock(ServletWebRequest.class); MockHttpServletRequest httpRequest = mock(MockHttpServletRequest.class); @@ -162,7 +161,7 @@ public class ServletWebResponseTest extends Assert * WICKET-5582 absolute URLs stay absolute after encoding */ @Test - public void encodeAbsoluteUrl() + void encodeAbsoluteUrl() { final String url = "http://localhost:8080/path"; @@ -191,7 +190,7 @@ public class ServletWebResponseTest extends Assert * WICKET-5582 absolute URLs stay absolute after encoding */ @Test - public void encodeRedirectAbsoluteUrl() + void encodeRedirectAbsoluteUrl() { final String url = "http://localhost:8080/path"; http://git-wip-us.apache.org/repos/asf/wicket/blob/645f239c/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilterTest.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilterTest.java b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilterTest.java index adeaf94..0e05b72 100644 --- a/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilterTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/protocol/http/servlet/WicketSessionFilterTest.java @@ -16,11 +16,13 @@ */ package org.apache.wicket.protocol.http.servlet; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.IOException; import java.lang.Thread.UncaughtExceptionHandler; import java.util.Enumeration; import java.util.concurrent.atomic.AtomicBoolean; - import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletContext; @@ -36,13 +38,12 @@ import org.apache.wicket.session.HttpSessionStore; import org.apache.wicket.util.tester.WicketTestCase; import org.apache.wicket.util.tester.WicketTester; import org.apache.wicket.util.time.Duration; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link WicketSessionFilter} */ -public class WicketSessionFilterTest extends WicketTestCase +class WicketSessionFilterTest extends WicketTestCase { @Override @@ -67,7 +68,7 @@ public class WicketSessionFilterTest extends WicketTestCase * @throws Exception */ @Test - public void applicationAndSessionAreExported() throws Exception + void applicationAndSessionAreExported() throws Exception { // bind the session so it can be found in TestSessionFilter tester.getSession().bind(); @@ -83,14 +84,14 @@ public class WicketSessionFilterTest extends WicketTestCase { TestSessionFilter sessionFilter = new TestSessionFilter(tester); - Assert.assertFalse(Application.exists()); - Assert.assertFalse(Session.exists()); + assertFalse(Application.exists()); + assertFalse(Session.exists()); sessionFilter.doFilter(tester.getRequest(), tester.getResponse(), new TestFilterChain()); - Assert.assertFalse(Application.exists()); - Assert.assertFalse(Session.exists()); + assertFalse(Application.exists()); + assertFalse(Session.exists()); } catch (Exception e) @@ -115,7 +116,7 @@ public class WicketSessionFilterTest extends WicketTestCase testThread.start(); testThread.join(Duration.seconds(1).getMilliseconds()); - Assert.assertTrue(failMessage.toString(), passed.get()); + assertTrue(passed.get(), failMessage.toString()); } /** @@ -124,7 +125,7 @@ public class WicketSessionFilterTest extends WicketTestCase */ private static class TestSessionFilter extends WicketSessionFilter { - public TestSessionFilter(final WicketTester tester) throws ServletException + TestSessionFilter(final WicketTester tester) throws ServletException { init(new FilterConfig() {
