wicket-core: Migrate to Junit 5

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/694ee32d
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/694ee32d
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/694ee32d

Branch: refs/heads/WICKET-6563
Commit: 694ee32dc63537c7fca22d0c0139a380882f2888
Parents: cba693f
Author: renoth <[email protected]>
Authored: Fri Aug 31 23:25:41 2018 +0200
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Wed Sep 26 16:12:57 2018 +0300

----------------------------------------------------------------------
 pom.xml                                         |   1 +
 .../wicket/util/tester/BaseWicketTester.java    |   4 +-
 .../apache/wicket/util/tester/WicketTester.java | 156 ++++++++++---------
 .../test/java/org/apache/wicket/TesterTest.java |   1 -
 .../handler/render/WebPageRendererTest.java     |   1 -
 5 files changed, 86 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/694ee32d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 39b9e56..7e74e89 100644
--- a/pom.xml
+++ b/pom.xml
@@ -516,6 +516,7 @@
                                <groupId>org.hamcrest</groupId>
                                <artifactId>java-hamcrest</artifactId>
                                <version>2.0.0.0</version>
+                               <scope>test</scope>
                        </dependency>
                        <dependency>
                                <groupId>org.eclipse.jetty</groupId>

http://git-wip-us.apache.org/repos/asf/wicket/blob/694ee32d/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java 
b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
index 313cb2d..92686b5 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
@@ -34,7 +34,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 import java.util.regex.Pattern;
-
 import javax.servlet.FilterConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.http.Cookie;
@@ -134,6 +133,7 @@ import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.util.time.Duration;
 import org.apache.wicket.util.visit.IVisit;
 import org.apache.wicket.util.visit.IVisitor;
+import org.opentest4j.AssertionFailedError;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -723,7 +723,7 @@ public class BaseWicketTester
                        {
                                if (redirectCount++ >= 100)
                                {
-                                       throw new AssertionError("Possible 
infinite redirect detected. Bailing out.");
+                                       throw new 
AssertionFailedError("Possible infinite redirect detected. Bailing out.");
                                }
 
                                Url newUrl = 
Url.parse(lastResponse.getRedirectLocation(),

http://git-wip-us.apache.org/repos/asf/wicket/blob/694ee32d/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java 
b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
index 66af566..1b469a8 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java
@@ -148,16 +148,14 @@ import org.slf4j.LoggerFactory;
  *
  * Cookie handling:
  *
- * There are some expectations about wicket tester cookie handling which 
should match as best as
- * it can be with a real client server request response cycle:
- * - all valid cookies set before a request is made 
(tester.getRequest().addCookie()) should
- *   appear in the page request
- * - all cookies set in the response should appear in the last response 
(tester.getLastResponse())
- *   after the request is made (expired cookies and others)
- * - all cookies set in the response should appear even after a redirect 
response is made
- *   until the final response (tester.getLastResponse()) is written to the 
client (wicket tester)
- * - all valid cookies (maxAge!=0) from the last response should be added to
- *   the next request cookies (tester.getRequest().getCookies())
+ * There are some expectations about wicket tester cookie handling which 
should match as best as it
+ * can be with a real client server request response cycle: - all valid 
cookies set before a request
+ * is made (tester.getRequest().addCookie()) should appear in the page request 
- all cookies set in
+ * the response should appear in the last response (tester.getLastResponse()) 
after the request is
+ * made (expired cookies and others) - all cookies set in the response should 
appear even after a
+ * redirect response is made until the final response 
(tester.getLastResponse()) is written to the
+ * client (wicket tester) - all valid cookies (maxAge!=0) from the last 
response should be added to
+ * the next request cookies (tester.getRequest().getCookies())
  *
  *
  * TODO General: Example usage of FormTester
@@ -260,19 +258,41 @@ public class WicketTester extends BaseWicketTester
        }
 
        /**
+        * Returns the current Maven build directory taken from the 
<tt>basedir</tt> system property, or
+        * null if not set
+        *
+        * @return path with a trailing slash
+        */
+       public static String getBasedir()
+       {
+               String basedir = System.getProperty("basedir");
+               if (basedir != null)
+               {
+                       basedir = basedir + "/";
+               }
+               else
+               {
+                       basedir = "";
+               }
+               return basedir;
+       }
+
+       /**
         * Asserts that the Ajax location header is present.
         */
        public void assertAjaxLocation()
        {
                if (null != getLastResponse().getHeader("Location"))
                {
-                       throw new AssertionFailedError("Location header should 
*not* be present when using Ajax");
+                       throw new AssertionFailedError(
+                               "Location header should *not* be present when 
using Ajax");
                }
 
                String ajaxLocation = 
getLastResponse().getHeader("Ajax-Location");
                if (null == ajaxLocation)
                {
-                       throw new AssertionFailedError("Ajax-Location header 
should be present when using Ajax");
+                       throw new AssertionFailedError(
+                               "Ajax-Location header should be present when 
using Ajax");
                }
 
                int statusCode = getLastResponse().getStatus();
@@ -296,8 +316,7 @@ public class WicketTester extends BaseWicketTester
        }
 
        /**
-        * Asserts that the <code>Component</code> a the given path has a 
behavior
-        * of the given type.
+        * Asserts that the <code>Component</code> a the given path has a 
behavior of the given type.
         *
         * @param path
         *            path to <code>Component</code>
@@ -311,14 +330,14 @@ public class WicketTester extends BaseWicketTester
                Component component = assertExists(path);
                List<? extends Behavior> behaviors = 
component.getBehaviors(expectedBehaviorClass);
                final String message = String.format("Component '%s' has no 
behaviors of type '%s'",
-                               component.getPageRelativePath(), 
expectedBehaviorClass);
+                       component.getPageRelativePath(), expectedBehaviorClass);
                assertResult(new Result(CollectionUtils.isEmpty(behaviors), 
message));
        }
 
        /**
         * Tests that a <code>Component</code> has been added to a 
<code>AjaxRequestTarget</code>, using
-        * {@link org.apache.wicket.ajax.AjaxRequestTarget#add(Component...)}. 
This method actually tests that a
-        * <code>Component</code> is on the Ajax response sent back to the 
client.
+        * {@link org.apache.wicket.ajax.AjaxRequestTarget#add(Component...)}. 
This method actually
+        * tests that a <code>Component</code> is on the Ajax response sent 
back to the client.
         * <p>
         * PLEASE NOTE! This method doesn't actually insert the 
<code>Component</code> in the client DOM
         * tree, using JavaScript. But it shouldn't be needed because you just 
have to trust that Wicket
@@ -335,8 +354,8 @@ public class WicketTester extends BaseWicketTester
 
        /**
         * Tests that a <code>Component</code> has been added to a 
<code>AjaxRequestTarget</code>, using
-        * {@link org.apache.wicket.ajax.AjaxRequestTarget#add(Component...)}. 
This method actually tests that a
-        * <code>Component</code> is on the Ajax response sent back to the 
client.
+        * {@link org.apache.wicket.ajax.AjaxRequestTarget#add(Component...)}. 
This method actually
+        * tests that a <code>Component</code> is on the Ajax response sent 
back to the client.
         * <p>
         * PLEASE NOTE! This method doesn't actually insert the 
<code>Component</code> in the client DOM
         * tree, using JavaScript. But it shouldn't be needed because you just 
have to trust that Wicket
@@ -377,9 +396,9 @@ public class WicketTester extends BaseWicketTester
         * Asserts that a component's markup has loaded with the given variation
         *
         * @param component
-        *              The component which markup to check
+        *            The component which markup to check
         * @param expectedVariation
-        *              The expected variation of the component's markup
+        *            The expected variation of the component's markup
         */
        public void assertMarkupVariation(Component component, String 
expectedVariation)
        {
@@ -389,7 +408,8 @@ public class WicketTester extends BaseWicketTester
                String actualVariation = 
markup.getMarkupResourceStream().getVariation();
                if (Objects.equal(expectedVariation, actualVariation) == false)
                {
-                       result = Result.fail(String.format("Wrong variation for 
component '%s'. Actual: '%s', expected: '%s'",
+                       result = Result.fail(
+                               String.format("Wrong variation for component 
'%s'. Actual: '%s', expected: '%s'",
                                        component.getPageRelativePath(), 
actualVariation, expectedVariation));
                }
 
@@ -400,10 +420,10 @@ public class WicketTester extends BaseWicketTester
         * Asserts that a component's markup has loaded with the given style.
         *
         * @param component
-        *              The component which markup to check
+        *            The component which markup to check
         * @param expectedStyle
-        *              The expected style of the component's markup.
-        *              For example: <em>green</em> in 
<code>MyPanel_green.html</code>
+        *            The expected style of the component's markup. For 
example: <em>green</em> in
+        *            <code>MyPanel_green.html</code>
         */
        public void assertMarkupStyle(Component component, String expectedStyle)
        {
@@ -413,7 +433,8 @@ public class WicketTester extends BaseWicketTester
                String actualStyle = 
markup.getMarkupResourceStream().getStyle();
                if (Objects.equal(expectedStyle, actualStyle) == false)
                {
-                       result = Result.fail(String.format("Wrong style for 
component '%s'. Actual: '%s', expected: '%s'",
+                       result = Result
+                               .fail(String.format("Wrong style for component 
'%s'. Actual: '%s', expected: '%s'",
                                        component.getPageRelativePath(), 
actualStyle, expectedStyle));
                }
 
@@ -424,9 +445,9 @@ public class WicketTester extends BaseWicketTester
         * Asserts that a component's markup has loaded with the given locale
         *
         * @param component
-        *              The component which markup to check
+        *            The component which markup to check
         * @param expectedLocale
-        *              The expected locale of the component's markup
+        *            The expected locale of the component's markup
         */
        public void assertMarkupLocale(Component component, Locale 
expectedLocale)
        {
@@ -436,7 +457,8 @@ public class WicketTester extends BaseWicketTester
                Locale actualLocale = 
markup.getMarkupResourceStream().getLocale();
                if (Objects.equal(expectedLocale, actualLocale) == false)
                {
-                       result = Result.fail(String.format("Wrong locale for 
component '%s'. Actual: '%s', expected: '%s'",
+                       result = Result
+                               .fail(String.format("Wrong locale for component 
'%s'. Actual: '%s', expected: '%s'",
                                        component.getPageRelativePath(), 
actualLocale, expectedLocale));
                }
 
@@ -448,7 +470,7 @@ public class WicketTester extends BaseWicketTester
                IMarkupFragment markup = null;
                if (component instanceof MarkupContainer)
                {
-                       markup = ((MarkupContainer) 
component).getAssociatedMarkup();
+                       markup = 
((MarkupContainer)component).getAssociatedMarkup();
                }
 
                if (markup == null)
@@ -458,7 +480,8 @@ public class WicketTester extends BaseWicketTester
 
                if (markup == null)
                {
-                       throw new AssertionFailedError(String.format("Cannot 
find the markup of component: %s", component.getPageRelativePath()));
+                       throw new AssertionFailedError(String.format("Cannot 
find the markup of component: %s",
+                               component.getPageRelativePath()));
                }
 
                return markup;
@@ -472,7 +495,8 @@ public class WicketTester extends BaseWicketTester
         */
        public void assertErrorMessages(Serializable... expectedErrorMessages)
        {
-               assertFeedbackMessages(new 
ExactLevelFeedbackMessageFilter(FeedbackMessage.ERROR), expectedErrorMessages);
+               assertFeedbackMessages(new 
ExactLevelFeedbackMessageFilter(FeedbackMessage.ERROR),
+                       expectedErrorMessages);
        }
 
        /**
@@ -495,7 +519,8 @@ public class WicketTester extends BaseWicketTester
         * @param expectedMessages
         *            expected feedback messages
         */
-       public void assertFeedbackMessages(IFeedbackMessageFilter filter, 
Serializable... expectedMessages)
+       public void assertFeedbackMessages(IFeedbackMessageFilter filter,
+               Serializable... expectedMessages)
        {
                List<FeedbackMessage> feedbackMessages = 
getFeedbackMessages(filter);
                List<Serializable> actualMessages = 
getActualFeedbackMessages(feedbackMessages);
@@ -506,31 +531,33 @@ public class WicketTester extends BaseWicketTester
         * Asserts that there is a feedback message provided by a given 
component
         *
         * @param component
-        *          the component that provided the expected feedback message. 
Optional.
+        *            the component that provided the expected feedback 
message. Optional.
         * @param key
-        *          the resource key for the feedback message. Mandatory.
+        *            the resource key for the feedback message. Mandatory.
         * @param model
-        *          the model used for interpolating the feedback message. 
Optional.
+        *            the model used for interpolating the feedback message. 
Optional.
         * @param filter
-        *          the filter that decides in which messages to look in. E.g. 
with a specific
-        *          level, rendered or not, etc.
+        *            the filter that decides in which messages to look in. 
E.g. with a specific level,
+        *            rendered or not, etc.
         */
-       public void assertComponentFeedbackMessage(Component component, String 
key, IModel<?> model, IFeedbackMessageFilter filter)
+       public void assertComponentFeedbackMessage(Component component, String 
key, IModel<?> model,
+               IFeedbackMessageFilter filter)
        {
                Args.notNull(key, "key");
 
-               String expectedMessage = 
getApplication().getResourceSettings().getLocalizer().getString(key, component, 
model);
+               String expectedMessage = 
getApplication().getResourceSettings().getLocalizer().getString(
+                       key, component, model);
 
                List<FeedbackMessage> feedbackMessages = 
getFeedbackMessages(filter);
                List<Serializable> actualMessages = 
getActualFeedbackMessages(feedbackMessages);
 
-               assertTrue(actualMessages.contains(expectedMessage),
-                                  String.format("Feedback message with key 
'%s' cannot be found in %s", key, actualMessages));
+               assertTrue(actualMessages.contains(expectedMessage), String
+                       .format("Feedback message with key '%s' cannot be found 
in %s", key, actualMessages));
        }
 
        /**
-        * Extracts the actual messages from the passed feedback messages.
-        * Specially handles ValidationErrorFeedback messages by extracting 
their String message
+        * Extracts the actual messages from the passed feedback messages. 
Specially handles
+        * ValidationErrorFeedback messages by extracting their String message
         *
         * @param feedbackMessages
         *            the feedback messages
@@ -573,13 +600,15 @@ public class WicketTester extends BaseWicketTester
                final List<FeedbackMessage> renderedMessages = 
model.getObject();
                if (renderedMessages == null)
                {
-                       throw new AssertionFailedError(String.format("feedback 
panel at path [%s] returned null messages", path));
+                       throw new AssertionFailedError(
+                               String.format("feedback panel at path [%s] 
returned null messages", path));
                }
 
                if (messages.length != renderedMessages.size())
                {
-                       throw new AssertionFailedError(String.format("you 
expected '%d' messages for the feedback panel [%s], but there were actually 
'%d'",
-                                       messages.length, path, 
renderedMessages.size()));
+                       throw new AssertionFailedError(String.format(
+                               "you expected '%d' messages for the feedback 
panel [%s], but there were actually '%d'",
+                               messages.length, path, 
renderedMessages.size()));
                }
 
                for (int i = 0; i < messages.length && i < 
renderedMessages.size(); i++)
@@ -834,15 +863,16 @@ public class WicketTester extends BaseWicketTester
                }
                catch (ClassCastException e)
                {
-                       throw new IllegalArgumentException("Component with id:" 
+ id +
-                               " is not a BookmarkablePageLink");
+                       throw new IllegalArgumentException(
+                               "Component with id:" + id + " is not a 
BookmarkablePageLink");
                }
 
-               assertEquals(pageClass,
-                       pageLink.getPageClass(), "BookmarkablePageLink: " + id 
+ " is pointing to the wrong page");
+               assertEquals(pageClass, pageLink.getPageClass(),
+                       "BookmarkablePageLink: " + id + " is pointing to the 
wrong page");
 
-               assertEquals(parameters, pageLink.getPageParameters(), "One or 
more of the parameters associated with the BookmarkablePageLink: " +
-                               id + " do not match");
+               assertEquals(parameters, pageLink.getPageParameters(),
+                       "One or more of the parameters associated with the 
BookmarkablePageLink: " + id +
+                               " do not match");
        }
 
        /**
@@ -970,24 +1000,4 @@ public class WicketTester extends BaseWicketTester
                String actualRedirectUrl = 
getLastResponse().getRedirectLocation();
                assertEquals(expectedRedirectUrl, actualRedirectUrl);
        }
-
-       /**
-        * Returns the current Maven build directory taken from the 
<tt>basedir</tt> system property, or
-        * null if not set
-        *
-        * @return path with a trailing slash
-        */
-       public static String getBasedir()
-       {
-               String basedir = System.getProperty("basedir");
-               if (basedir != null)
-               {
-                       basedir = basedir + "/";
-               }
-               else
-               {
-                       basedir = "";
-               }
-               return basedir;
-       }
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/694ee32d/wicket-core/src/test/java/org/apache/wicket/TesterTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/TesterTest.java 
b/wicket-core/src/test/java/org/apache/wicket/TesterTest.java
index 692324d..64bc26f 100644
--- a/wicket-core/src/test/java/org/apache/wicket/TesterTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/TesterTest.java
@@ -23,7 +23,6 @@ import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.util.tester.WicketTestCase;
 import org.junit.jupiter.api.Test;
 
-
 /**
  * @author jcompagner
  */

http://git-wip-us.apache.org/repos/asf/wicket/blob/694ee32d/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java
 
b/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java
index 5956c33..a404885 100644
--- 
a/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java
+++ 
b/wicket-core/src/test/java/org/apache/wicket/request/handler/render/WebPageRendererTest.java
@@ -43,7 +43,6 @@ import org.apache.wicket.request.http.WebResponse;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-
 /**
  * Tests for the calculation whether or not to redirect or directly render a 
page
  */

Reply via email to