From 8c168e3b4b1186dcba282a52bdf3e60f1e7177f7 Mon Sep 17 00:00:00 2001 From: Wouter Born Date: Fri, 14 Jul 2023 10:59:53 +0200 Subject: [PATCH 01/40] Upgrade JDOM from 1.0 to 2.0.6.1 This upgrade fixes warnings in IntelliJ IDEA about the CVE-2021-33813 in the JDOM 1.0 dependency. The tags are redundant and cause issues in IntelliJ IDEA. It is also better to use JAVA_HOME instead of /usr/bin as javadoc may not always be symlinked to a Java 8 JDK causing compilation issues. Signed-off-by: Wouter Born --- mockrunner-all/pom.xml | 1 - .../mockrunner/base/HTMLOutputTestCase.java | 2 +- .../test/web/HTMLOutputModuleTest.java | 2 +- mockrunner-core/pom.xml | 5 ++--- .../com/mockrunner/test/util/XmlUtilTest.java | 4 ++-- .../java/com/mockrunner/util/web/XmlUtil.java | 20 +++++++++---------- mockrunner-ejb/pom.xml | 1 - mockrunner-jca/pom.xml | 1 - mockrunner-jdbc/pom.xml | 1 - .../mockrunner/jdbc/XMLResultSetFactory.java | 6 +++--- ...MLResultSetFactorySQLDeveloperSupport.java | 6 +++--- .../com/mockrunner/mock/jdbc/MockSQLXML.java | 15 +++++++------- .../mockrunner/test/jdbc/MockSQLXMLTest.java | 10 +++++----- mockrunner-jms-spring/pom.xml | 1 - mockrunner-jms/pom.xml | 1 - mockrunner-servlet/pom.xml | 1 - .../base/BasicHTMLOutputTestCase.java | 2 +- .../com/mockrunner/base/HTMLOutputModule.java | 4 ++-- .../example/servlet/RedirectServletTest.java | 2 +- mockrunner-tag/pom.xml | 1 - pom.xml | 10 +++++----- 21 files changed, 44 insertions(+), 52 deletions(-) diff --git a/mockrunner-all/pom.xml b/mockrunner-all/pom.xml index 4b7793a67..6fbffaceb 100644 --- a/mockrunner-all/pom.xml +++ b/mockrunner-all/pom.xml @@ -6,7 +6,6 @@ com.mockrunner mockrunner 2.0.7-SNAPSHOT - .. mockrunner-all diff --git a/mockrunner-all/src/main/java/com/mockrunner/base/HTMLOutputTestCase.java b/mockrunner-all/src/main/java/com/mockrunner/base/HTMLOutputTestCase.java index 87d61d692..a5987cdad 100644 --- a/mockrunner-all/src/main/java/com/mockrunner/base/HTMLOutputTestCase.java +++ b/mockrunner-all/src/main/java/com/mockrunner/base/HTMLOutputTestCase.java @@ -56,7 +56,7 @@ protected org.w3c.dom.Document getOutputAsW3CDocument() /** * Delegates to {@link HTMLOutputModule#getOutputAsJDOMDocument} */ - protected org.jdom.Document getOutputAsJDOMDocument() + protected org.jdom2.Document getOutputAsJDOMDocument() { return getHTMLOutputModule().getOutputAsJDOMDocument(); } diff --git a/mockrunner-all/src/test/java/com/mockrunner/test/web/HTMLOutputModuleTest.java b/mockrunner-all/src/test/java/com/mockrunner/test/web/HTMLOutputModuleTest.java index 2ae4fdd49..38bfdb578 100644 --- a/mockrunner-all/src/test/java/com/mockrunner/test/web/HTMLOutputModuleTest.java +++ b/mockrunner-all/src/test/java/com/mockrunner/test/web/HTMLOutputModuleTest.java @@ -17,7 +17,7 @@ import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; -import org.jdom.Element; +import org.jdom2.Element; import org.junit.Before; import org.junit.Test; diff --git a/mockrunner-core/pom.xml b/mockrunner-core/pom.xml index 7e7d581b9..35b448c81 100644 --- a/mockrunner-core/pom.xml +++ b/mockrunner-core/pom.xml @@ -6,7 +6,6 @@ com.mockrunner mockrunner 2.0.7-SNAPSHOT - .. mockrunner-core @@ -31,8 +30,8 @@ - jdom - jdom + org.jdom + jdom2 diff --git a/mockrunner-core/src/main/java/com/mockrunner/test/util/XmlUtilTest.java b/mockrunner-core/src/main/java/com/mockrunner/test/util/XmlUtilTest.java index 5983a0b3f..282198e41 100644 --- a/mockrunner-core/src/main/java/com/mockrunner/test/util/XmlUtilTest.java +++ b/mockrunner-core/src/main/java/com/mockrunner/test/util/XmlUtilTest.java @@ -5,8 +5,8 @@ import junit.framework.TestCase; -import org.jdom.Document; -import org.jdom.Element; +import org.jdom2.Document; +import org.jdom2.Element; import com.mockrunner.util.web.XmlUtil; diff --git a/mockrunner-core/src/main/java/com/mockrunner/util/web/XmlUtil.java b/mockrunner-core/src/main/java/com/mockrunner/util/web/XmlUtil.java index aab42bceb..8ae749abf 100644 --- a/mockrunner-core/src/main/java/com/mockrunner/util/web/XmlUtil.java +++ b/mockrunner-core/src/main/java/com/mockrunner/util/web/XmlUtil.java @@ -5,9 +5,9 @@ import org.apache.xerces.parsers.DOMParser; import org.cyberneko.html.HTMLConfiguration; -import org.jdom.Element; -import org.jdom.input.DOMBuilder; -import org.jdom.output.XMLOutputter; +import org.jdom2.Element; +import org.jdom2.input.DOMBuilder; +import org.jdom2.output.XMLOutputter; import org.xml.sax.InputSource; import com.mockrunner.base.NestedApplicationException; @@ -34,10 +34,10 @@ public class XmlUtil * * * the method returns the h1 tag as Element. - * @param document the org.jdom.Document + * @param document the org.jdom2.Document * @return the body Element */ - public static Element getBodyFragmentFromJDOMDocument(org.jdom.Document document) + public static Element getBodyFragmentFromJDOMDocument(org.jdom2.Document document) { Element element = document.getRootElement().getChild("BODY"); if(null == element) @@ -57,17 +57,17 @@ public static Element getBodyFragmentFromJDOMDocument(org.jdom.Document document * @return the body element * @deprecated use {@link #getBodyFragmentFromJDOMDocument} */ - public static Element getBodyFragmentJDOMDocument(org.jdom.Document document) + public static Element getBodyFragmentJDOMDocument(org.jdom2.Document document) { return getBodyFragmentFromJDOMDocument(document); } /** * Returns the documents XML content as a string. - * @param document the org.jdom.Document + * @param document the org.jdom2.Document * @return the output as string */ - public static String createStringFromJDOMDocument(org.jdom.Document document) + public static String createStringFromJDOMDocument(org.jdom2.Document document) { try { @@ -83,9 +83,9 @@ public static String createStringFromJDOMDocument(org.jdom.Document document) * Creates a JDOM Document from a specified * W3C Document. * @param document the org.w3c.dom.Document - * @return the org.jdom.Document + * @return the org.jdom2.Document */ - public static org.jdom.Document createJDOMDocument(org.w3c.dom.Document document) + public static org.jdom2.Document createJDOMDocument(org.w3c.dom.Document document) { return new DOMBuilder().build(document); } diff --git a/mockrunner-ejb/pom.xml b/mockrunner-ejb/pom.xml index 20f0dc1a5..e787cb3e6 100644 --- a/mockrunner-ejb/pom.xml +++ b/mockrunner-ejb/pom.xml @@ -6,7 +6,6 @@ com.mockrunner mockrunner 2.0.7-SNAPSHOT - .. mockrunner-ejb diff --git a/mockrunner-jca/pom.xml b/mockrunner-jca/pom.xml index 094db9730..8d805b9c9 100644 --- a/mockrunner-jca/pom.xml +++ b/mockrunner-jca/pom.xml @@ -6,7 +6,6 @@ com.mockrunner mockrunner 2.0.7-SNAPSHOT - .. mockrunner-jca diff --git a/mockrunner-jdbc/pom.xml b/mockrunner-jdbc/pom.xml index 44cf19bae..56e5d75b4 100644 --- a/mockrunner-jdbc/pom.xml +++ b/mockrunner-jdbc/pom.xml @@ -6,7 +6,6 @@ com.mockrunner mockrunner 2.0.7-SNAPSHOT - .. mockrunner-jdbc diff --git a/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactory.java b/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactory.java index 24d7c4617..c8faf67d8 100644 --- a/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactory.java +++ b/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactory.java @@ -7,9 +7,9 @@ import java.util.List; import java.util.Map; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.input.SAXBuilder; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.input.SAXBuilder; import com.mockrunner.base.NestedApplicationException; import com.mockrunner.mock.jdbc.MockResultSet; diff --git a/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactorySQLDeveloperSupport.java b/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactorySQLDeveloperSupport.java index 837ac29d3..b9d3fb098 100644 --- a/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactorySQLDeveloperSupport.java +++ b/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactorySQLDeveloperSupport.java @@ -4,9 +4,9 @@ import java.util.Iterator; import java.util.List; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.input.SAXBuilder; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.input.SAXBuilder; import com.mockrunner.base.NestedApplicationException; import com.mockrunner.mock.jdbc.MockResultSet; diff --git a/mockrunner-jdbc/src/main/java/com/mockrunner/mock/jdbc/MockSQLXML.java b/mockrunner-jdbc/src/main/java/com/mockrunner/mock/jdbc/MockSQLXML.java index c6ef37f25..fab2a8cf6 100644 --- a/mockrunner-jdbc/src/main/java/com/mockrunner/mock/jdbc/MockSQLXML.java +++ b/mockrunner-jdbc/src/main/java/com/mockrunner/mock/jdbc/MockSQLXML.java @@ -32,13 +32,13 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import org.jdom.Document; -import org.jdom.input.DOMBuilder; -import org.jdom.input.SAXBuilder; -import org.jdom.input.SAXHandler; -import org.jdom.output.DOMOutputter; -import org.jdom.output.Format; -import org.jdom.output.XMLOutputter; +import org.jdom2.Document; +import org.jdom2.input.DOMBuilder; +import org.jdom2.input.SAXBuilder; +import org.jdom2.input.sax.SAXHandler; +import org.jdom2.output.DOMOutputter; +import org.jdom2.output.Format; +import org.jdom2.output.XMLOutputter; import org.w3c.dom.Node; import org.xml.sax.InputSource; @@ -146,6 +146,7 @@ protected XMLInputFactory createXMLInputFactory() protected SAXBuilder createJDOMSAXBuilder() { + SAXBuilder builder = new SAXBuilder(); builder.setValidation(false); return builder; diff --git a/mockrunner-jdbc/src/test/java/com/mockrunner/test/jdbc/MockSQLXMLTest.java b/mockrunner-jdbc/src/test/java/com/mockrunner/test/jdbc/MockSQLXMLTest.java index 074832ebc..47059016a 100644 --- a/mockrunner-jdbc/src/test/java/com/mockrunner/test/jdbc/MockSQLXMLTest.java +++ b/mockrunner-jdbc/src/test/java/com/mockrunner/test/jdbc/MockSQLXMLTest.java @@ -24,11 +24,11 @@ import junit.framework.TestCase; -import org.jdom.Document; -import org.jdom.input.DOMBuilder; -import org.jdom.input.SAXBuilder; -import org.jdom.output.Format; -import org.jdom.output.XMLOutputter; +import org.jdom2.Document; +import org.jdom2.input.DOMBuilder; +import org.jdom2.input.SAXBuilder; +import org.jdom2.output.Format; +import org.jdom2.output.XMLOutputter; import org.xml.sax.ContentHandler; import org.xml.sax.helpers.AttributesImpl; diff --git a/mockrunner-jms-spring/pom.xml b/mockrunner-jms-spring/pom.xml index 3cb9a0c18..f93b38332 100644 --- a/mockrunner-jms-spring/pom.xml +++ b/mockrunner-jms-spring/pom.xml @@ -6,7 +6,6 @@ com.mockrunner mockrunner 2.0.0-SNAPSHOT - .. mockrunner-jms-spring diff --git a/mockrunner-jms/pom.xml b/mockrunner-jms/pom.xml index c594db51b..550bd9443 100644 --- a/mockrunner-jms/pom.xml +++ b/mockrunner-jms/pom.xml @@ -6,7 +6,6 @@ com.mockrunner mockrunner 2.0.7-SNAPSHOT - .. mockrunner-jms diff --git a/mockrunner-servlet/pom.xml b/mockrunner-servlet/pom.xml index 5163d2cc8..5c2d1e425 100644 --- a/mockrunner-servlet/pom.xml +++ b/mockrunner-servlet/pom.xml @@ -6,7 +6,6 @@ com.mockrunner mockrunner 2.0.7-SNAPSHOT - .. mockrunner-servlet diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/base/BasicHTMLOutputTestCase.java b/mockrunner-servlet/src/main/java/com/mockrunner/base/BasicHTMLOutputTestCase.java index 16fd09b43..7859ffc09 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/base/BasicHTMLOutputTestCase.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/base/BasicHTMLOutputTestCase.java @@ -56,7 +56,7 @@ protected org.w3c.dom.Document getOutputAsW3CDocument() /** * Delegates to {@link HTMLOutputModule#getOutputAsJDOMDocument} */ - protected org.jdom.Document getOutputAsJDOMDocument() + protected org.jdom2.Document getOutputAsJDOMDocument() { return getHTMLOutputModule().getOutputAsJDOMDocument(); } diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/base/HTMLOutputModule.java b/mockrunner-servlet/src/main/java/com/mockrunner/base/HTMLOutputModule.java index f6d0777da..269590782 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/base/HTMLOutputModule.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/base/HTMLOutputModule.java @@ -66,10 +66,10 @@ public org.w3c.dom.Document getOutputAsW3CDocument() * to parse the string output yourself. Please note that * HTML parsing is not very fast and may slow down * your test suite. - * @return the output as org.jdom.Document + * @return the output as org.jdom2.Document * @throws RuntimeException if a parsing error occurs */ - public org.jdom.Document getOutputAsJDOMDocument() + public org.jdom2.Document getOutputAsJDOMDocument() { return XmlUtil.createJDOMDocument(getOutputAsW3CDocument()); } diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/RedirectServletTest.java b/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/RedirectServletTest.java index 2589ee6dd..1d5f69ecb 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/RedirectServletTest.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/RedirectServletTest.java @@ -4,7 +4,7 @@ import java.io.BufferedReader; -import org.jdom.Element; +import org.jdom2.Element; import org.junit.Before; import org.junit.Test; diff --git a/mockrunner-tag/pom.xml b/mockrunner-tag/pom.xml index 3eed1af44..d4fa06ed6 100644 --- a/mockrunner-tag/pom.xml +++ b/mockrunner-tag/pom.xml @@ -6,7 +6,6 @@ com.mockrunner mockrunner 2.0.7-SNAPSHOT - .. mockrunner-tag diff --git a/pom.xml b/pom.xml index a97d38b6a..63a47a42f 100644 --- a/pom.xml +++ b/pom.xml @@ -147,9 +147,9 @@ 2.0.8 - jdom - jdom - 1.0 + org.jdom + jdom2 + 2.0.6.1 junit @@ -493,7 +493,7 @@ - /usr/bin/javadoc + ${env.JAVA_HOME}/bin/javadoc @@ -505,7 +505,7 @@ - /usr/bin/javadoc + ${env.JAVA_HOME}/bin/javadoc From 90dd2e34fbd8115bde192cd7da9eb490cf438d95 Mon Sep 17 00:00:00 2001 From: cemartins Date: Sun, 23 Jul 2023 20:51:24 +0000 Subject: [PATCH 02/40] [maven-release-plugin] prepare release mockrunner-2.0.7 --- mockrunner-all/pom.xml | 28 ++++++++++++++-------------- mockrunner-core/pom.xml | 2 +- mockrunner-ejb/pom.xml | 2 +- mockrunner-jca/pom.xml | 2 +- mockrunner-jdbc/pom.xml | 2 +- mockrunner-jms/pom.xml | 2 +- mockrunner-servlet/pom.xml | 2 +- mockrunner-struts/pom.xml | 2 +- mockrunner-tag/pom.xml | 2 +- pom.xml | 4 ++-- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/mockrunner-all/pom.xml b/mockrunner-all/pom.xml index 6fbffaceb..4a26fe470 100644 --- a/mockrunner-all/pom.xml +++ b/mockrunner-all/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.7 mockrunner-all @@ -16,75 +16,75 @@ com.mockrunner mockrunner-core - 2.0.7-SNAPSHOT + 2.0.7 com.mockrunner mockrunner-jms - 2.0.7-SNAPSHOT + 2.0.7 com.mockrunner mockrunner-jms - 2.0.7-SNAPSHOT + 2.0.7 tests test com.mockrunner mockrunner-ejb - 2.0.7-SNAPSHOT + 2.0.7 com.mockrunner mockrunner-ejb - 2.0.7-SNAPSHOT + 2.0.7 tests test com.mockrunner mockrunner-jdbc - 2.0.7-SNAPSHOT + 2.0.7 com.mockrunner mockrunner-jdbc - 2.0.7-SNAPSHOT + 2.0.7 tests test com.mockrunner mockrunner-jca - 2.0.7-SNAPSHOT + 2.0.7 com.mockrunner mockrunner-servlet - 2.0.7-SNAPSHOT + 2.0.7 com.mockrunner mockrunner-servlet - 2.0.7-SNAPSHOT + 2.0.7 tests test com.mockrunner mockrunner-tag - 2.0.7-SNAPSHOT + 2.0.7 com.mockrunner mockrunner-struts - 2.0.7-SNAPSHOT + 2.0.7 com.mockrunner mockrunner-struts - 2.0.7-SNAPSHOT + 2.0.7 tests test diff --git a/mockrunner-core/pom.xml b/mockrunner-core/pom.xml index 35b448c81..d4bf85bcc 100644 --- a/mockrunner-core/pom.xml +++ b/mockrunner-core/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.7 mockrunner-core diff --git a/mockrunner-ejb/pom.xml b/mockrunner-ejb/pom.xml index e787cb3e6..1edd8335c 100644 --- a/mockrunner-ejb/pom.xml +++ b/mockrunner-ejb/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.7 mockrunner-ejb diff --git a/mockrunner-jca/pom.xml b/mockrunner-jca/pom.xml index 8d805b9c9..f47110a7a 100644 --- a/mockrunner-jca/pom.xml +++ b/mockrunner-jca/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.7 mockrunner-jca diff --git a/mockrunner-jdbc/pom.xml b/mockrunner-jdbc/pom.xml index 56e5d75b4..7989d043f 100644 --- a/mockrunner-jdbc/pom.xml +++ b/mockrunner-jdbc/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.7 mockrunner-jdbc diff --git a/mockrunner-jms/pom.xml b/mockrunner-jms/pom.xml index 550bd9443..818187a9e 100644 --- a/mockrunner-jms/pom.xml +++ b/mockrunner-jms/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.7 mockrunner-jms diff --git a/mockrunner-servlet/pom.xml b/mockrunner-servlet/pom.xml index 5c2d1e425..c52fb601d 100644 --- a/mockrunner-servlet/pom.xml +++ b/mockrunner-servlet/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.7 mockrunner-servlet diff --git a/mockrunner-struts/pom.xml b/mockrunner-struts/pom.xml index f867618be..cd1576705 100644 --- a/mockrunner-struts/pom.xml +++ b/mockrunner-struts/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.7 .. diff --git a/mockrunner-tag/pom.xml b/mockrunner-tag/pom.xml index d4fa06ed6..7365c5d92 100644 --- a/mockrunner-tag/pom.xml +++ b/mockrunner-tag/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.7 mockrunner-tag diff --git a/pom.xml b/pom.xml index 63a47a42f..c53c1dc12 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.7 pom MockRunner http://mockrunner.github.io @@ -56,7 +56,7 @@ scm:git:https://github.com/mockrunner/mockrunner.git https://github.com/mockrunner/mockrunner scm:git:https://github.com/mockrunner/mockrunner.git - HEAD + mockrunner-2.0.7 From 9458528325336a22109b7a3bf54b2ba65944631a Mon Sep 17 00:00:00 2001 From: cemartins Date: Sun, 23 Jul 2023 20:51:26 +0000 Subject: [PATCH 03/40] [maven-release-plugin] prepare for next development iteration --- mockrunner-all/pom.xml | 28 ++++++++++++++-------------- mockrunner-core/pom.xml | 2 +- mockrunner-ejb/pom.xml | 2 +- mockrunner-jca/pom.xml | 2 +- mockrunner-jdbc/pom.xml | 2 +- mockrunner-jms/pom.xml | 2 +- mockrunner-servlet/pom.xml | 2 +- mockrunner-struts/pom.xml | 2 +- mockrunner-tag/pom.xml | 2 +- pom.xml | 4 ++-- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/mockrunner-all/pom.xml b/mockrunner-all/pom.xml index 4a26fe470..dfce1e1d2 100644 --- a/mockrunner-all/pom.xml +++ b/mockrunner-all/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7 + 2.0.8-SNAPSHOT mockrunner-all @@ -16,75 +16,75 @@ com.mockrunner mockrunner-core - 2.0.7 + 2.0.8-SNAPSHOT com.mockrunner mockrunner-jms - 2.0.7 + 2.0.8-SNAPSHOT com.mockrunner mockrunner-jms - 2.0.7 + 2.0.8-SNAPSHOT tests test com.mockrunner mockrunner-ejb - 2.0.7 + 2.0.8-SNAPSHOT com.mockrunner mockrunner-ejb - 2.0.7 + 2.0.8-SNAPSHOT tests test com.mockrunner mockrunner-jdbc - 2.0.7 + 2.0.8-SNAPSHOT com.mockrunner mockrunner-jdbc - 2.0.7 + 2.0.8-SNAPSHOT tests test com.mockrunner mockrunner-jca - 2.0.7 + 2.0.8-SNAPSHOT com.mockrunner mockrunner-servlet - 2.0.7 + 2.0.8-SNAPSHOT com.mockrunner mockrunner-servlet - 2.0.7 + 2.0.8-SNAPSHOT tests test com.mockrunner mockrunner-tag - 2.0.7 + 2.0.8-SNAPSHOT com.mockrunner mockrunner-struts - 2.0.7 + 2.0.8-SNAPSHOT com.mockrunner mockrunner-struts - 2.0.7 + 2.0.8-SNAPSHOT tests test diff --git a/mockrunner-core/pom.xml b/mockrunner-core/pom.xml index d4bf85bcc..b28165348 100644 --- a/mockrunner-core/pom.xml +++ b/mockrunner-core/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7 + 2.0.8-SNAPSHOT mockrunner-core diff --git a/mockrunner-ejb/pom.xml b/mockrunner-ejb/pom.xml index 1edd8335c..209eccff7 100644 --- a/mockrunner-ejb/pom.xml +++ b/mockrunner-ejb/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7 + 2.0.8-SNAPSHOT mockrunner-ejb diff --git a/mockrunner-jca/pom.xml b/mockrunner-jca/pom.xml index f47110a7a..c531475a1 100644 --- a/mockrunner-jca/pom.xml +++ b/mockrunner-jca/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7 + 2.0.8-SNAPSHOT mockrunner-jca diff --git a/mockrunner-jdbc/pom.xml b/mockrunner-jdbc/pom.xml index 7989d043f..a595cf37f 100644 --- a/mockrunner-jdbc/pom.xml +++ b/mockrunner-jdbc/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7 + 2.0.8-SNAPSHOT mockrunner-jdbc diff --git a/mockrunner-jms/pom.xml b/mockrunner-jms/pom.xml index 818187a9e..d87583470 100644 --- a/mockrunner-jms/pom.xml +++ b/mockrunner-jms/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7 + 2.0.8-SNAPSHOT mockrunner-jms diff --git a/mockrunner-servlet/pom.xml b/mockrunner-servlet/pom.xml index c52fb601d..07d76db82 100644 --- a/mockrunner-servlet/pom.xml +++ b/mockrunner-servlet/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7 + 2.0.8-SNAPSHOT mockrunner-servlet diff --git a/mockrunner-struts/pom.xml b/mockrunner-struts/pom.xml index cd1576705..92ceb4019 100644 --- a/mockrunner-struts/pom.xml +++ b/mockrunner-struts/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7 + 2.0.8-SNAPSHOT .. diff --git a/mockrunner-tag/pom.xml b/mockrunner-tag/pom.xml index 7365c5d92..949e26509 100644 --- a/mockrunner-tag/pom.xml +++ b/mockrunner-tag/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7 + 2.0.8-SNAPSHOT mockrunner-tag diff --git a/pom.xml b/pom.xml index c53c1dc12..3e24b1f80 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7 + 2.0.8-SNAPSHOT pom MockRunner http://mockrunner.github.io @@ -56,7 +56,7 @@ scm:git:https://github.com/mockrunner/mockrunner.git https://github.com/mockrunner/mockrunner scm:git:https://github.com/mockrunner/mockrunner.git - mockrunner-2.0.7 + HEAD From 60d3a5012a62016dbb8d003c0905cb8ff1c57f50 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Tue, 28 May 2024 17:24:54 +0200 Subject: [PATCH 04/40] Add .editorconfig file to keep formatting consistent --- .editorconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..c59c447bf --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = tab +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false From b6c86079a9bc557c4613fc9df550d94998243e26 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Tue, 28 May 2024 17:44:44 +0200 Subject: [PATCH 05/40] Use version 4.4.6 of karaf-maven-plugin --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 3e24b1f80..951233059 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ Europe/Berlin - + Steinar Bang @@ -316,7 +316,7 @@ org.apache.karaf.tooling karaf-maven-plugin - 4.1.7 + 4.4.6 true 80 @@ -429,7 +429,7 @@ - + @@ -572,7 +572,7 @@ mockrunner-core - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - verify - - jar - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadoc - verify - - jar - - - - - ${javadoc-executable-path} - ${project.build.sourceEncoding} - ${project.build.sourceEncoding} - ${project.build.sourceEncoding} - none - -Xdoclint:none - - + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + verify + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadoc + verify + + jar + + + + + ${javadoc-executable-path} + ${project.build.sourceEncoding} + ${project.build.sourceEncoding} + ${project.build.sourceEncoding} + none + -Xdoclint:none + + org.apache.maven.plugins maven-surefire-plugin - --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.lang=ALL-UNNAMED - - + + - - - release-module-exclusives - - - - performRelease - true - - - - - - com.github.github - site-maven-plugin - - ${project.artifactId} - Ejb Site - - - - github-site - - site - - site - - - - - - - + + + release-module-exclusives + + + + performRelease + true + + + + + + com.github.github + site-maven-plugin + + ${project.artifactId} + Ejb Site + + + + github-site + + site + + site + + + + + + + From ff95f582c60029a8d46dbefb04bcbdf4dc2bce6a Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sat, 23 May 2026 13:34:27 +0200 Subject: [PATCH 22/40] Replace space with equal sign in argLine config of maven-surefire-plugin --- mockrunner-ejb/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mockrunner-ejb/pom.xml b/mockrunner-ejb/pom.xml index df642ff4b..faf5ac9ff 100644 --- a/mockrunner-ejb/pom.xml +++ b/mockrunner-ejb/pom.xml @@ -100,7 +100,7 @@ org.apache.maven.plugins maven-surefire-plugin - --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens=java.base/java.lang=ALL-UNNAMED From 34e7d7116ac1867b40219031774562c3a64c1e02 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sat, 23 May 2026 13:43:16 +0200 Subject: [PATCH 23/40] Extract and upload JVM dump and crash files on github action worflow failures --- .github/workflows/build.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a786d212a..98815506b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,3 +22,12 @@ jobs: java-version: 1.8 - name: Build with Maven run: mvn -B package --file pom.xml + - name: Store JVM Crash and Surefire Logs + if: always() # Forces this step to run even if the Maven build fails + uses: actions/upload-artifact@v4 + with: + name: maven-crash-logs + path: | + **/hs_err_pid*.log + **/target/surefire-reports/*.dump* + **/target/surefire-reports/*.txt From a4d954147e2daffd903fb9a70ac748b7f686f047 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sat, 23 May 2026 15:55:23 +0200 Subject: [PATCH 24/40] Force surefire error generation in maven module mockrunner-ejb --- mockrunner-ejb/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mockrunner-ejb/pom.xml b/mockrunner-ejb/pom.xml index faf5ac9ff..1f63ece60 100644 --- a/mockrunner-ejb/pom.xml +++ b/mockrunner-ejb/pom.xml @@ -101,6 +101,8 @@ maven-surefire-plugin --add-opens=java.base/java.lang=ALL-UNNAMED + 0 + false From 3ac73ef72ace1be3d85d78c95d026f50f2092c49 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sat, 23 May 2026 15:57:46 +0200 Subject: [PATCH 25/40] Add debug flags "-X -e" to maven build in github actions workflow --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 98815506b..18cc108f7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: with: java-version: 1.8 - name: Build with Maven - run: mvn -B package --file pom.xml + run: mvn -B -X -e package --file pom.xml - name: Store JVM Crash and Surefire Logs if: always() # Forces this step to run even if the Maven build fails uses: actions/upload-artifact@v4 From 3fdfe84354c7509b2be596fb404349a3875a3c2f Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sat, 23 May 2026 15:59:14 +0200 Subject: [PATCH 26/40] Check system logs for memory (OOM) kills at the end of github actions CI workflow --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 18cc108f7..b08db3773 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,3 +31,6 @@ jobs: **/hs_err_pid*.log **/target/surefire-reports/*.dump* **/target/surefire-reports/*.txt + - name: Check System Logs for Memory (OOM) Kills + if: always() + run: dmesg | grep -i -E 'oom[-_]killer|killed process' || echo "No OS-level OOM kills detected." From 690f3ab5c8c4e4358dd65ea0a22681f74baca05d Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sat, 23 May 2026 16:13:48 +0200 Subject: [PATCH 27/40] Remove maven verbose flags from github actions CI workflow Leaving the saving of surefire logs and crash logs in place. Also leaving the check for OOM kills in place. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b08db3773..67d9aba55 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: with: java-version: 1.8 - name: Build with Maven - run: mvn -B -X -e package --file pom.xml + run: mvn -B package --file pom.xml - name: Store JVM Crash and Surefire Logs if: always() # Forces this step to run even if the Maven build fails uses: actions/upload-artifact@v4 From fab7a4a7939f39d1217dec4ff88cdf37945beaa2 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sat, 23 May 2026 21:59:22 +0200 Subject: [PATCH 28/40] Add Junit jupiter 6.1.0, assertj 3.27.7 and mockito 5.23.0 to mockrunner parent pom dependency management --- pom.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pom.xml b/pom.xml index 632e73a89..bc7f19ca4 100644 --- a/pom.xml +++ b/pom.xml @@ -161,6 +161,23 @@ junit 4.12 + + org.junit + junit-bom + 6.1.0 + pom + import + + + org.assertj + assertj-core + 3.27.7 + + + org.mockito + mockito-core + 5.23.0 + org.mockejb mockejb From e03a8ad13ce019fbac79ae17a4d7622553e31d68 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sat, 23 May 2026 22:17:39 +0200 Subject: [PATCH 29/40] Unify indentation and white space in mockrunner-servlet tests according to editorconfig --- .../mockrunner/test/web/ExceptionTestTag.java | 4 +- .../test/web/JasperJspFactoryTest.java | 76 ++++---- .../test/web/MockExpressionEvaluatorTest.java | 6 +- .../test/web/MockFilterChainTest.java | 168 +++++++++--------- .../test/web/MockFunctionMapperTest.java | 14 +- .../test/web/MockHttpServletRequestTest.java | 19 +- .../test/web/MockHttpServletResponseTest.java | 28 +-- .../test/web/MockHttpSessionTest.java | 73 ++++---- .../MockJspPropertyGroupDescriptorTest.java | 6 +- .../test/web/MockJspWriterTest.java | 6 +- .../test/web/MockServletContextTest.java | 65 ++++--- .../test/web/MockVariableResolverTest.java | 2 +- .../com/mockrunner/test/web/TestBodyTag.java | 18 +- .../mockrunner/test/web/TestFragmentTag.java | 4 +- .../java/com/mockrunner/test/web/TestTag.java | 14 +- .../test/web/WebMockObjectFactoryTest.java | 54 +++--- 16 files changed, 271 insertions(+), 286 deletions(-) diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java index 8e473fe64..0145a1b79 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java @@ -8,12 +8,12 @@ public class ExceptionTestTag extends TestBodyTag implements TryCatchFinally private boolean doFinallyCalled = false; private Throwable caughtException = null; private Throwable throwException = null; - + public ExceptionTestTag() { throwException = null; } - + public ExceptionTestTag(Throwable throwException) { this.throwException = throwException; diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java index 55b292ab7..26b105f0f 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java @@ -22,14 +22,14 @@ public class JasperJspFactoryTest extends TestCase { private WebMockObjectFactory mockFactory; private JasperJspFactory jasperFactory; - + protected void setUp() throws Exception { super.setUp(); mockFactory = new WebMockObjectFactory(); jasperFactory = new JasperJspFactory(); } - + public void testConfigure() { assertSame(jasperFactory, jasperFactory.configure(mockFactory)); @@ -38,7 +38,7 @@ public void testConfigure() assertSame(jasperFactory.getPageContext(null, null, null, null, true, 1, true), mockFactory.getMockPageContext()); assertTrue(mockFactory.getMockPageContext().getELContext() instanceof ELContextImpl); } - + public void testResolveVariable() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); @@ -46,7 +46,7 @@ public void testResolveVariable() ELResolver resolver = mockFactory.getMockPageContext().getELContext().getELResolver(); assertEquals("value", resolver.getValue(mockFactory.getMockPageContext().getELContext(), null, "test")); } - + public void testValueExpressionGetAndSet() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); @@ -59,7 +59,7 @@ public void testValueExpressionGetAndSet() valueExpression.setValue(mockFactory.getMockPageContext().getELContext(), "anotherValue"); assertEquals("anotherValue", testObject.getTestProperty()); } - + public void testValueExpressionAttributes() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); @@ -78,7 +78,7 @@ public void testValueExpressionAttributes() assertTrue(valueExpression.isReadOnly(mockFactory.getMockPageContext().getELContext())); assertEquals("${test.testReadOnlyProperty}", valueExpression.getExpressionString()); } - + public void testArithmeticValueExpression() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); @@ -86,7 +86,7 @@ public void testArithmeticValueExpression() mockFactory.getMockRequest().setAttribute("test", testObject); assertExpressionEquals("${(test['testReadOnlyProperty'] + test.testArrayProperty[0]) == 26}", "true"); } - + public void testDeferredValueExpression() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); @@ -97,7 +97,7 @@ public void testDeferredValueExpression() mockFactory.getMockSession().setAttribute("test", "xyz"); assertExpressionEquals("#{sessionScope.test}", "xyz"); } - + public void testDeferredMethodExpression() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); @@ -112,7 +112,7 @@ public void testDeferredMethodExpression() assertTrue(Arrays.equals(new Class[] {String.class}, methodInfo.getParamTypes())); assertEquals("#{test.testMethod}", methodExpression.getExpressionString()); } - + public void testExpressionScopes() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); @@ -129,7 +129,7 @@ public void testExpressionScopes() assertExpressionEquals("${applicationScope.requesttest}", ""); assertExpressionEquals("${sessionScope.requesttest}", ""); } - + public void testImplicitObjects() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); @@ -149,41 +149,41 @@ public void testImplicitObjects() assertExpressionEquals("${headerValues.header[1]}", "value2"); assertExpressionEquals("${header.header}", "value1"); } - + private void assertExpressionEquals(String expression, String value) { JspApplicationContext applicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(mockFactory.getMockPageContext().getServletContext()); ValueExpression valueExpression = applicationContext.getExpressionFactory().createValueExpression(mockFactory.getMockPageContext().getELContext(), expression, String.class); assertEquals(value, valueExpression.getValue(mockFactory.getMockPageContext().getELContext())); } - + public static class TestObject { - private String testProperty; - - public String getTestProperty() - { - return testProperty; - } - - public void setTestProperty(String testProperty) - { - this.testProperty = testProperty; - } - - public String[] getTestArrayProperty() - { - return new String[] {"1"}; - } - - public Integer getTestReadOnlyProperty() - { - return 25; - } - - public String testMethod(String test) - { - return test; - } + private String testProperty; + + public String getTestProperty() + { + return testProperty; + } + + public void setTestProperty(String testProperty) + { + this.testProperty = testProperty; + } + + public String[] getTestArrayProperty() + { + return new String[] {"1"}; + } + + public Integer getTestReadOnlyProperty() + { + return 25; + } + + public String testMethod(String test) + { + return test; + } } } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java index f75eafdd5..b67d96b00 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java @@ -41,7 +41,7 @@ public void testEvaluateFailure() throws Exception //should throw exception } } - + public void testEvaluateOk() throws Exception { evaluator.addObject("myexp", 3); @@ -50,7 +50,7 @@ public void testEvaluateOk() throws Exception evaluator.addObject("myexp", object); assertEquals(object, evaluator.evaluate("myexp", Object.class, null, null)); } - + public void testExpression() throws Exception { Expression expression = evaluator.parseExpression("myexp", String.class, null); @@ -76,6 +76,6 @@ public void testExpression() throws Exception //should throw exception } } - + public void testDummy(){} } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java index b089f932b..f44ba9a38 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java @@ -19,13 +19,13 @@ public class MockFilterChainTest extends TestCase { private MockFilterChain chain; - + protected void setUp() throws Exception { super.setUp(); chain = new MockFilterChain(); } - + public void testNoServlet() throws Exception { chain.doFilter(null, null); @@ -38,21 +38,21 @@ public void testNoServlet() throws Exception chain.doFilter(null, null); assertFalse(servlet.wasServiceCalled()); } - + public void testFilterInstance() throws Exception { try { chain.addFilter(String.class); fail(); - } + } catch(IllegalArgumentException exc) { //should throw exception } chain.addFilter(TestFilter.class); } - + public void testDoFilter() throws Exception { TestFilter filter1 = new TestFilter(); @@ -76,7 +76,7 @@ public void testDoFilter() throws Exception assertNull(chain.getLastRequest()); assertNull(chain.getLastResponse()); } - + public void testRequestAndResponseList() throws Exception { TestFilter filter1 = new TestFilter(); @@ -107,7 +107,7 @@ public void testRequestAndResponseList() throws Exception assertSame(response2, chain.getResponseList().get(3)); assertSame(response2, chain.getLastResponse()); } - + public void testLastRequestAndResponse() throws Exception { TestFilter filter1 = new TestFilter(); @@ -122,7 +122,7 @@ public void testLastRequestAndResponse() throws Exception assertSame(request, chain.getLastRequest()); assertSame(response, chain.getLastResponse()); } - + public void testReset() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); @@ -137,102 +137,102 @@ public void testReset() throws Exception chain.doFilter(request, response); assertFalse(filter2.wasDoFilterCalled()); } - + public static class SkipTestFilter implements Filter { - public void init(FilterConfig config) throws ServletException - { + public void init(FilterConfig config) throws ServletException + { - } + } - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException - { - - } + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException + { - public void destroy() - { - - } + } + + public void destroy() + { + + } } - + public static class TestFilter implements Filter { - private boolean doFilterCalled = false; - private boolean doChain = true; - private ServletRequest request; - private ServletResponse response; + private boolean doFilterCalled = false; + private boolean doChain = true; + private ServletRequest request; + private ServletResponse response; - public void init(FilterConfig config) throws ServletException - { + public void init(FilterConfig config) throws ServletException + { - } + } - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException - { - doFilterCalled = true; - if(doChain) + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - if(null != this.request) + doFilterCalled = true; + if(doChain) { - request = this.request; + if(null != this.request) + { + request = this.request; + } + if(null != this.response) + { + response = this.response; + } + chain.doFilter(request, response); } - if(null != this.response) - { - response = this.response; - } - chain.doFilter(request, response); } - } - public void destroy() - { - - } + public void destroy() + { - public void setDoChain(boolean doChain) - { - this.doChain = doChain; - } - - public void setRequest(ServletRequest request) - { - this.request = request; - } - - public void setResponse(ServletResponse response) - { - this.response = response; - } - - public boolean wasDoFilterCalled() - { - return doFilterCalled; - } + } - public void reset() - { - doFilterCalled = false; - } + public void setDoChain(boolean doChain) + { + this.doChain = doChain; + } + + public void setRequest(ServletRequest request) + { + this.request = request; + } + + public void setResponse(ServletResponse response) + { + this.response = response; + } + + public boolean wasDoFilterCalled() + { + return doFilterCalled; + } + + public void reset() + { + doFilterCalled = false; + } } - + public static class TestServlet extends HttpServlet { - private boolean serviceCalled = false; - - public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException - { - serviceCalled = true; - } - - public void reset() - { - serviceCalled = false; - } - - public boolean wasServiceCalled() - { - return serviceCalled; - } + private boolean serviceCalled = false; + + public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException + { + serviceCalled = true; + } + + public void reset() + { + serviceCalled = false; + } + + public boolean wasServiceCalled() + { + return serviceCalled; + } } } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java index 73ac090a2..9b15ed021 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java @@ -12,14 +12,14 @@ public class MockFunctionMapperTest extends TestCase private Method method1; private Method method2; private Method method3; - + protected void setUp() throws Exception { super.setUp(); mapper = new MockFunctionMapper(); method1 = this.getClass().getMethod("method1", null); method2 = this.getClass().getMethod("method2", null); - method3 = this.getClass().getMethod("method3", null); + method3 = this.getClass().getMethod("method3", null); } public void testAddFuntion() @@ -33,21 +33,21 @@ public void testAddFuntion() assertNull(mapper.resolveFunction(null, "method2")); assertNull(mapper.resolveFunction("myPrefix", "method3")); } - + public void method1() { - + } - + public void method2() { } - + public void method3() { } - + public void testDummy(){} } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java index d0cca377b..595fe0fd5 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java @@ -149,11 +149,11 @@ public void testFluentApi() throws Exception { assertEquals(servletPath, request.getServletPath()); Principal principal = new Principal() { - @Override - public String getName() { - return "jad"; - } - }; + @Override + public String getName() { + return "jad"; + } + }; String remoteUser = "jad"; String utf8 = "UTF-8"; String contentType = "application/json"; @@ -486,8 +486,7 @@ private int getEnumerationSize(Enumeration enumeration) { return size; } - private class TestAttributeListener implements ServletRequestAttributeListener - { + private class TestAttributeListener implements ServletRequestAttributeListener { private boolean wasAttributeAddedCalled = false; private boolean wasAttributeReplacedCalled = false; private boolean wasAttributeRemovedCalled = false; @@ -530,8 +529,7 @@ public boolean wasAttributeReplacedCalled() } } - private class TestAttributeOrderListener implements ServletRequestAttributeListener - { + private class TestAttributeOrderListener implements ServletRequestAttributeListener { private String addedEventKey; private Object addedEventValue; private String replacedEventKey; @@ -588,8 +586,7 @@ public Object getReplacedEventValue() } } - private class TestRequestDispatcher implements RequestDispatcher - { + private class TestRequestDispatcher implements RequestDispatcher { public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException { diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java index 1a8d45d78..2b509bc00 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java @@ -14,13 +14,13 @@ public class MockHttpServletResponseTest extends TestCase { private MockHttpServletResponse response; - + protected void setUp() throws Exception { super.setUp(); response = new MockHttpServletResponse(); } - + public void testResetAll() throws Exception { response.addHeader("header", "headervalue"); @@ -31,7 +31,7 @@ public void testResetAll() throws Exception assertEquals(8192, response.getBufferSize()); assertFalse(response.wasErrorSent()); } - + public void testHeaders() { response.addHeader("testHeader", "xyz"); @@ -54,7 +54,7 @@ public void testHeaders() Collection headers = response.getHeaderNames(); assertTrue(headers.isEmpty()); } - + public void testGetHeaderNames() { response.addHeader("testHeader1", "xyz1"); @@ -67,7 +67,7 @@ public void testGetHeaderNames() assertTrue(headerNames.contains("testHeader2")); assertTrue(headerNames.contains("testHeader3")); } - + public void testGetHeaders() { response.addHeader("testHeader1", "xyz1"); @@ -78,7 +78,7 @@ public void testGetHeaders() assertTrue(headers.contains("xyz1")); assertTrue(headers.contains("abc")); } - + public void testHeadersCaseInsensitive() { response.addHeader("testHeader", "xyz"); @@ -93,7 +93,7 @@ public void testHeadersCaseInsensitive() assertTrue(headerNames.contains("MYHEADER1")); assertTrue(headerNames.contains("myHeader2")); } - + public void testOutputStreams() throws IOException { response.getOutputStream().print("test"); @@ -103,21 +103,21 @@ public void testOutputStreams() throws IOException assertEquals("testtruetest", response.getOutputStreamContent()); assertEquals("testtruetest".getBytes().length, response.getOutputStreamBinaryContent().length); } - + public void testGetSetContentType() throws IOException { assertNull(response.getContentType()); response.setContentType("myType"); assertEquals("myType", response.getContentType()); } - + public void testFlush() throws IOException { response.getOutputStream().write('a'); response.flushBuffer(); assertEquals("a", ((MockServletOutputStream)response.getOutputStream()).getContent()); } - + public void testReset() throws IOException { response.addHeader("testHeader", "xyz"); @@ -130,7 +130,7 @@ public void testReset() throws IOException response.reset(); assertNull(response.getHeaderList("testHeader")); } - + public void testSetCharacterEncoding() throws IOException { response.setCharacterEncoding("ISO-8859-1"); @@ -142,11 +142,11 @@ public void testSetCharacterEncoding() throws IOException response.setCharacterEncoding("ISO-8859-1"); assertTrue(response.getOutputStreamContent().startsWith("??")); response.resetAll(); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding("UTF-8"); String input = "\u00F8"; - PrintWriter writer = response.getWriter(); + PrintWriter writer = response.getWriter(); writer.write(input); - response.flushBuffer(); + response.flushBuffer(); String output = response.getOutputStreamContent(); assertTrue(output.equals(input)); } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java index 46d19ab29..187f8cd43 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java @@ -35,7 +35,7 @@ public void testResetAll() throws Exception assertNull(session.getAttribute("key")); assertEquals(-1, session.getMaxInactiveInterval()); } - + public void testBindingListenerInvalidate() { TestSessionListener listener1 = new TestSessionListener(); @@ -57,13 +57,13 @@ public void testBindingListenerInvalidate() { session.invalidate(); fail(); - } + } catch(IllegalStateException exc) { //should throw exception } } - + public void testBindingListenerOverwriteAttribute() { TestSessionListener listener1 = new TestSessionListener(); @@ -74,7 +74,7 @@ public void testBindingListenerOverwriteAttribute() assertTrue(listener2.wasValueBoundCalled()); assertFalse(listener2.wasValueUnboundCalled()); } - + public void testBindingListenerOverwriteSameAttribute() { TestSessionListener listener = new TestSessionListener(); @@ -85,7 +85,7 @@ public void testBindingListenerOverwriteSameAttribute() assertTrue(listener.wasValueBoundCalled()); assertTrue(listener.wasValueUnboundBeforeBoundCalled()); } - + public void testBindingListenerCorrectOrder() { session.setAttribute("key", "test"); @@ -107,7 +107,7 @@ public void testBindingListenerCorrectOrder() assertEquals(listener, listener.getUnboundEventValue()); assertEquals(null, listener.getUnboundSessionValue()); } - + public void testAttributeListenerCalled() { TestAttributeListener listener1 = new TestAttributeListener(); @@ -138,7 +138,7 @@ public void testAttributeListenerCalled() assertTrue(listener2.wasAttributeRemovedCalled()); assertTrue(listener3.wasAttributeRemovedCalled()); } - + public void testAttributeListenerOrder() { TestAttributeOrderListener listener = new TestAttributeOrderListener(); @@ -156,7 +156,7 @@ public void testAttributeListenerOrder() assertEquals("anotherValue", listener.getRemovedEventValue()); assertNull("", listener.getRemovedSessionValue()); } - + public void testAttributeListenerNullValue() { TestAttributeListener listener = new TestAttributeListener(); @@ -175,7 +175,7 @@ public void testAttributeListenerNullValue() session.removeAttribute("myKey"); assertFalse(listener.wasAttributeRemovedCalled()); } - + public void testGetAttributeNames() { Enumeration enumeration = session.getAttributeNames(); @@ -206,20 +206,19 @@ public void testGetAttributeNames() enumeration = session.getAttributeNames(); assertFalse(enumeration.hasMoreElements()); } - - private static class TestSessionListener implements HttpSessionBindingListener - { + + private static class TestSessionListener implements HttpSessionBindingListener { private boolean valueBoundCalled = false; private boolean valueUnboundCalled = false; private boolean valueUnboundBeforeBoundCalled = false; - + public void reset() { valueBoundCalled = false; valueUnboundCalled = false; valueUnboundBeforeBoundCalled = false; } - + public void valueBound(HttpSessionBindingEvent event) { valueBoundCalled = true; @@ -233,7 +232,7 @@ public void valueUnbound(HttpSessionBindingEvent event) valueUnboundBeforeBoundCalled = true; } } - + public boolean wasValueBoundCalled() { return valueBoundCalled; @@ -243,22 +242,21 @@ public boolean wasValueUnboundCalled() { return valueUnboundCalled; } - + public boolean wasValueUnboundBeforeBoundCalled() { return valueUnboundBeforeBoundCalled; } } - - private static class TestSessionOrderListener implements HttpSessionBindingListener - { + + private static class TestSessionOrderListener implements HttpSessionBindingListener { private String boundEventKey; private Object boundEventValue; private Object boundSessionValue; private String unboundEventKey; private Object unboundEventValue; private Object unboundSessionValue; - + public void valueBound(HttpSessionBindingEvent event) { boundEventKey = event.getName(); @@ -272,7 +270,7 @@ public void valueUnbound(HttpSessionBindingEvent event) unboundEventValue = event.getValue(); unboundSessionValue = event.getSession().getAttribute(unboundEventKey); } - + public String getBoundEventKey() { return boundEventKey; @@ -303,14 +301,13 @@ public Object getUnboundSessionValue() return unboundSessionValue; } } - - private static class InvalidateAttributeListener implements HttpSessionAttributeListener - { + + private static class InvalidateAttributeListener implements HttpSessionAttributeListener { private boolean didThrowIllegalStateException = false; - + public void attributeAdded(HttpSessionBindingEvent event) { - + } public void attributeRemoved(HttpSessionBindingEvent event) @@ -320,7 +317,7 @@ public void attributeRemoved(HttpSessionBindingEvent event) try { session.getAttribute(event.getName()); - } + } catch(IllegalStateException exc) { didThrowIllegalStateException = true; @@ -329,7 +326,7 @@ public void attributeRemoved(HttpSessionBindingEvent event) public void attributeReplaced(HttpSessionBindingEvent event) { - + } public boolean getDidThrowIllegalStateException() @@ -337,13 +334,12 @@ public boolean getDidThrowIllegalStateException() return didThrowIllegalStateException; } } - - private static class TestAttributeListener implements HttpSessionAttributeListener - { + + private static class TestAttributeListener implements HttpSessionAttributeListener { private boolean wasAttributeAddedCalled = false; private boolean wasAttributeReplacedCalled = false; private boolean wasAttributeRemovedCalled = false; - + public void attributeAdded(HttpSessionBindingEvent event) { wasAttributeAddedCalled = true; @@ -358,14 +354,14 @@ public void attributeReplaced(HttpSessionBindingEvent event) { wasAttributeReplacedCalled = true; } - + public void reset() { wasAttributeAddedCalled = false; wasAttributeReplacedCalled = false; wasAttributeRemovedCalled = false; } - + public boolean wasAttributeAddedCalled() { return wasAttributeAddedCalled; @@ -381,9 +377,8 @@ public boolean wasAttributeReplacedCalled() return wasAttributeReplacedCalled; } } - - private static class TestAttributeOrderListener implements HttpSessionAttributeListener - { + + private static class TestAttributeOrderListener implements HttpSessionAttributeListener { private String addedEventKey; private Object addedEventValue; private Object addedSessionValue; @@ -393,7 +388,7 @@ private static class TestAttributeOrderListener implements HttpSessionAttributeL private String removedEventKey; private Object removedEventValue; private Object removedSessionValue; - + public void attributeAdded(HttpSessionBindingEvent event) { addedEventKey = event.getName(); @@ -414,7 +409,7 @@ public void attributeReplaced(HttpSessionBindingEvent event) replacedEventValue = event.getValue(); replacedSessionValue = event.getSession().getAttribute(replacedEventKey); } - + public String getAddedEventKey() { return addedEventKey; diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java index dc3fd7a2b..bbf8db967 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java @@ -9,7 +9,7 @@ public class MockJspPropertyGroupDescriptorTest extends TestCase { private MockJspPropertyGroupDescriptor descriptor; - + protected void setUp() throws Exception { descriptor = new MockJspPropertyGroupDescriptor(); @@ -60,7 +60,7 @@ public void testReset() assertEquals("false", descriptor.getScriptingInvalid()); assertEquals("false", descriptor.getTrimDirectiveWhitespaces()); } - + public void testIncludeAndURLPatterns() { assertTrue(descriptor.getIncludeCodas().isEmpty()); @@ -82,7 +82,7 @@ public void testIncludeAndURLPatterns() assertTrue(descriptor.getIncludePreludes().isEmpty()); assertTrue(descriptor.getUrlPatterns().isEmpty()); } - + public void testIncludeAndURLPatternsListChange() { descriptor.addIncludeCoda("coda1"); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java index 2885fafbd..772e0b7ad 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java @@ -20,7 +20,7 @@ public void testWithDefaultWriter() throws Exception writer.print("test3"); assertEquals("test3", writer.getOutputAsString()); } - + public void testWithProvidedWriter() throws Exception { StringWriter providedWriter = new StringWriter(); @@ -30,7 +30,7 @@ public void testWithProvidedWriter() throws Exception { writer.clear(); fail(); - } + } catch(IOException exc) { //should throw exception @@ -42,7 +42,7 @@ public void testWithProvidedWriter() throws Exception writer.flush(); assertEquals("test1test2test3", providedWriter.toString()); } - + public void testWithProvidedResponse() throws Exception { MockHttpServletResponse response = new MockHttpServletResponse(); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java index ef9ff8354..29036e958 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java @@ -38,7 +38,7 @@ protected void tearDown() { context = null; } - + public void testResetAll() throws Exception { context.setAttribute("key", "value"); @@ -49,7 +49,7 @@ public void testResetAll() throws Exception assertNull(context.getResourcePaths("path")); assertNull(context.getResource("path")); } - + public void testResources() throws Exception { context.setResource("testPath", new URL("http://test")); @@ -79,7 +79,7 @@ public void testResources() throws Exception assertEquals(3, stream.read()); assertEquals(-1, stream.read()); } - + public void testAttributeListenerCalled() { TestAttributeListener listener1 = new TestAttributeListener(); @@ -144,7 +144,7 @@ public void testAttributeListenerNullValue() context.removeAttribute("myKey"); assertFalse(listener.wasAttributeRemovedCalled()); } - + public void testGetAttributeNames() { Enumeration enumeration = context.getAttributeNames(); @@ -175,24 +175,24 @@ public void testGetAttributeNames() enumeration = context.getAttributeNames(); assertFalse(enumeration.hasMoreElements()); } - + public void testRequestDispatcher() throws Exception { final String rdPath1 = "rdPathOne"; final String rdPath2 = "rdPathTwo"; final String rdPath3 = "rdPathThree"; - + assertEquals(0, context.getRequestDispatcherMap().size()); MockRequestDispatcher rd1 = (MockRequestDispatcher)context.getRequestDispatcher(rdPath1); assertEquals(rdPath1, rd1.getPath()); assertNull(rd1.getForwardedRequest()); assertNull(rd1.getIncludedRequest()); - + assertEquals(1, context.getRequestDispatcherMap().size()); assertTrue(context.getRequestDispatcherMap().containsKey(rdPath1)); assertSame(rd1, context.getRequestDispatcherMap().get(rdPath1)); - + MockRequestDispatcher actualRd2 = new MockRequestDispatcher(); context.setRequestDispatcher(rdPath2, actualRd2); MockRequestDispatcher rd2 = (MockRequestDispatcher)context.getRequestDispatcher(rdPath2); @@ -200,31 +200,31 @@ public void testRequestDispatcher() throws Exception assertSame(actualRd2, rd2); assertNull(rd1.getForwardedRequest()); assertNull(rd1.getIncludedRequest()); - + rd2 = (MockRequestDispatcher)context.getNamedDispatcher(rdPath2); assertEquals(rdPath2, rd2.getPath()); assertSame(actualRd2, rd2); - + assertEquals(2, context.getRequestDispatcherMap().size()); assertTrue(context.getRequestDispatcherMap().containsKey(rdPath2)); assertSame(rd2, context.getRequestDispatcherMap().get(rdPath2)); - + RequestDispatcher actualRd3 = new TestRequestDispatcher(); context.setRequestDispatcher(rdPath3, actualRd3); RequestDispatcher rd3 = context.getRequestDispatcher(rdPath3); assertSame(actualRd3, rd3); - + rd3 = context.getNamedDispatcher(rdPath3); assertSame(actualRd3, rd3); - + assertEquals(3, context.getRequestDispatcherMap().size()); assertTrue(context.getRequestDispatcherMap().containsKey(rdPath3)); assertSame(rd3, context.getRequestDispatcherMap().get(rdPath3)); - + context.clearRequestDispatcherMap(); assertEquals(0, context.getRequestDispatcherMap().size()); } - + public void testSetResourceAsStream() throws Exception { byte[] input = {1, 2, 3, 4}; @@ -235,7 +235,7 @@ public void testSetResourceAsStream() throws Exception result = context.getResourceAsStream("testpath2"); assertTrue(StreamUtil.compareStreams(new ByteArrayInputStream(input), result)); } - + public void testGetContext() throws Exception { assertNull(context.getContext("abc")); @@ -245,7 +245,7 @@ public void testGetContext() throws Exception context.setContext("xyz", anotherContext); assertSame(anotherContext, context.getContext("xyz")); } - + public void testInitParameters() { context.setInitParameter("key1", "value1"); @@ -270,7 +270,7 @@ public void testInitParameters() params = context.getInitParameterNames(); assertFalse(params.hasMoreElements()); } - + public void testInitParametersOverwrite() { assertTrue(context.setInitParameter("key1", "value1")); @@ -282,7 +282,7 @@ public void testInitParametersOverwrite() context.setInitParameters(parameters); assertEquals("value2", context.getInitParameter("key1")); } - + public void testVersion() { context.setMajorVersion(5); @@ -290,13 +290,12 @@ public void testVersion() assertEquals(5, context.getMajorVersion()); assertEquals(1, context.getMinorVersion()); } - - private class TestAttributeListener implements ServletContextAttributeListener - { + + private class TestAttributeListener implements ServletContextAttributeListener { private boolean wasAttributeAddedCalled = false; private boolean wasAttributeReplacedCalled = false; private boolean wasAttributeRemovedCalled = false; - + public void attributeAdded(ServletContextAttributeEvent event) { wasAttributeAddedCalled = true; @@ -311,14 +310,14 @@ public void attributeReplaced(ServletContextAttributeEvent event) { wasAttributeReplacedCalled = true; } - + public void reset() { wasAttributeAddedCalled = false; wasAttributeReplacedCalled = false; wasAttributeRemovedCalled = false; } - + public boolean wasAttributeAddedCalled() { return wasAttributeAddedCalled; @@ -335,15 +334,14 @@ public boolean wasAttributeReplacedCalled() } } - private class TestAttributeOrderListener implements ServletContextAttributeListener - { + private class TestAttributeOrderListener implements ServletContextAttributeListener { private String addedEventKey; private Object addedEventValue; private String replacedEventKey; private Object replacedEventValue; private String removedEventKey; private Object removedEventValue; - + public void attributeAdded(ServletContextAttributeEvent event) { addedEventKey = event.getName(); @@ -361,7 +359,7 @@ public void attributeReplaced(ServletContextAttributeEvent event) replacedEventKey = event.getName(); replacedEventValue = event.getValue(); } - + public String getAddedEventKey() { return addedEventKey; @@ -392,15 +390,14 @@ public Object getReplacedEventValue() return replacedEventValue; } } - - private class TestRequestDispatcher implements RequestDispatcher - { - + + private class TestRequestDispatcher implements RequestDispatcher { + public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException { } - + public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException { diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java index adc71794f..a27e909ef 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java @@ -17,7 +17,7 @@ protected void tearDown() throws Exception { resolver = null; } - + public void testResolve() throws Exception { assertNull(resolver.resolveVariable("test")); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java index e8766f47b..99ed6bebd 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java @@ -24,7 +24,7 @@ public class TestBodyTag extends BodyTagSupport private boolean doEndTagCalled = false; private boolean doAfterBodyCalled = false; private boolean doInitBodyCalled = false; - + public void setDoAfterBodyReturnValue(int doAfterBodyReturnValue) { this.doAfterBodyReturnValue = doAfterBodyReturnValue; @@ -53,7 +53,7 @@ public int doStartTag() throws JspException } return doStartTagReturnValue; } - + public void doInitBody() throws JspException { doInitBodyCalled = true; @@ -66,7 +66,7 @@ public int doAfterBody() throws JspException int returnValue = doAfterBodyReturnValue; if(BodyTagSupport.EVAL_BODY_AGAIN == doAfterBodyReturnValue) { - doAfterBodyReturnValue = BodyTagSupport.SKIP_BODY; + doAfterBodyReturnValue = BodyTagSupport.SKIP_BODY; } return returnValue; } @@ -106,7 +106,7 @@ public void setTestString(String testString) { this.testString = testString; } - + public void setPageContext(PageContext context) { super.setPageContext(context); @@ -117,12 +117,12 @@ public PageContext getPageContext() { return context; } - + public JspWriter getBufferedOut() { return bufferedOut; } - + public void release() { if(wasDoStartTagCalled() && wasDoEndTagCalled()) @@ -131,17 +131,17 @@ public void release() } releaseCalled = true; } - + public boolean wasReleaseCalled() { return releaseCalled; } - + public boolean wasReleaseCallLastMethodCall() { return releaseLastCall; } - + public boolean wasDoInitBodyCalled() { return doInitBodyCalled; diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java index 12ce4ed66..58d710c09 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java @@ -30,6 +30,6 @@ public int doStartTag() throws JspException } return EVAL_BODY_INCLUDE; } - - + + } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java index c67c8b555..fd3d30425 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java @@ -21,7 +21,7 @@ public class TestTag extends TagSupport private boolean doStartTagCalled = false; private boolean doEndTagCalled = false; private boolean doAfterBodyCalled = false; - + public void setDoAfterBodyReturnValue(int doAfterBodyReturnValue) { this.doAfterBodyReturnValue = doAfterBodyReturnValue; @@ -50,14 +50,14 @@ public int doStartTag() throws JspException } return doStartTagReturnValue; } - + public int doAfterBody() throws JspException { doAfterBodyCalled = true; int returnValue = doAfterBodyReturnValue; if(BodyTagSupport.EVAL_BODY_AGAIN == doAfterBodyReturnValue) { - doAfterBodyReturnValue = BodyTagSupport.SKIP_BODY; + doAfterBodyReturnValue = BodyTagSupport.SKIP_BODY; } return returnValue; } @@ -67,7 +67,7 @@ public int doEndTag() throws JspException doEndTagCalled = true; return doEndTagReturnValue; } - + public double getTestDouble() { return testDouble; @@ -111,12 +111,12 @@ public boolean wasReleaseCalled() { return releaseCalled; } - + public boolean wasReleaseCallLastMethodCall() { return releaseLastCall; } - + public boolean wasDoAfterBodyCalled() { return doAfterBodyCalled; @@ -131,7 +131,7 @@ public boolean wasDoStartTagCalled() { return doStartTagCalled; } - + public void setPageContext(PageContext context) { super.setPageContext(context); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java index b758de0a8..785b22dc9 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java @@ -38,7 +38,7 @@ public void testDifferentMockObjects() assertNotSame(factory1.getMockServletConfig(), factory2.getMockServletConfig()); assertNotSame(factory1.getMockServletContext(), factory2.getMockServletContext()); } - + public void testMockObjectsWithSameContext() { WebMockObjectFactory factory1 = new WebMockObjectFactory(); @@ -49,7 +49,7 @@ public void testMockObjectsWithSameContext() assertNotSame(factory1.getMockServletConfig(), factory2.getMockServletConfig()); assertSame(factory1.getMockServletContext(), factory2.getMockServletContext()); } - + public void testMockObjectsWithSameSessionAndContext() { WebMockObjectFactory factory1 = new WebMockObjectFactory(); @@ -66,7 +66,7 @@ public void testMockObjectsWithSameSessionAndContext() assertNotSame(factory1.getMockServletConfig(), factory2.getMockServletConfig()); assertSame(factory1.getMockServletContext(), factory2.getMockServletContext()); } - + public void testSetDefaultJspFactory() { WebMockObjectFactory factory = new WebMockObjectFactory(); @@ -88,7 +88,7 @@ public void testSetDefaultJspFactory() assertNull(factory.getMockJspFactory()); assertNull(factory.getJspFactory()); } - + public void testAddRequestWrapper() { WebMockObjectFactory factory = new WebMockObjectFactory(); @@ -100,7 +100,7 @@ public void testAddRequestWrapper() HttpServletRequestWrapper requestWrapper = (HttpServletRequestWrapper)factory.getWrappedRequest(); assertSame(factory.getMockRequest(), requestWrapper.getRequest()); } - + public void testAddResponseWrapper() throws Exception { WebMockObjectFactory factory = new WebMockObjectFactory(); @@ -109,11 +109,11 @@ public void testAddResponseWrapper() throws Exception assertTrue(response instanceof HttpServletResponseWrapper); response.getWriter().print("test"); response.getWriter().flush(); - assertEquals("test", factory.getMockResponse().getOutputStreamContent()); + assertEquals("test", factory.getMockResponse().getOutputStreamContent()); HttpServletResponseWrapper responseWrapper = (HttpServletResponseWrapper)factory.getWrappedResponse(); assertSame(factory.getMockResponse(), responseWrapper.getResponse()); } - + public void testAddRequestAndResponseWrapperClasses() { WebMockObjectFactory factory = new WebMockObjectFactory(); @@ -124,7 +124,7 @@ public void testAddRequestAndResponseWrapperClasses() assertTrue(factory.getWrappedResponse() instanceof TestResponseWrapper); assertSame(factory.getMockResponse(), ((TestResponseWrapper)factory.getWrappedResponse()).getResponse()); } - + public void testRefresh() throws Exception { WebMockObjectFactory factory = new WebMockObjectFactory(); @@ -141,7 +141,7 @@ public void testRefresh() throws Exception assertSame(responseWrapper, pageContext.getResponse()); assertSame(pageContext, factory.getMockJspFactory().getPageContext()); } - + public void testOverrideCreate() { WebMockObjectFactory factory = new TestWebMockObjectFactory(); @@ -154,39 +154,36 @@ public void testOverrideCreate() assertNotSame(factory.getMockServletContext().getClass(), MockServletContext.class); assertNotSame(factory.getMockSession().getClass(), MockHttpSession.class); } - - public static class TestRequestWrapper extends MockHttpServletRequest - { + + public static class TestRequestWrapper extends MockHttpServletRequest { private HttpServletRequest request; - + public TestRequestWrapper(HttpServletRequest request) { this.request = request; } - + public HttpServletRequest getRequest() { return request; } } - - public static class TestResponseWrapper extends MockHttpServletResponse - { + + public static class TestResponseWrapper extends MockHttpServletResponse { private HttpServletResponse response; - + public TestResponseWrapper(HttpServletResponse response) { this.response = response; } - + public HttpServletResponse getResponse() { return response; } } - - public static class TestWebMockObjectFactory extends WebMockObjectFactory - { + + public static class TestWebMockObjectFactory extends WebMockObjectFactory { public MockFilterChain createMockFilterChain() { return new MockFilterChain() {}; @@ -196,7 +193,7 @@ public MockFilterConfig createMockFilterConfig() { return new MockFilterConfig() {}; } - + public MockPageContext createMockPageContext() { return new MockPageContext() {}; @@ -204,7 +201,7 @@ public MockPageContext createMockPageContext() public MockHttpServletRequest createMockRequest() { - + return new MockHttpServletRequest() {}; } @@ -228,9 +225,8 @@ public MockHttpSession createMockSession() return new MockHttpSession() {}; } } - - public static class TestJspFactory extends JspFactory - { + + public static class TestJspFactory extends JspFactory { public JspEngineInfo getEngineInfo() { return null; @@ -248,7 +244,7 @@ public PageContext getPageContext(Servlet servlet, ServletRequest request, Servl public void releasePageContext(PageContext pageContext) { - - } + + } } } From 20e8c296a462d95d483a83d109a9f6588fd196e8 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sun, 24 May 2026 08:41:43 +0200 Subject: [PATCH 30/40] Change scope of junit 4 maven dependency from provided to test in maven module mockrunner-servlet --- mockrunner-servlet/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mockrunner-servlet/pom.xml b/mockrunner-servlet/pom.xml index 881f76e1a..011d5dd78 100644 --- a/mockrunner-servlet/pom.xml +++ b/mockrunner-servlet/pom.xml @@ -16,7 +16,7 @@ junit junit - provided + test com.mockrunner From 6f8244c91d1e8a8d07e76b091ae2b4c502d56511 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sun, 24 May 2026 08:46:01 +0200 Subject: [PATCH 31/40] Move JUnit tests in mockrunner-servlet examples from src/main/java to src/test/java --- .../com/mockrunner/example/servlet/ImageButtonFilterTest.java | 0 .../java/com/mockrunner/example/servlet/LogoutServletTest.java | 0 .../java/com/mockrunner/example/servlet/RedirectServletTest.java | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename mockrunner-servlet/src/{main => test}/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java (100%) rename mockrunner-servlet/src/{main => test}/java/com/mockrunner/example/servlet/LogoutServletTest.java (100%) rename mockrunner-servlet/src/{main => test}/java/com/mockrunner/example/servlet/RedirectServletTest.java (100%) diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java similarity index 100% rename from mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java rename to mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/LogoutServletTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java similarity index 100% rename from mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/LogoutServletTest.java rename to mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/RedirectServletTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java similarity index 100% rename from mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/RedirectServletTest.java rename to mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java From 2f29dc379a9db34e5461cd9117231cb567df8bab Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sun, 24 May 2026 08:52:04 +0200 Subject: [PATCH 32/40] Remove JUnit 4 annotations from test base class in mockrunner-servlet src/main/java --- .../com/mockrunner/servlet/BasicServletTestCaseAdapter.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/servlet/BasicServletTestCaseAdapter.java b/mockrunner-servlet/src/main/java/com/mockrunner/servlet/BasicServletTestCaseAdapter.java index ea3bf4e5b..f6df475b9 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/servlet/BasicServletTestCaseAdapter.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/servlet/BasicServletTestCaseAdapter.java @@ -5,9 +5,6 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; -import org.junit.After; -import org.junit.Before; - import com.mockrunner.base.BasicHTMLOutputTestCase; import com.mockrunner.base.HTMLOutputModule; import com.mockrunner.mock.web.WebMockObjectFactory; @@ -38,7 +35,6 @@ public BasicServletTestCaseAdapter(String name) super(name); } - @After public void tearDown() throws Exception { servletTestModule = null; @@ -49,7 +45,6 @@ public void tearDown() throws Exception * Creates the {@link com.mockrunner.servlet.ServletTestModule}. If you * overwrite this method, you must call super.setUp(). */ - @Before public void setUp() throws Exception { servletTestModule = createServletTestModule(getWebMockObjectFactory()); From f20b8f941abc316f491f385150cacebddc1e3a7e Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Sun, 24 May 2026 19:52:11 +0200 Subject: [PATCH 33/40] Apply editorconfig formatting to mockrunner-servlet pom.xml --- mockrunner-servlet/pom.xml | 263 +++++++++++++++++++------------------ 1 file changed, 134 insertions(+), 129 deletions(-) diff --git a/mockrunner-servlet/pom.xml b/mockrunner-servlet/pom.xml index 011d5dd78..9aa5e2275 100644 --- a/mockrunner-servlet/pom.xml +++ b/mockrunner-servlet/pom.xml @@ -1,137 +1,142 @@ - 4.0.0 - - com.mockrunner - mockrunner - 2.0.8-SNAPSHOT - + 4.0.0 + + com.mockrunner + mockrunner + 2.0.8-SNAPSHOT + - mockrunner-servlet - MockRunner-Servlet - Mock classes for servlets + mockrunner-servlet + MockRunner-Servlet + Mock classes for servlets - - - junit - junit - test - - - com.mockrunner - mockrunner-core - - - com.mockrunner - mockrunner-core - xml - features - - - commons-logging - commons-logging - - - javax.servlet - javax.servlet-api - - - org.apache.tomcat - jasper - - - - - - org.apache.felix - maven-bundle-plugin - - - - com.mockrunner.base, - com.mockrunner.example.servlet, - com.mockrunner.mock.web, - com.mockrunner.servlet - Export-Package> - - - - - org.apache.karaf.tooling - karaf-maven-plugin - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - verify - - jar - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadoc - verify - - jar - - - - - ${javadoc-executable-path} - ${project.build.sourceEncoding} - ${project.build.sourceEncoding} - ${project.build.sourceEncoding} - none - -Xdoclint:none - - - - + + + junit + junit + test + + + com.mockrunner + mockrunner-core + test + + + com.mockrunner + mockrunner-core + + + com.mockrunner + mockrunner-core + xml + features + + + commons-logging + commons-logging + + + javax.servlet + javax.servlet-api + + + org.apache.tomcat + jasper + + + + + + org.apache.felix + maven-bundle-plugin + + + + com.mockrunner.base, + com.mockrunner.example.servlet, + com.mockrunner.mock.web, + com.mockrunner.servlet + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + verify + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadoc + verify + + jar + + + + + ${javadoc-executable-path} + ${project.build.sourceEncoding} + ${project.build.sourceEncoding} + ${project.build.sourceEncoding} + none + -Xdoclint:none + + + + - - - release-module-exclusives - - - - performRelease - true - - - - - - com.github.github - site-maven-plugin - - ${project.artifactId} - Servlet Site - - - - github-site - - site - - site - - - - - - - + + + release-module-exclusives + + + + performRelease + true + + + + + + com.github.github + site-maven-plugin + + ${project.artifactId} + Servlet Site + + + + github-site + + site + + site + + + + + + + From fbf1ba25fb74b9ac7d0728738f3760968e94d4d4 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Mon, 25 May 2026 06:53:44 +0200 Subject: [PATCH 34/40] Add test scoped maven dependencies for junit jupiter and assertj to maven module mockrunnner-servlet --- mockrunner-servlet/pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mockrunner-servlet/pom.xml b/mockrunner-servlet/pom.xml index 9aa5e2275..5cbfee7e2 100644 --- a/mockrunner-servlet/pom.xml +++ b/mockrunner-servlet/pom.xml @@ -18,6 +18,16 @@ junit test + + org.junit.jupiter + junit-jupiter-api + test + + + org.assertj + assertj-core + test + com.mockrunner mockrunner-core From 224be3738378e7e2b86c13561bb10bd5265428ee Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Mon, 25 May 2026 09:14:17 +0200 Subject: [PATCH 35/40] Change mockrunner-servlet unit tests from JUnit 3 style to JUnit jupiter with assertj for collection assertions Also suppress warnings about the use of raw types (i.e. non-parameterized types) in the tests. --- .../test/web/JasperJspFactoryTest.java | 81 +++++---- .../test/web/MockExpressionEvaluatorTest.java | 22 ++- .../test/web/MockFilterChainTest.java | 28 ++-- .../test/web/MockFilterConfigTest.java | 11 +- .../test/web/MockFunctionMapperTest.java | 13 +- .../test/web/MockHttpServletRequestTest.java | 154 ++++++++++-------- .../test/web/MockHttpServletResponseTest.java | 89 ++++++---- .../test/web/MockHttpSessionTest.java | 62 ++++--- .../MockJspPropertyGroupDescriptorTest.java | 25 ++- .../test/web/MockJspWriterTest.java | 18 +- .../test/web/MockServletConfigTest.java | 13 +- .../test/web/MockServletContextTest.java | 59 +++++-- .../test/web/MockVariableResolverTest.java | 20 ++- .../test/web/WebMockObjectFactoryTest.java | 39 +++-- 14 files changed, 403 insertions(+), 231 deletions(-) diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java index 26b105f0f..d9e784caa 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java @@ -1,6 +1,6 @@ package com.mockrunner.test.web; -import java.util.Arrays; +import static org.assertj.core.api.Assertions.assertThat; import javax.el.ELResolver; import javax.el.MethodExpression; @@ -11,43 +11,46 @@ import org.apache.jasper.el.ELContextImpl; import org.apache.jasper.runtime.JspApplicationContextImpl; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.JasperJspFactory; import com.mockrunner.mock.web.MockHttpServletRequest; import com.mockrunner.mock.web.WebMockObjectFactory; -import junit.framework.TestCase; - -public class JasperJspFactoryTest extends TestCase +class JasperJspFactoryTest { private WebMockObjectFactory mockFactory; private JasperJspFactory jasperFactory; + @BeforeEach protected void setUp() throws Exception { - super.setUp(); mockFactory = new WebMockObjectFactory(); jasperFactory = new JasperJspFactory(); } - public void testConfigure() + @Test + void testConfigure() { - assertSame(jasperFactory, jasperFactory.configure(mockFactory)); - assertTrue(jasperFactory.getJspApplicationContext(null) instanceof JspApplicationContextImpl); - assertSame(jasperFactory.getJspApplicationContext(null), mockFactory.getMockServletContext().getAttribute(JspApplicationContextImpl.class.getName())); - assertSame(jasperFactory.getPageContext(null, null, null, null, true, 1, true), mockFactory.getMockPageContext()); - assertTrue(mockFactory.getMockPageContext().getELContext() instanceof ELContextImpl); + assertThat(jasperFactory).isSameAs(jasperFactory.configure(mockFactory)); + assertThat(jasperFactory.getJspApplicationContext(null)).isInstanceOf(JspApplicationContextImpl.class); + assertThat(jasperFactory.getJspApplicationContext(null)).isSameAs(mockFactory.getMockServletContext().getAttribute(JspApplicationContextImpl.class.getName())); + assertThat(jasperFactory.getPageContext(null, null, null, null, true, 1, true)).isSameAs(mockFactory.getMockPageContext()); + assertThat(mockFactory.getMockPageContext().getELContext()).isInstanceOf(ELContextImpl.class); } - public void testResolveVariable() + @Test + void testResolveVariable() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); mockFactory.getMockSession().setAttribute("test", "value"); ELResolver resolver = mockFactory.getMockPageContext().getELContext().getELResolver(); - assertEquals("value", resolver.getValue(mockFactory.getMockPageContext().getELContext(), null, "test")); + assertThat(resolver.getValue(mockFactory.getMockPageContext().getELContext(), null, "test")).isEqualTo("value"); } - public void testValueExpressionGetAndSet() + @Test + void testValueExpressionGetAndSet() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); TestObject testObject = new TestObject(); @@ -55,12 +58,13 @@ public void testValueExpressionGetAndSet() mockFactory.getMockSession().setAttribute("test", testObject); JspApplicationContext applicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(mockFactory.getMockPageContext().getServletContext()); ValueExpression valueExpression = applicationContext.getExpressionFactory().createValueExpression(mockFactory.getMockPageContext().getELContext(), "${test.testProperty}", String.class); - assertEquals("value", valueExpression.getValue(mockFactory.getMockPageContext().getELContext())); + assertThat(valueExpression.getValue(mockFactory.getMockPageContext().getELContext())).isEqualTo("value"); valueExpression.setValue(mockFactory.getMockPageContext().getELContext(), "anotherValue"); - assertEquals("anotherValue", testObject.getTestProperty()); + assertThat(testObject.getTestProperty()).isEqualTo("anotherValue"); } - public void testValueExpressionAttributes() + @Test + void testValueExpressionAttributes() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); TestObject testObject = new TestObject(); @@ -68,18 +72,19 @@ public void testValueExpressionAttributes() mockFactory.getMockSession().setAttribute("test", testObject); JspApplicationContext applicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(mockFactory.getMockPageContext().getServletContext()); ValueExpression valueExpression = applicationContext.getExpressionFactory().createValueExpression(mockFactory.getMockPageContext().getELContext(), "${test.testProperty}", String.class); - assertEquals(String.class, valueExpression.getExpectedType()); - assertEquals(String.class, valueExpression.getType(mockFactory.getMockPageContext().getELContext())); - assertFalse(valueExpression.isReadOnly(mockFactory.getMockPageContext().getELContext())); - assertEquals("${test.testProperty}", valueExpression.getExpressionString()); + assertThat(valueExpression.getExpectedType()).isEqualTo(String.class); + assertThat(valueExpression.getType(mockFactory.getMockPageContext().getELContext())).isEqualTo(String.class); + assertThat(valueExpression.isReadOnly(mockFactory.getMockPageContext().getELContext())).isFalse(); + assertThat(valueExpression.getExpressionString()).isEqualTo("${test.testProperty}"); valueExpression = applicationContext.getExpressionFactory().createValueExpression(mockFactory.getMockPageContext().getELContext(), "${test.testReadOnlyProperty}", Integer.class); - assertEquals(Integer.class, valueExpression.getExpectedType()); - assertEquals(Integer.class, valueExpression.getType(mockFactory.getMockPageContext().getELContext())); - assertTrue(valueExpression.isReadOnly(mockFactory.getMockPageContext().getELContext())); - assertEquals("${test.testReadOnlyProperty}", valueExpression.getExpressionString()); + assertThat(valueExpression.getExpectedType()).isEqualTo(Integer.class); + assertThat(valueExpression.getType(mockFactory.getMockPageContext().getELContext())).isEqualTo(Integer.class); + assertThat(valueExpression.isReadOnly(mockFactory.getMockPageContext().getELContext())).isTrue(); + assertThat(valueExpression.getExpressionString()).isEqualTo("${test.testReadOnlyProperty}"); } - public void testArithmeticValueExpression() + @Test + void testArithmeticValueExpression() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); TestObject testObject = new TestObject(); @@ -87,7 +92,8 @@ public void testArithmeticValueExpression() assertExpressionEquals("${(test['testReadOnlyProperty'] + test.testArrayProperty[0]) == 26}", "true"); } - public void testDeferredValueExpression() + @Test + void testDeferredValueExpression() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); TestObject testObject = new TestObject(); @@ -98,22 +104,24 @@ public void testDeferredValueExpression() assertExpressionEquals("#{sessionScope.test}", "xyz"); } - public void testDeferredMethodExpression() + @Test + void testDeferredMethodExpression() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); TestObject testObject = new TestObject(); mockFactory.getMockServletContext().setAttribute("test", testObject); JspApplicationContext applicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(mockFactory.getMockPageContext().getServletContext()); MethodExpression methodExpression = applicationContext.getExpressionFactory().createMethodExpression(mockFactory.getMockPageContext().getELContext(), "#{test.testMethod}", String.class, new Class[] {String.class,}); - assertEquals("Hello World", methodExpression.invoke(mockFactory.getMockPageContext().getELContext(), new String[] {"Hello World"})); + assertThat(methodExpression.invoke(mockFactory.getMockPageContext().getELContext(), new String[] {"Hello World"})).isEqualTo("Hello World"); MethodInfo methodInfo = methodExpression.getMethodInfo(mockFactory.getMockPageContext().getELContext()); - assertEquals("testMethod", methodInfo.getName()); - assertEquals(String.class, methodInfo.getReturnType()); - assertTrue(Arrays.equals(new Class[] {String.class}, methodInfo.getParamTypes())); - assertEquals("#{test.testMethod}", methodExpression.getExpressionString()); + assertThat(methodInfo.getName()).isEqualTo("testMethod"); + assertThat(methodInfo.getReturnType()).isEqualTo(String.class); + assertThat(methodInfo.getParamTypes()).isEqualTo(new Class[] {String.class}); + assertThat(methodExpression.getExpressionString()).isEqualTo("#{test.testMethod}"); } - public void testExpressionScopes() + @Test + void testExpressionScopes() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); mockFactory.getMockRequest().setAttribute("requesttest", "requestvalue"); @@ -130,7 +138,8 @@ public void testExpressionScopes() assertExpressionEquals("${sessionScope.requesttest}", ""); } - public void testImplicitObjects() + @Test + void testImplicitObjects() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); MockHttpServletRequest request = mockFactory.getMockRequest(); @@ -154,7 +163,7 @@ private void assertExpressionEquals(String expression, String value) { JspApplicationContext applicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(mockFactory.getMockPageContext().getServletContext()); ValueExpression valueExpression = applicationContext.getExpressionFactory().createValueExpression(mockFactory.getMockPageContext().getELContext(), expression, String.class); - assertEquals(value, valueExpression.getValue(mockFactory.getMockPageContext().getELContext())); + assertThat(valueExpression.getValue(mockFactory.getMockPageContext().getELContext())).isEqualTo(value); } public static class TestObject diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java index b67d96b00..a131843de 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java @@ -1,25 +1,31 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + import javax.servlet.jsp.el.ELException; import javax.servlet.jsp.el.Expression; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockExpressionEvaluator; import com.mockrunner.mock.web.MockFunctionMapper; import com.mockrunner.mock.web.MockVariableResolver; -public class MockExpressionEvaluatorTest extends TestCase +@SuppressWarnings("deprecation") +class MockExpressionEvaluatorTest { private MockExpressionEvaluator evaluator; + @BeforeEach protected void setUp() throws Exception { - super.setUp(); evaluator = new MockExpressionEvaluator(); } - public void testEvaluateFailure() throws Exception + @Test + void testEvaluateFailure() throws Exception { try { @@ -42,7 +48,8 @@ public void testEvaluateFailure() throws Exception } } - public void testEvaluateOk() throws Exception + @Test + void testEvaluateOk() throws Exception { evaluator.addObject("myexp", 3); assertEquals(3, evaluator.evaluate("myexp", Integer.class, null, null)); @@ -51,7 +58,8 @@ public void testEvaluateOk() throws Exception assertEquals(object, evaluator.evaluate("myexp", Object.class, null, null)); } - public void testExpression() throws Exception + @Test + void testExpression() throws Exception { Expression expression = evaluator.parseExpression("myexp", String.class, null); try @@ -77,5 +85,5 @@ public void testExpression() throws Exception } } - public void testDummy(){} + void testDummy(){} } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java index f44ba9a38..8e627179f 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java @@ -1,5 +1,12 @@ package com.mockrunner.test.web; +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 static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.IOException; import javax.servlet.Filter; @@ -10,23 +17,23 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; +import org.junit.jupiter.api.BeforeEach; + import com.mockrunner.mock.web.MockFilterChain; import com.mockrunner.mock.web.MockHttpServletRequest; import com.mockrunner.mock.web.MockHttpServletResponse; -import junit.framework.TestCase; - -public class MockFilterChainTest extends TestCase +class MockFilterChainTest { private MockFilterChain chain; + @BeforeEach protected void setUp() throws Exception { - super.setUp(); chain = new MockFilterChain(); } - public void testNoServlet() throws Exception + void testNoServlet() throws Exception { chain.doFilter(null, null); TestServlet servlet = new TestServlet(); @@ -39,7 +46,7 @@ public void testNoServlet() throws Exception assertFalse(servlet.wasServiceCalled()); } - public void testFilterInstance() throws Exception + void testFilterInstance() throws Exception { try { @@ -53,7 +60,7 @@ public void testFilterInstance() throws Exception chain.addFilter(TestFilter.class); } - public void testDoFilter() throws Exception + void testDoFilter() throws Exception { TestFilter filter1 = new TestFilter(); TestFilter filter2 = new TestFilter(); @@ -77,7 +84,7 @@ public void testDoFilter() throws Exception assertNull(chain.getLastResponse()); } - public void testRequestAndResponseList() throws Exception + void testRequestAndResponseList() throws Exception { TestFilter filter1 = new TestFilter(); TestFilter filter2 = new TestFilter(); @@ -108,7 +115,7 @@ public void testRequestAndResponseList() throws Exception assertSame(response2, chain.getLastResponse()); } - public void testLastRequestAndResponse() throws Exception + void testLastRequestAndResponse() throws Exception { TestFilter filter1 = new TestFilter(); TestFilter filter2 = new TestFilter(); @@ -123,7 +130,7 @@ public void testLastRequestAndResponse() throws Exception assertSame(response, chain.getLastResponse()); } - public void testReset() throws Exception + void testReset() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); @@ -218,6 +225,7 @@ public void reset() public static class TestServlet extends HttpServlet { + private static final long serialVersionUID = -395159716150268037L; private boolean serviceCalled = false; public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterConfigTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterConfigTest.java index 2463c05e6..82e4faea6 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterConfigTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterConfigTest.java @@ -1,17 +1,24 @@ package com.mockrunner.test.web; +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.assertTrue; + import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockFilterConfig; -public class MockFilterConfigTest extends TestCase +public class MockFilterConfigTest { + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test public void testInitParameters() { MockFilterConfig config = new MockFilterConfig(); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java index 9b15ed021..42a0e9a5a 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java @@ -1,27 +1,32 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.lang.reflect.Method; -import com.mockrunner.mock.web.MockFunctionMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import com.mockrunner.mock.web.MockFunctionMapper; -public class MockFunctionMapperTest extends TestCase +public class MockFunctionMapperTest { private MockFunctionMapper mapper; private Method method1; private Method method2; private Method method3; + @BeforeEach protected void setUp() throws Exception { - super.setUp(); mapper = new MockFunctionMapper(); method1 = this.getClass().getMethod("method1", null); method2 = this.getClass().getMethod("method2", null); method3 = this.getClass().getMethod("method3", null); } + @Test public void testAddFuntion() { mapper.addFunction(null, "method1", method1); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java index 595fe0fd5..0c3733819 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java @@ -1,14 +1,23 @@ package com.mockrunner.test.web; +import static java.util.Collections.list; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertNotEquals; +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.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.BufferedReader; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.net.URI; import java.security.Principal; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Enumeration; import java.util.List; import java.util.Locale; @@ -22,40 +31,45 @@ import javax.servlet.ServletResponse; import javax.servlet.http.Cookie; -import org.apache.tools.ant.types.selectors.SelectorUtils; - -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockHttpServletRequest; import com.mockrunner.mock.web.MockHttpSession; import com.mockrunner.mock.web.MockRequestDispatcher; -public class MockHttpServletRequestTest extends TestCase +class MockHttpServletRequestTest { private MockHttpServletRequest request; + + @BeforeEach protected void setUp() { request = new MockHttpServletRequest(); } + @AfterEach protected void tearDown() { request = null; } - public void testResetAll() throws Exception + @Test + void testResetAll() throws Exception { request .addAttribute("key", "value") .addHeader("header", "headervalue") .setContentLength(5) .resetAll(); - assertNull(request.getAttribute("key")); - assertNull(request.getHeader("header")); - assertEquals(-1, request.getContentLength()); + assertThat(request.getAttribute("key")).isNull();; + assertThat(request.getHeader("header")).isNull(); + assertThat(request.getContentLength()).isEqualTo(-1); } - public void testAttributeListenerCalled() + @Test + void testAttributeListenerCalled() { TestAttributeListener listener1 = new TestAttributeListener(); TestAttributeListener listener2 = new TestAttributeListener(); @@ -65,59 +79,59 @@ public void testAttributeListenerCalled() .addAttributeListener(listener2) .addAttributeListener(listener3) .addAttribute("key", "value"); - assertTrue(listener1.wasAttributeAddedCalled()); - assertTrue(listener2.wasAttributeAddedCalled()); - assertTrue(listener3.wasAttributeAddedCalled()); - assertFalse(listener1.wasAttributeReplacedCalled()); - assertFalse(listener2.wasAttributeReplacedCalled()); - assertFalse(listener3.wasAttributeReplacedCalled()); + assertThat(listener1.wasAttributeAddedCalled()).isTrue(); + assertThat(listener2.wasAttributeAddedCalled()).isTrue(); + assertThat(listener3.wasAttributeAddedCalled()).isTrue(); + assertThat(listener1.wasAttributeReplacedCalled()).isFalse(); + assertThat(listener2.wasAttributeReplacedCalled()).isFalse(); + assertThat(listener3.wasAttributeReplacedCalled()).isFalse(); listener1.reset(); listener2.reset(); listener3.reset(); request.setAttribute("key", "value1"); - assertFalse(listener1.wasAttributeAddedCalled()); - assertFalse(listener2.wasAttributeAddedCalled()); - assertFalse(listener3.wasAttributeAddedCalled()); - assertTrue(listener1.wasAttributeReplacedCalled()); - assertTrue(listener2.wasAttributeReplacedCalled()); - assertTrue(listener3.wasAttributeReplacedCalled()); + assertThat(listener1.wasAttributeAddedCalled()).isFalse(); + assertThat(listener2.wasAttributeAddedCalled()).isFalse(); + assertThat(listener3.wasAttributeAddedCalled()).isFalse(); + assertThat(listener1.wasAttributeReplacedCalled()).isTrue(); + assertThat(listener2.wasAttributeReplacedCalled()).isTrue(); + assertThat(listener3.wasAttributeReplacedCalled()).isTrue(); request.removeAttribute("key"); - assertTrue(listener1.wasAttributeRemovedCalled()); - assertTrue(listener2.wasAttributeRemovedCalled()); - assertTrue(listener3.wasAttributeRemovedCalled()); + assertThat(listener1.wasAttributeRemovedCalled()).isTrue(); + assertThat(listener2.wasAttributeRemovedCalled()).isTrue(); + assertThat(listener3.wasAttributeRemovedCalled()).isTrue(); } - @SuppressWarnings("rawtypes") - public void testFluentApi() throws Exception { + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + void testFluentApi() throws Exception { request .setupAddParameter("param1", "value1") .clearParameters() .setupAddParameter("param2", "value2") .setupAddParameter("param3", "value3"); - assertEquals(2, request.getParameterMap().size()); + assertThat(request.getParameterMap().size()).isEqualTo(2); request .addAttribute("attribute1", "avalue1") .clearAttributes() .addAttribute("attribute2", "avalue2") .addAttribute("attribute3", "avalue3"); Enumeration attributeNames = request.getAttributeNames(); - int attributeNamesSize = getEnumerationSize(attributeNames); - assertEquals(2, attributeNamesSize); + assertThat(list(attributeNames)).hasSize(2); Locale defaultLocale = request.getLocale(); - assertNotNull(defaultLocale); - assertEquals("Expect an empty locales list", 0, getEnumerationSize(request.getLocales())); + assertThat(defaultLocale).isNotNull(); + assertThat(Collections.list(request.getLocales())).isEmpty(); Locale nbNo = Locale.forLanguageTag("nb-NO"); request.addLocale(nbNo); // Verify default locale has changed and that getLocales() is non-empty assertNotEquals(defaultLocale, request.getLocale()); assertEquals(nbNo, request.getLocale()); - assertEquals(1, getEnumerationSize(request.getLocales())); + assertThat(list(request.getLocales())).hasSize(1); Locale nnNo = Locale.forLanguageTag("nn-NO"); request.addLocales(Arrays.asList(nnNo, Locale.CANADA_FRENCH)); // Verify that default locale hasn't changed and that the list of locales is changed by two assertEquals(nbNo, request.getLocale()); - assertEquals(3, getEnumerationSize(request.getLocales())); + assertThat(Collections.list(request.getLocales())).hasSize(3); String basicAuth = "Basic"; String post = "POST"; @@ -187,7 +201,8 @@ public String getName() { assertEquals(remoteHost, request.getRemoteHost()); } - public void testFluentCreators() { + @Test + void testFluentCreators() { final String url = "http://localhost:8181/myapp/servlet/argument?arg1=value"; MockHttpServletRequest getRequest = MockHttpServletRequest.getRequest(URI.create(url)); assertEquals(url, getRequest.getRequestURL().toString()); @@ -197,7 +212,8 @@ public void testFluentCreators() { assertEquals("POST", postJsonRequest.getMethod()); } - public void testAttributeListenerValues() + @Test + void testAttributeListenerValues() { TestAttributeOrderListener listener = new TestAttributeOrderListener(); request @@ -213,7 +229,8 @@ public void testAttributeListenerValues() assertEquals("anotherValue", listener.getRemovedEventValue()); } - public void testAttributeListenerNullValue() + @Test + void testAttributeListenerNullValue() { TestAttributeListener listener = new TestAttributeListener(); request @@ -233,13 +250,15 @@ public void testAttributeListenerNullValue() assertFalse(listener.wasAttributeRemovedCalled()); } - public void testGetAttributeNames() + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + void testGetAttributeNames() { Enumeration enumeration = request.getAttributeNames(); - assertFalse(enumeration.hasMoreElements()); + assertThat(enumeration.hasMoreElements()).isFalse(); request.setAttribute("key", null); enumeration = request.getAttributeNames(); - assertFalse(enumeration.hasMoreElements()); + assertThat(enumeration.hasMoreElements()).isFalse(); request .addAttribute("key1", "value1") .addAttribute("key2", "value2"); @@ -249,23 +268,24 @@ public void testGetAttributeNames() List testList = new ArrayList(); testList.add(enumeration.nextElement()); testList.add(enumeration.nextElement()); - assertFalse(enumeration.hasMoreElements()); - assertTrue(testList.contains("key1")); - assertTrue(testList.contains("key2")); + assertThat(enumeration.hasMoreElements()).isFalse(); + assertThat(testList.contains("key1")).isTrue(); + assertThat(testList.contains("key2")).isTrue(); request.setAttribute("key2", null); - assertNull(request.getAttribute("key2")); + assertThat(request.getAttribute("key2")).isNull();; enumeration = request.getAttributeNames(); testList = new ArrayList(); testList.add(enumeration.nextElement()); - assertFalse(enumeration.hasMoreElements()); - assertTrue(testList.contains("key1")); + assertThat(enumeration.hasMoreElements()).isFalse(); + assertThat(testList).contains("key1"); request.setAttribute("key1", null); - assertNull(request.getAttribute("key1")); + assertThat(request.getAttribute("key1")).isNull();; enumeration = request.getAttributeNames(); - assertFalse(enumeration.hasMoreElements()); + assertThat(enumeration.hasMoreElements()).isFalse(); } - public void testAddRequestParameter() throws Exception + @Test + void testAddRequestParameter() throws Exception { request.setupAddParameter("abc", "abc"); assertEquals("abc", request.getParameter("abc")); @@ -279,7 +299,9 @@ public void testAddRequestParameter() throws Exception assertEquals("456", request.getParameterValues("abc")[1]); } - public void testHeaders() + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + void testHeaders() { request .addHeader("testHeader", "xyz") @@ -333,7 +355,9 @@ public void testHeaders() assertFalse(request.getHeaders("doesnotexist").hasMoreElements()); } - public void testHeadersCaseInsensitive() + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + void testHeadersCaseInsensitive() { request .addHeader("testHeader", "xyz") @@ -362,7 +386,8 @@ public void testHeadersCaseInsensitive() assertTrue(headerNames.contains("myHeader2")); } - public void testCookies() + @Test + void testCookies() { assertNull(request.getCookies()); request @@ -379,7 +404,8 @@ public void testCookies() assertEquals("value3", cookies[2].getValue()); } - public void testBodyContent() throws Exception + @Test + void testBodyContent() throws Exception { request.setBodyContent("test\nanothertest???"); BufferedReader reader = request.getReader(); @@ -395,7 +421,8 @@ public void testBodyContent() throws Exception assertEquals(55, stream.read()); } - public void testRequestDispatcher() throws Exception + @Test + void testRequestDispatcher() throws Exception { final String rdPath1 = "rdPathOne"; final String rdPath2 = "rdPathTwo"; @@ -437,7 +464,8 @@ public void testRequestDispatcher() throws Exception assertEquals(0, request.getRequestDispatcherMap().size()); } - public void testSessionCreation() throws Exception + @Test + void testSessionCreation() throws Exception { request.setSession(null); assertNull(request.getSession(false)); @@ -458,7 +486,8 @@ public void testSessionCreation() throws Exception assertNotNull(request.getSession(false)); } - public void testSessionInvalidate() throws Exception + @Test + void testSessionInvalidate() throws Exception { request.setSession(new MockHttpSession()); request.getSession().invalidate(); @@ -466,7 +495,8 @@ public void testSessionInvalidate() throws Exception assertTrue(((MockHttpSession)request.getSession(true)).isValid()); } - public void testIsUserInRole() + @Test + void testIsUserInRole() { request .setUserInRole("role1", true) @@ -476,16 +506,6 @@ public void testIsUserInRole() assertFalse(request.isUserInRole("role3")); } - private int getEnumerationSize(Enumeration enumeration) { - int size = 0; - while(enumeration.hasMoreElements()) { - ++size; - enumeration.nextElement(); - } - - return size; - } - private class TestAttributeListener implements ServletRequestAttributeListener { private boolean wasAttributeAddedCalled = false; private boolean wasAttributeReplacedCalled = false; diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java index 2b509bc00..88588d9e2 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java @@ -1,27 +1,33 @@ package com.mockrunner.test.web; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.IOException; import java.io.PrintWriter; -import java.util.Collection; - import javax.servlet.http.HttpServletResponse; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockHttpServletResponse; import com.mockrunner.mock.web.MockServletOutputStream; -public class MockHttpServletResponseTest extends TestCase +class MockHttpServletResponseTest { private MockHttpServletResponse response; + @BeforeEach protected void setUp() throws Exception { - super.setUp(); response = new MockHttpServletResponse(); } - public void testResetAll() throws Exception + @Test + void testResetAll() throws Exception { response.addHeader("header", "headervalue"); response.sendError(HttpServletResponse.SC_BAD_REQUEST); @@ -32,7 +38,9 @@ public void testResetAll() throws Exception assertFalse(response.wasErrorSent()); } - public void testHeaders() + @SuppressWarnings("unchecked") + @Test + void testHeaders() { response.addHeader("testHeader", "xyz"); response.addHeader("testHeader", "abc"); @@ -51,35 +59,40 @@ public void testHeaders() response.addIntHeader("intHeader", 0); assertEquals("0", response.getHeader("intHeader")); response.clearHeaders(); - Collection headers = response.getHeaderNames(); - assertTrue(headers.isEmpty()); + assertThat(response.getHeaderNames()).isEmpty(); } - public void testGetHeaderNames() + @SuppressWarnings("unchecked") + @Test + void testGetHeaderNames() { response.addHeader("testHeader1", "xyz1"); response.addHeader("testHeader1", "abc"); response.addHeader("testHeader2", "xyz2"); response.addHeader("testHeader3", "xyz3"); - Collection headerNames= response.getHeaderNames(); - assertEquals(3, headerNames.size()); - assertTrue(headerNames.contains("testHeader1")); - assertTrue(headerNames.contains("testHeader2")); - assertTrue(headerNames.contains("testHeader3")); + assertThat(response.getHeaderNames()) + .hasSize(3) + .contains("testHeader1") + .contains("testHeader2") + .contains("testHeader3"); } - public void testGetHeaders() + @SuppressWarnings("unchecked") + @Test + void testGetHeaders() { response.addHeader("testHeader1", "xyz1"); response.addHeader("testHeader1", "abc"); response.addHeader("testHeader2", "xyz2"); - Collection headers = response.getHeaders("testHeader1"); - assertEquals(2, headers.size()); - assertTrue(headers.contains("xyz1")); - assertTrue(headers.contains("abc")); + assertThat(response.getHeaders("testHeader1")) + .hasSize(2) + .contains("xyz1") + .contains("abc"); } - public void testHeadersCaseInsensitive() + @SuppressWarnings("unchecked") + @Test + void testHeadersCaseInsensitive() { response.addHeader("testHeader", "xyz"); response.addHeader("TESTHeader", "abc"); @@ -87,14 +100,15 @@ public void testHeadersCaseInsensitive() response.addHeader("myHeader2", "abc"); assertEquals("xyz", response.getHeader("myheader1")); assertEquals("abc", response.getHeader("MYHEADER2")); - Collection headerNames = response.getHeaderNames(); - assertEquals(3, headerNames.size()); - assertTrue(headerNames.contains("testHeader")); - assertTrue(headerNames.contains("MYHEADER1")); - assertTrue(headerNames.contains("myHeader2")); + assertThat(response.getHeaderNames()) + .hasSize(3) + .contains("testHeader") + .contains("MYHEADER1") + .contains("myHeader2"); } - public void testOutputStreams() throws IOException + @Test + void testOutputStreams() throws IOException { response.getOutputStream().print("test"); response.getWriter().print(true); @@ -104,21 +118,24 @@ public void testOutputStreams() throws IOException assertEquals("testtruetest".getBytes().length, response.getOutputStreamBinaryContent().length); } - public void testGetSetContentType() throws IOException + @Test + void testGetSetContentType() throws IOException { assertNull(response.getContentType()); response.setContentType("myType"); assertEquals("myType", response.getContentType()); } - public void testFlush() throws IOException + @Test + void testFlush() throws IOException { response.getOutputStream().write('a'); response.flushBuffer(); assertEquals("a", ((MockServletOutputStream)response.getOutputStream()).getContent()); } - public void testReset() throws IOException + @Test + void testReset() throws IOException { response.addHeader("testHeader", "xyz"); assertTrue(response.getHeaderList("testHeader").size() == 1); @@ -131,7 +148,8 @@ public void testReset() throws IOException assertNull(response.getHeaderList("testHeader")); } - public void testSetCharacterEncoding() throws IOException + @Test + void testSetCharacterEncoding() throws IOException { response.setCharacterEncoding("ISO-8859-1"); response.getWriter().write("?"); @@ -151,21 +169,24 @@ public void testSetCharacterEncoding() throws IOException assertTrue(output.equals(input)); } - public void testRedirect() throws IOException + @Test + void testRedirect() throws IOException { response.sendRedirect("/some-location"); assertEquals("/some-location", response.getHeader("Location")); assertEquals(HttpServletResponse.SC_FOUND, response.getStatusCode()); } - public void testEncodeRedirectURL() throws IOException { + @Test + void testEncodeRedirectURL() throws IOException { final String encoded1 = response.encodeRedirectURL("page#/some-location?a=b&c=d"); assertEquals("page%23%2Fsome-location%3Fa%3Db%26c%3Dd", encoded1); final String encoded2 = response.encodeRedirectURL("page"); assertEquals("page", encoded2); } - public void testEncodeRedirectUrl() throws IOException { + @Test + void testEncodeRedirectUrl() throws IOException { final String encoded = response.encodeRedirectUrl("page#/some-location?a=b&c=d"); assertEquals("page%23%2Fsome-location%3Fa%3Db%26c%3Dd", encoded); final String encoded2 = response.encodeRedirectUrl("page"); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java index 187f8cd43..040d4bd45 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java @@ -1,5 +1,13 @@ package com.mockrunner.test.web; +import static java.util.Collections.list; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.ArrayList; import java.util.Enumeration; import java.util.List; @@ -9,25 +17,30 @@ import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingListener; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockHttpSession; -public class MockHttpSessionTest extends TestCase +class MockHttpSessionTest { private MockHttpSession session; - protected void setUp() + @BeforeEach + void setUp() { session = new MockHttpSession(); } - protected void tearDown() + @AfterEach + void tearDown() { session = null; } - public void testResetAll() throws Exception + @Test + void testResetAll() throws Exception { session.setAttribute("key", "value"); session.setMaxInactiveInterval(3); @@ -36,7 +49,8 @@ public void testResetAll() throws Exception assertEquals(-1, session.getMaxInactiveInterval()); } - public void testBindingListenerInvalidate() + @Test + void testBindingListenerInvalidate() { TestSessionListener listener1 = new TestSessionListener(); TestSessionListener listener2 = new TestSessionListener(); @@ -64,7 +78,8 @@ public void testBindingListenerInvalidate() } } - public void testBindingListenerOverwriteAttribute() + @Test + void testBindingListenerOverwriteAttribute() { TestSessionListener listener1 = new TestSessionListener(); TestSessionListener listener2 = new TestSessionListener(); @@ -75,7 +90,8 @@ public void testBindingListenerOverwriteAttribute() assertFalse(listener2.wasValueUnboundCalled()); } - public void testBindingListenerOverwriteSameAttribute() + @Test + void testBindingListenerOverwriteSameAttribute() { TestSessionListener listener = new TestSessionListener(); session.setAttribute("key", listener); @@ -86,7 +102,8 @@ public void testBindingListenerOverwriteSameAttribute() assertTrue(listener.wasValueUnboundBeforeBoundCalled()); } - public void testBindingListenerCorrectOrder() + @Test + void testBindingListenerCorrectOrder() { session.setAttribute("key", "test"); TestSessionOrderListener listener = new TestSessionOrderListener(); @@ -108,7 +125,8 @@ public void testBindingListenerCorrectOrder() assertEquals(null, listener.getUnboundSessionValue()); } - public void testAttributeListenerCalled() + @Test + void testAttributeListenerCalled() { TestAttributeListener listener1 = new TestAttributeListener(); TestAttributeListener listener2 = new TestAttributeListener(); @@ -139,7 +157,8 @@ public void testAttributeListenerCalled() assertTrue(listener3.wasAttributeRemovedCalled()); } - public void testAttributeListenerOrder() + @Test + void testAttributeListenerOrder() { TestAttributeOrderListener listener = new TestAttributeOrderListener(); session.addAttributeListener(listener); @@ -154,10 +173,11 @@ public void testAttributeListenerOrder() session.removeAttribute("key"); assertEquals("key", listener.getRemovedEventKey()); assertEquals("anotherValue", listener.getRemovedEventValue()); - assertNull("", listener.getRemovedSessionValue()); + assertNull(listener.getRemovedSessionValue()); } - public void testAttributeListenerNullValue() + @Test + void testAttributeListenerNullValue() { TestAttributeListener listener = new TestAttributeListener(); session.addAttributeListener(listener); @@ -176,24 +196,24 @@ public void testAttributeListenerNullValue() assertFalse(listener.wasAttributeRemovedCalled()); } - public void testGetAttributeNames() + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + void testGetAttributeNames() { - Enumeration enumeration = session.getAttributeNames(); - assertFalse(enumeration.hasMoreElements()); + assertThat(list(session.getAttributeNames())).isEmpty(); session.setAttribute("key", null); - enumeration = session.getAttributeNames(); - assertFalse(enumeration.hasMoreElements()); + assertThat(list(session.getAttributeNames())).isEmpty(); session.setAttribute("key1", "value1"); session.setAttribute("key2", "value2"); assertEquals("value1", session.getAttribute("key1")); assertEquals("value2", session.getAttribute("key2")); - enumeration = session.getAttributeNames(); + Enumeration enumeration = session.getAttributeNames(); List testList = new ArrayList(); testList.add(enumeration.nextElement()); testList.add(enumeration.nextElement()); assertFalse(enumeration.hasMoreElements()); - assertTrue(testList.contains("key1")); - assertTrue(testList.contains("key2")); + assertThat(testList).contains("key1"); + assertThat(testList).contains("key2"); session.setAttribute("key2", null); assertNull(session.getAttribute("key2")); enumeration = session.getAttributeNames(); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java index bbf8db967..60961eb60 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java @@ -1,26 +1,34 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Iterator; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockJspPropertyGroupDescriptor; -public class MockJspPropertyGroupDescriptorTest extends TestCase +class MockJspPropertyGroupDescriptorTest { private MockJspPropertyGroupDescriptor descriptor; - protected void setUp() throws Exception + @BeforeEach + void setUp() throws Exception { descriptor = new MockJspPropertyGroupDescriptor(); } - protected void tearDown() throws Exception + @AfterEach + void tearDown() throws Exception { descriptor = null; } - public void testReset() + @Test + void testReset() { descriptor.addIncludeCoda("coda"); descriptor.addIncludePrelude("prelude"); @@ -61,7 +69,8 @@ public void testReset() assertEquals("false", descriptor.getTrimDirectiveWhitespaces()); } - public void testIncludeAndURLPatterns() + @Test + void testIncludeAndURLPatterns() { assertTrue(descriptor.getIncludeCodas().isEmpty()); assertTrue(descriptor.getIncludePreludes().isEmpty()); @@ -83,7 +92,9 @@ public void testIncludeAndURLPatterns() assertTrue(descriptor.getUrlPatterns().isEmpty()); } - public void testIncludeAndURLPatternsListChange() + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + void testIncludeAndURLPatternsListChange() { descriptor.addIncludeCoda("coda1"); descriptor.addIncludePrelude("prelude1"); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java index 772e0b7ad..e95b1330b 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java @@ -1,16 +1,20 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.IOException; import java.io.StringWriter; +import org.junit.jupiter.api.Test; + import com.mockrunner.mock.web.MockHttpServletResponse; import com.mockrunner.mock.web.MockJspWriter; -import junit.framework.TestCase; - -public class MockJspWriterTest extends TestCase +class MockJspWriterTest { - public void testWithDefaultWriter() throws Exception + @Test + void testWithDefaultWriter() throws Exception { MockJspWriter writer = new MockJspWriter(); writer.print("test1"); @@ -21,7 +25,8 @@ public void testWithDefaultWriter() throws Exception assertEquals("test3", writer.getOutputAsString()); } - public void testWithProvidedWriter() throws Exception + @Test + void testWithProvidedWriter() throws Exception { StringWriter providedWriter = new StringWriter(); MockJspWriter writer = new MockJspWriter(providedWriter); @@ -43,7 +48,8 @@ public void testWithProvidedWriter() throws Exception assertEquals("test1test2test3", providedWriter.toString()); } - public void testWithProvidedResponse() throws Exception + @Test + void testWithProvidedResponse() throws Exception { MockHttpServletResponse response = new MockHttpServletResponse(); MockJspWriter writer = new MockJspWriter(response); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletConfigTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletConfigTest.java index 034410f65..cccc28a21 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletConfigTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletConfigTest.java @@ -1,18 +1,25 @@ package com.mockrunner.test.web; +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.assertTrue; + import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockServletConfig; -public class MockServletConfigTest extends TestCase +class MockServletConfigTest { - public void testInitParameters() + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + void testInitParameters() { MockServletConfig config = new MockServletConfig(); config.setInitParameter("key1", "value1"); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java index 29036e958..6d6574b4c 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java @@ -1,5 +1,11 @@ package com.mockrunner.test.web; +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 static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -19,27 +25,33 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockRequestDispatcher; import com.mockrunner.mock.web.MockServletContext; import com.mockrunner.util.common.StreamUtil; -public class MockServletContextTest extends TestCase +class MockServletContextTest { private MockServletContext context; - protected void setUp() + @BeforeEach + void setUp() { context = new MockServletContext(); } - protected void tearDown() + @AfterEach + void tearDown() { context = null; } - public void testResetAll() throws Exception + @SuppressWarnings({ "rawtypes", "deprecation" }) + @Test + void testResetAll() throws Exception { context.setAttribute("key", "value"); context.addResourcePaths("path", new ArrayList()); @@ -50,7 +62,9 @@ public void testResetAll() throws Exception assertNull(context.getResource("path")); } - public void testResources() throws Exception + @SuppressWarnings({ "deprecation", "rawtypes", "unchecked" }) + @Test + void testResources() throws Exception { context.setResource("testPath", new URL("http://test")); assertEquals(new URL("http://test"), context.getResource("testPath")); @@ -80,7 +94,8 @@ public void testResources() throws Exception assertEquals(-1, stream.read()); } - public void testAttributeListenerCalled() + @Test + void testAttributeListenerCalled() { TestAttributeListener listener1 = new TestAttributeListener(); TestAttributeListener listener2 = new TestAttributeListener(); @@ -111,7 +126,8 @@ public void testAttributeListenerCalled() assertTrue(listener3.wasAttributeRemovedCalled()); } - public void testAttributeListenerValues() + @Test + void testAttributeListenerValues() { TestAttributeOrderListener listener = new TestAttributeOrderListener(); context.addAttributeListener(listener); @@ -126,7 +142,8 @@ public void testAttributeListenerValues() assertEquals("anotherValue", listener.getRemovedEventValue()); } - public void testAttributeListenerNullValue() + @Test + void testAttributeListenerNullValue() { TestAttributeListener listener = new TestAttributeListener(); context.addAttributeListener(listener); @@ -145,7 +162,9 @@ public void testAttributeListenerNullValue() assertFalse(listener.wasAttributeRemovedCalled()); } - public void testGetAttributeNames() + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + void testGetAttributeNames() { Enumeration enumeration = context.getAttributeNames(); assertFalse(enumeration.hasMoreElements()); @@ -176,7 +195,8 @@ public void testGetAttributeNames() assertFalse(enumeration.hasMoreElements()); } - public void testRequestDispatcher() throws Exception + @Test + void testRequestDispatcher() throws Exception { final String rdPath1 = "rdPathOne"; final String rdPath2 = "rdPathTwo"; @@ -225,7 +245,8 @@ public void testRequestDispatcher() throws Exception assertEquals(0, context.getRequestDispatcherMap().size()); } - public void testSetResourceAsStream() throws Exception + @Test + void testSetResourceAsStream() throws Exception { byte[] input = {1, 2, 3, 4}; context.setResourceAsStream("testpath1", input); @@ -236,7 +257,8 @@ public void testSetResourceAsStream() throws Exception assertTrue(StreamUtil.compareStreams(new ByteArrayInputStream(input), result)); } - public void testGetContext() throws Exception + @Test + void testGetContext() throws Exception { assertNull(context.getContext("abc")); context.setContext("abc", context); @@ -246,7 +268,9 @@ public void testGetContext() throws Exception assertSame(anotherContext, context.getContext("xyz")); } - public void testInitParameters() + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + void testInitParameters() { context.setInitParameter("key1", "value1"); Map parameters = new HashMap(); @@ -271,7 +295,9 @@ public void testInitParameters() assertFalse(params.hasMoreElements()); } - public void testInitParametersOverwrite() + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + void testInitParametersOverwrite() { assertTrue(context.setInitParameter("key1", "value1")); assertEquals("value1", context.getInitParameter("key1")); @@ -283,7 +309,8 @@ public void testInitParametersOverwrite() assertEquals("value2", context.getInitParameter("key1")); } - public void testVersion() + @Test + void testVersion() { context.setMajorVersion(5); context.setMinorVersion(1); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java index a27e909ef..37aeb0445 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java @@ -1,24 +1,32 @@ package com.mockrunner.test.web; -import com.mockrunner.mock.web.MockVariableResolver; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import com.mockrunner.mock.web.MockVariableResolver; -public class MockVariableResolverTest extends TestCase +class MockVariableResolverTest { private MockVariableResolver resolver; - protected void setUp() throws Exception + @BeforeEach + void setUp() throws Exception { resolver = new MockVariableResolver(); } - protected void tearDown() throws Exception + @AfterEach + void tearDown() throws Exception { resolver = null; } - public void testResolve() throws Exception + @Test + void testResolve() throws Exception { assertNull(resolver.resolveVariable("test")); resolver.addVariable("test", 3); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java index 785b22dc9..b9963daa2 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java @@ -1,5 +1,11 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + import javax.servlet.Servlet; import javax.servlet.ServletContext; import javax.servlet.ServletRequest; @@ -13,6 +19,8 @@ import javax.servlet.jsp.JspFactory; import javax.servlet.jsp.PageContext; +import org.junit.jupiter.api.Test; + import com.mockrunner.mock.web.MockFilterChain; import com.mockrunner.mock.web.MockFilterConfig; import com.mockrunner.mock.web.MockHttpServletRequest; @@ -24,11 +32,10 @@ import com.mockrunner.mock.web.MockServletContext; import com.mockrunner.mock.web.WebMockObjectFactory; -import junit.framework.TestCase; - -public class WebMockObjectFactoryTest extends TestCase +class WebMockObjectFactoryTest { - public void testDifferentMockObjects() + @Test + void testDifferentMockObjects() { WebMockObjectFactory factory1 = new WebMockObjectFactory(); WebMockObjectFactory factory2 = new WebMockObjectFactory(); @@ -39,7 +46,8 @@ public void testDifferentMockObjects() assertNotSame(factory1.getMockServletContext(), factory2.getMockServletContext()); } - public void testMockObjectsWithSameContext() + @Test + void testMockObjectsWithSameContext() { WebMockObjectFactory factory1 = new WebMockObjectFactory(); WebMockObjectFactory factory2 = new WebMockObjectFactory(factory1); @@ -50,7 +58,8 @@ public void testMockObjectsWithSameContext() assertSame(factory1.getMockServletContext(), factory2.getMockServletContext()); } - public void testMockObjectsWithSameSessionAndContext() + @Test + void testMockObjectsWithSameSessionAndContext() { WebMockObjectFactory factory1 = new WebMockObjectFactory(); WebMockObjectFactory factory2 = new WebMockObjectFactory(factory1, false); @@ -67,7 +76,8 @@ public void testMockObjectsWithSameSessionAndContext() assertSame(factory1.getMockServletContext(), factory2.getMockServletContext()); } - public void testSetDefaultJspFactory() + @Test + void testSetDefaultJspFactory() { WebMockObjectFactory factory = new WebMockObjectFactory(); assertSame(factory.getMockJspFactory(), JspFactory.getDefaultFactory()); @@ -89,7 +99,8 @@ public void testSetDefaultJspFactory() assertNull(factory.getJspFactory()); } - public void testAddRequestWrapper() + @Test + void testAddRequestWrapper() { WebMockObjectFactory factory = new WebMockObjectFactory(); factory.getMockRequest().setupAddParameter("test", "test"); @@ -101,7 +112,8 @@ public void testAddRequestWrapper() assertSame(factory.getMockRequest(), requestWrapper.getRequest()); } - public void testAddResponseWrapper() throws Exception + @Test + void testAddResponseWrapper() throws Exception { WebMockObjectFactory factory = new WebMockObjectFactory(); factory.addResponseWrapper(HttpServletResponseWrapper.class); @@ -114,7 +126,8 @@ public void testAddResponseWrapper() throws Exception assertSame(factory.getMockResponse(), responseWrapper.getResponse()); } - public void testAddRequestAndResponseWrapperClasses() + @Test + void testAddRequestAndResponseWrapperClasses() { WebMockObjectFactory factory = new WebMockObjectFactory(); factory.addRequestWrapper(TestRequestWrapper.class); @@ -125,7 +138,8 @@ public void testAddRequestAndResponseWrapperClasses() assertSame(factory.getMockResponse(), ((TestResponseWrapper)factory.getWrappedResponse()).getResponse()); } - public void testRefresh() throws Exception + @Test + void testRefresh() throws Exception { WebMockObjectFactory factory = new WebMockObjectFactory(); HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(factory.getMockRequest()); @@ -142,7 +156,8 @@ public void testRefresh() throws Exception assertSame(pageContext, factory.getMockJspFactory().getPageContext()); } - public void testOverrideCreate() + @Test + void testOverrideCreate() { WebMockObjectFactory factory = new TestWebMockObjectFactory(); assertNotSame(factory.getMockRequest().getClass(), MockHttpServletRequest.class); From 1013f2ce052755cc1545222e085d688655f89054 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Mon, 25 May 2026 09:29:58 +0200 Subject: [PATCH 36/40] Use editorconfig formatting of example tests inheriting BasicServletTestCaseAdapter --- .../example/servlet/ImageButtonFilterTest.java | 4 ++-- .../example/servlet/LogoutServletTest.java | 12 ++++++------ .../example/servlet/RedirectServletTest.java | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java index 46e03043a..052cb4cf7 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java @@ -13,13 +13,13 @@ /** * Example test for the {@link ImageButtonFilter}. * Demonstrates the usage of the filter test features in - * {@link com.mockrunner.servlet.ServletTestModule} + * {@link com.mockrunner.servlet.ServletTestModule} * and {@link com.mockrunner.servlet.BasicServletTestCaseAdapter}. */ public class ImageButtonFilterTest extends BasicServletTestCaseAdapter { private ImageButtonFilter filter; - + @Before public void setUp() throws Exception { diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java index f567422d1..842d2fff0 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java @@ -14,28 +14,28 @@ /** * Example test for {@link LogoutServlet}. - * Demonstrates the usage of {@link com.mockrunner.servlet.ServletTestModule} + * Demonstrates the usage of {@link com.mockrunner.servlet.ServletTestModule} * and {@link com.mockrunner.servlet.BasicServletTestCaseAdapter} * with and without a filter. */ public class LogoutServletTest extends BasicServletTestCaseAdapter { - @Before + @Before public void setUp() throws Exception { super.setUp(); createServlet(LogoutServlet.class); } - - @Test + + @Test public void testDoLogout() throws Exception { addRequestParameter("logout", "true"); doPost(); assertFalse(getWebMockObjectFactory().getMockSession().isValid()); } - - @Test + + @Test public void testDoLogoutWithFilteredImageButton() throws Exception { addRequestParameter("logout.x", "11"); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java index 1d5f69ecb..42c4cbd09 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java @@ -12,22 +12,22 @@ /** * Example test for {@link RedirectServlet}. - * Demonstrates the usage of {@link com.mockrunner.servlet.ServletTestModule} + * Demonstrates the usage of {@link com.mockrunner.servlet.ServletTestModule} * and {@link com.mockrunner.servlet.BasicServletTestCaseAdapter}. * Demonstrates the testing of output data as string as well as parsed * HTML data (testServletOutputAsXML). - * + * */ public class RedirectServletTest extends BasicServletTestCaseAdapter { - @Before + @Before public void setUp() throws Exception { super.setUp(); createServlet(RedirectServlet.class); } - - @Test + + @Test public void testServletOutput() throws Exception { addRequestParameter("redirecturl", "http://www.mockrunner.com"); @@ -43,8 +43,8 @@ public void testServletOutput() throws Exception assertEquals("", reader.readLine().trim()); verifyOutputContains("URL=http://www.mockrunner.com"); } - - @Test + + @Test public void testServletOutputAsXML() throws Exception { addRequestParameter("redirecturl", "http://www.mockrunner.com"); From e2f075611b00fd13f14b14cacb04e29db190f5e6 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Mon, 25 May 2026 09:32:05 +0200 Subject: [PATCH 37/40] Change example tests inheriting BasicServletTestCaseAdapter from JUnit 4 to JUnit jupiter --- .../mockrunner/example/servlet/ImageButtonFilterTest.java | 6 +++--- .../com/mockrunner/example/servlet/LogoutServletTest.java | 6 +++--- .../com/mockrunner/example/servlet/RedirectServletTest.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java index 052cb4cf7..2b7d24ad1 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java @@ -5,8 +5,8 @@ import javax.servlet.http.HttpServletRequest; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.servlet.BasicServletTestCaseAdapter; @@ -20,7 +20,7 @@ public class ImageButtonFilterTest extends BasicServletTestCaseAdapter { private ImageButtonFilter filter; - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java index 842d2fff0..7326721d3 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java @@ -7,8 +7,8 @@ import javax.servlet.http.HttpServletRequest; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.servlet.BasicServletTestCaseAdapter; @@ -20,7 +20,7 @@ */ public class LogoutServletTest extends BasicServletTestCaseAdapter { - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java index 42c4cbd09..1e6b88fc8 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java @@ -5,8 +5,8 @@ import java.io.BufferedReader; import org.jdom2.Element; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.servlet.BasicServletTestCaseAdapter; @@ -20,7 +20,7 @@ */ public class RedirectServletTest extends BasicServletTestCaseAdapter { - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); From e21629283f2b349082b0ec3cffb1c5f87f59a7f6 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Mon, 25 May 2026 09:35:59 +0200 Subject: [PATCH 38/40] Remove unused field in ImageButtonFieldTest --- .../com/mockrunner/example/servlet/ImageButtonFilterTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java index 2b7d24ad1..9138a0966 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java @@ -18,13 +18,11 @@ */ public class ImageButtonFilterTest extends BasicServletTestCaseAdapter { - private ImageButtonFilter filter; - @BeforeEach public void setUp() throws Exception { super.setUp(); - filter = createFilter(ImageButtonFilter.class); + createFilter(ImageButtonFilter.class); } @Test From e690c0a1770e68177e5ca2edce783f564436551c Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Mon, 25 May 2026 09:38:34 +0200 Subject: [PATCH 39/40] Use try-with-resource to remove warning about leaked resources --- .../test/web/MockJspWriterTest.java | 73 ++++++++++--------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java index e95b1330b..209089591 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java @@ -16,35 +16,37 @@ class MockJspWriterTest @Test void testWithDefaultWriter() throws Exception { - MockJspWriter writer = new MockJspWriter(); - writer.print("test1"); - writer.clear(); - writer.print("test2"); - writer.clearBuffer(); - writer.print("test3"); - assertEquals("test3", writer.getOutputAsString()); + try (MockJspWriter writer = new MockJspWriter()) { + writer.print("test1"); + writer.clear(); + writer.print("test2"); + writer.clearBuffer(); + writer.print("test3"); + assertEquals("test3", writer.getOutputAsString()); + } } @Test void testWithProvidedWriter() throws Exception { StringWriter providedWriter = new StringWriter(); - MockJspWriter writer = new MockJspWriter(providedWriter); - writer.print("test1"); - try - { - writer.clear(); - fail(); - } - catch(IOException exc) - { - //should throw exception + try (MockJspWriter writer = new MockJspWriter(providedWriter)) { + writer.print("test1"); + try + { + writer.clear(); + fail(); + } + catch(IOException exc) + { + //should throw exception + } + writer.print("test2"); + writer.clearBuffer(); + writer.print("test3"); + assertEquals("", writer.getOutputAsString()); + writer.flush(); } - writer.print("test2"); - writer.clearBuffer(); - writer.print("test3"); - assertEquals("", writer.getOutputAsString()); - writer.flush(); assertEquals("test1test2test3", providedWriter.toString()); } @@ -52,19 +54,20 @@ void testWithProvidedWriter() throws Exception void testWithProvidedResponse() throws Exception { MockHttpServletResponse response = new MockHttpServletResponse(); - MockJspWriter writer = new MockJspWriter(response); - writer.print("test1"); - assertEquals("test1", writer.getOutputAsString()); - assertEquals("test1", response.getOutputStreamContent()); - response.getWriter().print("test2"); - assertEquals("test1test2", writer.getOutputAsString()); - assertEquals("test1test2", response.getOutputStreamContent()); - writer.clear(); - assertEquals("", writer.getOutputAsString()); - assertEquals("", response.getOutputStreamContent()); - writer.print("test1"); - writer.clearBuffer(); - assertEquals("", writer.getOutputAsString()); + try (MockJspWriter writer = new MockJspWriter(response)) { + writer.print("test1"); + assertEquals("test1", writer.getOutputAsString()); + assertEquals("test1", response.getOutputStreamContent()); + response.getWriter().print("test2"); + assertEquals("test1test2", writer.getOutputAsString()); + assertEquals("test1test2", response.getOutputStreamContent()); + writer.clear(); + assertEquals("", writer.getOutputAsString()); + assertEquals("", response.getOutputStreamContent()); + writer.print("test1"); + writer.clearBuffer(); + assertEquals("", writer.getOutputAsString()); + } assertEquals("", response.getOutputStreamContent()); } } From 86517ca1ef234417b4613b7b62ef8387daec3755 Mon Sep 17 00:00:00 2001 From: Steinar Bang Date: Mon, 25 May 2026 09:40:26 +0200 Subject: [PATCH 40/40] Add generated serial version UID to JSP test tags --- .../src/test/java/com/mockrunner/test/web/ExceptionTestTag.java | 1 + .../src/test/java/com/mockrunner/test/web/TestBodyTag.java | 1 + .../src/test/java/com/mockrunner/test/web/TestFragmentTag.java | 1 + .../src/test/java/com/mockrunner/test/web/TestTag.java | 1 + 4 files changed, 4 insertions(+) diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java index 0145a1b79..5b4c6b9bc 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java @@ -4,6 +4,7 @@ public class ExceptionTestTag extends TestBodyTag implements TryCatchFinally { + private static final long serialVersionUID = -5883246210258932478L; private boolean doCatchCalled = false; private boolean doFinallyCalled = false; private Throwable caughtException = null; diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java index 99ed6bebd..5d7a2f953 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java @@ -10,6 +10,7 @@ public class TestBodyTag extends BodyTagSupport { + private static final long serialVersionUID = 6856704428326055577L; private String testString; private Integer testInteger; private double testDouble; diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java index 58d710c09..d36efa5c1 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java @@ -9,6 +9,7 @@ public class TestFragmentTag extends TagSupport { + private static final long serialVersionUID = -423825397076113310L; private JspFragment testFragment; public void setTestFragment(JspFragment testFragment) diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java index fd3d30425..7019f0aad 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java @@ -9,6 +9,7 @@ public class TestTag extends TagSupport { + private static final long serialVersionUID = -6184401531349252629L; private String testString; private Integer testInteger; private double testDouble;