- upgrade junit4 with junit5 in wicket-util - replace Junit4 Methods in WicketTester.java - remove junit 4 dependencies in pom.xml
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/51725af8 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/51725af8 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/51725af8 Branch: refs/heads/WICKET-6563 Commit: 51725af8cf2d566e9fe69f76152cfc36ce222c71 Parents: 0b48f27 Author: renoth <johannes.ren...@gmx.de> Authored: Tue Jul 31 12:32:49 2018 +0200 Committer: Martin Tzvetanov Grigorov <mgrigo...@apache.org> Committed: Wed Sep 26 15:51:32 2018 +0300 ---------------------------------------------------------------------- .../apache/wicket/util/tester/WicketTester.java | 135 ++++---- wicket-util/pom.xml | 6 + .../license/AbstractLicenseHeaderHandler.java | 17 +- .../license/ApacheLicenseHeaderTestCase.java | 12 +- .../util/license/CssLicenseHeaderHandler.java | 3 +- .../util/license/JavaLicenseHeaderHandler.java | 5 +- .../license/PropertiesLicenseHeaderHandler.java | 9 +- .../license/VelocityLicenseHeaderHandler.java | 9 +- .../util/license/XmlLicenseHeaderHandler.java | 14 +- .../util/license/XmlPrologHeaderHandler.java | 118 +++---- .../markup/xhtml/WellFormedXmlTestCase.java | 325 +++++++++---------- .../wicket/util/collections/IntHashMapTest.java | 3 +- 12 files changed, 336 insertions(+), 320 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java index dc352b6..e4e08df 100644 --- a/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java +++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/WicketTester.java @@ -51,6 +51,7 @@ import org.apache.wicket.protocol.http.WebApplication; import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.util.lang.Args; import org.apache.wicket.util.lang.Objects; +import org.opentest4j.AssertionFailedError; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -283,13 +284,15 @@ public class WicketTester extends BaseWicketTester { if (null != getLastResponse().getHeader("Location")) { - fail("Location header should *not* be present when using Ajax"); + throw new AssertionFailedError( + "Location header should *not* be present when using Ajax"); } String ajaxLocation = getLastResponse().getHeader("Ajax-Location"); if (null == ajaxLocation) { - fail("Ajax-Location header should be present when using Ajax"); + throw new AssertionFailedError( + "Ajax-Location header should be present when using Ajax"); } int statusCode = getLastResponse().getStatus(); @@ -313,6 +316,18 @@ public class WicketTester extends BaseWicketTester } /** + * + * @param result + */ + private void assertResult(Result result) + { + if (result.wasFailed()) + { + throw new AssertionFailedError(result.getMessage()); + } + } + + /** * Asserts that the <code>Component</code> a the given path has a behavior of the given type. * * @param path @@ -340,13 +355,13 @@ public class WicketTester extends BaseWicketTester * tree, using JavaScript. But it shouldn't be needed because you just have to trust that Wicket * Ajax JavaScript works. * - * @param component - * a <code>Component</code> to be tested + * @param componentPath + * a <code>Component</code> path to test */ - public void assertComponentOnAjaxResponse(Component component) + public void assertComponentOnAjaxResponse(String componentPath) { - Result result = isComponentOnAjaxResponse(component); - assertResult(result); + Component component = getComponentFromLastRenderedPage(componentPath, false); + assertComponentOnAjaxResponse(component); } /** @@ -358,13 +373,13 @@ public class WicketTester extends BaseWicketTester * tree, using JavaScript. But it shouldn't be needed because you just have to trust that Wicket * Ajax JavaScript works. * - * @param componentPath - * a <code>Component</code> path to test + * @param component + * a <code>Component</code> to be tested */ - public void assertComponentOnAjaxResponse(String componentPath) + public void assertComponentOnAjaxResponse(Component component) { - Component component = getComponentFromLastRenderedPage(componentPath, false); - assertComponentOnAjaxResponse(component); + Result result = isComponentOnAjaxResponse(component); + assertResult(result); } /** @@ -413,6 +428,28 @@ public class WicketTester extends BaseWicketTester assertResult(result); } + private IMarkupFragment getMarkupFragment(Component component) + { + IMarkupFragment markup = null; + if (component instanceof MarkupContainer) + { + markup = ((MarkupContainer)component).getAssociatedMarkup(); + } + + if (markup == null) + { + markup = component.getMarkup(); + } + + if (markup == null) + { + throw new AssertionFailedError(String.format("Cannot find the markup of component: %s", + component.getPageRelativePath())); + } + + return markup; + } + /** * Asserts that a component's markup has loaded with the given style. * @@ -462,28 +499,6 @@ public class WicketTester extends BaseWicketTester assertResult(result); } - private IMarkupFragment getMarkupFragment(Component component) - { - IMarkupFragment markup = null; - if (component instanceof MarkupContainer) - { - markup = ((MarkupContainer)component).getAssociatedMarkup(); - } - - if (markup == null) - { - markup = component.getMarkup(); - } - - if (markup == null) - { - fail(String.format("Cannot find the markup of component: %s", - component.getPageRelativePath())); - } - - return markup; - } - /** * Asserts error-level feedback messages. * @@ -683,19 +698,30 @@ public class WicketTester extends BaseWicketTester } /** - * Asserts no error-level feedback messages. + * Asserts last-rendered <code>Page</code> against an expected HTML document. + * <p> + * Use <code>-Dwicket.replace.expected.results=true</code> to automatically replace the expected + * output file. + * + * @param clazz + * <code>Class</code> used to load the file (relative to <code>clazz</code> package) + * @param filename + * expected output filename <code>String</code> + * @throws Exception */ - public void assertNoErrorMessage() + @Override + public void assertResultPage(final Class<?> clazz, final String filename) throws Exception { - assertNoFeedbackMessage(FeedbackMessage.ERROR); + String document = getLastResponseAsString(); + DiffUtil.validatePage(document, clazz, filename, true); } /** - * Asserts no info-level feedback messages. + * Asserts no error-level feedback messages. */ - public void assertNoInfoMessage() + public void assertNoErrorMessage() { - assertNoFeedbackMessage(FeedbackMessage.INFO); + assertNoFeedbackMessage(FeedbackMessage.ERROR); } /** @@ -722,22 +748,11 @@ public class WicketTester extends BaseWicketTester } /** - * Asserts last-rendered <code>Page</code> against an expected HTML document. - * <p> - * Use <code>-Dwicket.replace.expected.results=true</code> to automatically replace the expected - * output file. - * - * @param clazz - * <code>Class</code> used to load the file (relative to <code>clazz</code> package) - * @param filename - * expected output filename <code>String</code> - * @throws Exception + * Asserts no info-level feedback messages. */ - @Override - public void assertResultPage(final Class<?> clazz, final String filename) throws Exception + public void assertNoInfoMessage() { - String document = getLastResponseAsString(); - DiffUtil.validatePage(document, clazz, filename, true); + assertNoFeedbackMessage(FeedbackMessage.INFO); } /** @@ -810,18 +825,6 @@ public class WicketTester extends BaseWicketTester } /** - * - * @param result - */ - private void assertResult(Result result) - { - if (result.wasFailed()) - { - fail(result.getMessage()); - } - } - - /** * Checks whether a component is visible and/or enabled before usage * * @param component http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-util/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-util/pom.xml b/wicket-util/pom.xml index d5777f8..6f71806 100755 --- a/wicket-util/pom.xml +++ b/wicket-util/pom.xml @@ -44,5 +44,11 @@ <groupId>org.apache.commons</groupId> <artifactId>commons-collections4</artifactId> </dependency> + <dependency> + <groupId>org.opentest4j</groupId> + <artifactId>opentest4j</artifactId> + <version>RELEASE</version> + <scope>compile</scope> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-util/src/main/java/org/apache/wicket/util/license/AbstractLicenseHeaderHandler.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/license/AbstractLicenseHeaderHandler.java b/wicket-util/src/main/java/org/apache/wicket/util/license/AbstractLicenseHeaderHandler.java index c6e5685..cbbc934 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/license/AbstractLicenseHeaderHandler.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/license/AbstractLicenseHeaderHandler.java @@ -16,17 +16,12 @@ */ package org.apache.wicket.util.license; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.LineNumberReader; +import java.io.*; import java.util.List; import org.apache.wicket.util.io.IOUtils; import org.apache.wicket.util.string.Strings; - +import org.opentest4j.AssertionFailedError; abstract class AbstractLicenseHeaderHandler implements ILicenseHeaderHandler { @@ -81,7 +76,7 @@ abstract class AbstractLicenseHeaderHandler implements ILicenseHeaderHandler } catch (Exception e) { - throw new AssertionError(e.getMessage()); + throw new AssertionFailedError(e.getMessage()); } finally { @@ -91,7 +86,7 @@ abstract class AbstractLicenseHeaderHandler implements ILicenseHeaderHandler } catch (IOException e) { - throw new AssertionError(e.getMessage()); + throw new AssertionFailedError(e.getMessage()); } } @@ -115,7 +110,7 @@ abstract class AbstractLicenseHeaderHandler implements ILicenseHeaderHandler } catch (Exception e) { - throw new AssertionError(e.getMessage()); + throw new AssertionFailedError(e.getMessage()); } } @@ -147,7 +142,7 @@ abstract class AbstractLicenseHeaderHandler implements ILicenseHeaderHandler } catch (Exception e) { - throw new AssertionError(e.getMessage()); + throw new AssertionFailedError(e.getMessage()); } finally { http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-util/src/main/java/org/apache/wicket/util/license/ApacheLicenseHeaderTestCase.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/license/ApacheLicenseHeaderTestCase.java b/wicket-util/src/main/java/org/apache/wicket/util/license/ApacheLicenseHeaderTestCase.java index d03f8ad..4c88b1b 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/license/ApacheLicenseHeaderTestCase.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/license/ApacheLicenseHeaderTestCase.java @@ -16,6 +16,14 @@ */ package org.apache.wicket.util.license; +import org.apache.wicket.util.lang.Generics; +import org.apache.wicket.util.string.Strings; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.opentest4j.AssertionFailedError; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.File; import java.io.FileFilter; import java.util.ArrayList; @@ -96,7 +104,7 @@ public abstract class ApacheLicenseHeaderTestCase * */ @BeforeEach - final void before() + public final void before() { // setup the base directory for when running inside maven (building a release // comes to mind). @@ -186,7 +194,7 @@ public abstract class ApacheLicenseHeaderTestCase } System.out.println(failString); - throw new AssertionError(failString.toString()); + throw new AssertionFailedError(failString.toString()); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-util/src/main/java/org/apache/wicket/util/license/CssLicenseHeaderHandler.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/license/CssLicenseHeaderHandler.java b/wicket-util/src/main/java/org/apache/wicket/util/license/CssLicenseHeaderHandler.java index 2797d8a..7652e10 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/license/CssLicenseHeaderHandler.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/license/CssLicenseHeaderHandler.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.wicket.util.diff.Diff; import org.apache.wicket.util.diff.Revision; +import org.opentest4j.AssertionFailedError; class CssLicenseHeaderHandler extends AbstractLicenseHeaderHandler @@ -55,7 +56,7 @@ class CssLicenseHeaderHandler extends AbstractLicenseHeaderHandler } catch (Exception e) { - throw new AssertionError(e.getMessage()); + throw new AssertionFailedError(e.getMessage()); } return revision.size() == 0; http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-util/src/main/java/org/apache/wicket/util/license/JavaLicenseHeaderHandler.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/license/JavaLicenseHeaderHandler.java b/wicket-util/src/main/java/org/apache/wicket/util/license/JavaLicenseHeaderHandler.java index 3165ebc..d38c008 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/license/JavaLicenseHeaderHandler.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/license/JavaLicenseHeaderHandler.java @@ -23,6 +23,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.wicket.util.string.Strings; +import org.opentest4j.AssertionFailedError; class JavaLicenseHeaderHandler extends AbstractLicenseHeaderHandler { @@ -63,13 +64,13 @@ class JavaLicenseHeaderHandler extends AbstractLicenseHeaderHandler } else { - throw new AssertionError(); + throw new AssertionFailedError(); } } catch (Exception e) { e.printStackTrace(); - throw new AssertionError(e.getMessage()); + throw new AssertionFailedError(e.getMessage()); } return added; http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-util/src/main/java/org/apache/wicket/util/license/PropertiesLicenseHeaderHandler.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/license/PropertiesLicenseHeaderHandler.java b/wicket-util/src/main/java/org/apache/wicket/util/license/PropertiesLicenseHeaderHandler.java index 3da2788..4a0447d 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/license/PropertiesLicenseHeaderHandler.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/license/PropertiesLicenseHeaderHandler.java @@ -16,13 +16,14 @@ */ package org.apache.wicket.util.license; +import org.apache.wicket.util.diff.Diff; +import org.apache.wicket.util.diff.Revision; +import org.opentest4j.AssertionFailedError; + import java.io.File; import java.util.Arrays; import java.util.List; -import org.apache.wicket.util.diff.Diff; -import org.apache.wicket.util.diff.Revision; - class PropertiesLicenseHeaderHandler extends AbstractLicenseHeaderHandler { /** @@ -54,7 +55,7 @@ class PropertiesLicenseHeaderHandler extends AbstractLicenseHeaderHandler } catch (Exception e) { - throw new AssertionError(e.getMessage()); + throw new AssertionFailedError(e.getMessage()); } return revision.size() == 0; http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-util/src/main/java/org/apache/wicket/util/license/VelocityLicenseHeaderHandler.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/license/VelocityLicenseHeaderHandler.java b/wicket-util/src/main/java/org/apache/wicket/util/license/VelocityLicenseHeaderHandler.java index 54fd6a6..2d1286b 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/license/VelocityLicenseHeaderHandler.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/license/VelocityLicenseHeaderHandler.java @@ -16,13 +16,14 @@ */ package org.apache.wicket.util.license; +import org.apache.wicket.util.diff.Diff; +import org.apache.wicket.util.diff.Revision; +import org.opentest4j.AssertionFailedError; + import java.io.File; import java.util.Arrays; import java.util.List; -import org.apache.wicket.util.diff.Diff; -import org.apache.wicket.util.diff.Revision; - class VelocityLicenseHeaderHandler extends AbstractLicenseHeaderHandler { /** @@ -54,7 +55,7 @@ class VelocityLicenseHeaderHandler extends AbstractLicenseHeaderHandler } catch (Exception e) { - throw new AssertionError(e.getMessage()); + throw new AssertionFailedError(e.getMessage()); } return revision.size() == 0; http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-util/src/main/java/org/apache/wicket/util/license/XmlLicenseHeaderHandler.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/license/XmlLicenseHeaderHandler.java b/wicket-util/src/main/java/org/apache/wicket/util/license/XmlLicenseHeaderHandler.java index 822cd65..e8b1ad2 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/license/XmlLicenseHeaderHandler.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/license/XmlLicenseHeaderHandler.java @@ -16,16 +16,17 @@ */ package org.apache.wicket.util.license; +import org.apache.wicket.util.diff.Diff; +import org.apache.wicket.util.diff.Revision; +import org.apache.wicket.util.string.Strings; +import org.opentest4j.AssertionFailedError; + import java.io.File; import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.wicket.util.diff.Diff; -import org.apache.wicket.util.diff.Revision; -import org.apache.wicket.util.string.Strings; - class XmlLicenseHeaderHandler extends AbstractLicenseHeaderHandler { private final Pattern xmlHeader = Pattern.compile( @@ -81,8 +82,7 @@ class XmlLicenseHeaderHandler extends AbstractLicenseHeaderHandler } catch (Exception e) { - e.printStackTrace(); - throw new AssertionError(e.getMessage()); + throw new AssertionFailedError(e.getMessage()); } return revision.size() == 0; @@ -125,7 +125,7 @@ class XmlLicenseHeaderHandler extends AbstractLicenseHeaderHandler } catch (Exception e) { - throw new AssertionError(e.getMessage()); + throw new AssertionFailedError(e.getMessage()); } return added; http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-util/src/main/java/org/apache/wicket/util/license/XmlPrologHeaderHandler.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/license/XmlPrologHeaderHandler.java b/wicket-util/src/main/java/org/apache/wicket/util/license/XmlPrologHeaderHandler.java index 3206165..ab5a73e 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/license/XmlPrologHeaderHandler.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/license/XmlPrologHeaderHandler.java @@ -1,59 +1,59 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.util.license; - - - -import java.io.File; -import java.util.Arrays; -import java.util.List; - -class XmlPrologHeaderHandler extends XmlLicenseHeaderHandler -{ - /** - * Construct. - * - * @param ignoreFiles - */ - public XmlPrologHeaderHandler(final List<String> ignoreFiles) - { - super(ignoreFiles); - } - - /** - * @see org.apache.wicket.util.license.XmlLicenseHeaderHandler#checkLicenseHeader(java.io.File) - */ - @Override - public boolean checkLicenseHeader(final File file) - { - try - { - String header = extractLicenseHeader(file, 0, 1); - return header.startsWith("<?xml"); - } - catch (Exception e) - { - throw new AssertionError(e.getMessage()); - } - } - - @Override - public List<String> getSuffixes() - { - return Arrays.asList("html"); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.util.license; + +import org.opentest4j.AssertionFailedError; + +import java.io.File; +import java.util.Arrays; +import java.util.List; + +class XmlPrologHeaderHandler extends XmlLicenseHeaderHandler +{ + /** + * Construct. + * + * @param ignoreFiles + */ + public XmlPrologHeaderHandler(final List<String> ignoreFiles) + { + super(ignoreFiles); + } + + /** + * @see org.apache.wicket.util.license.XmlLicenseHeaderHandler#checkLicenseHeader(java.io.File) + */ + @Override + public boolean checkLicenseHeader(final File file) + { + try + { + String header = extractLicenseHeader(file, 0, 1); + return header.startsWith("<?xml"); + } + catch (Exception e) + { + throw new AssertionFailedError(e.getMessage()); + } + } + + @Override + public List<String> getSuffixes() + { + return Arrays.asList("html"); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-util/src/main/java/org/apache/wicket/util/markup/xhtml/WellFormedXmlTestCase.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/markup/xhtml/WellFormedXmlTestCase.java b/wicket-util/src/main/java/org/apache/wicket/util/markup/xhtml/WellFormedXmlTestCase.java index 1ad3a27..71f8357 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/markup/xhtml/WellFormedXmlTestCase.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/markup/xhtml/WellFormedXmlTestCase.java @@ -1,163 +1,162 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.util.markup.xhtml; - -import org.junit.jupiter.api.Test; -import org.xml.sax.*; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.File; -import java.io.FileFilter; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -/** - * Usable by tests to check that the html markup files are well formed. - * - * @author akiraly - */ -public class WellFormedXmlTestCase -{ - private DocumentBuilderFactory factory; - - /** - * Checks xml well formedness of html markup files under the current working directory. - */ - @Test - public void markupFiles() - { - factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - - File root = new File("").getAbsoluteFile(); - processDirectory(root); - } - - private void processDirectory(File dir) - { - for (File f : dir.listFiles(fileFilter)) - { - if (f.isDirectory()) - { - processDirectory(f); - } - else - { - processFile(f); - } - } - } - - private void processFile(File file) - { - DocumentBuilder builder; - - try - { - builder = factory.newDocumentBuilder(); - } - catch (ParserConfigurationException e) - { - throw new RuntimeException("Configuration exception while parsing xml markup.", e); - } - - builder.setEntityResolver(entityResolver); - builder.setErrorHandler(errorHandler); - - try - { - builder.parse(file); - } - catch (SAXException e) - { - throw new RuntimeException("Parsing xml sax failed, file: " + file, e); - } - catch (IOException e) - { - throw new RuntimeException("Parsing xml io failed, file: " + file, e); - } - } - - private static final FileFilter fileFilter = new FileFilter() - { - @Override - public boolean accept(File pathname) - { - String path = pathname.getAbsolutePath().replace('\\', '/'); - return !path.contains("/src/test/") && !path.contains("/target/") && - !"package.html".equals(pathname.getName()) && - (pathname.isDirectory() || pathname.getName().endsWith(".html")); - } - }; - - private static final ErrorHandler errorHandler = new ErrorHandler() - { - @Override - public void warning(SAXParseException exception) throws SAXException - { - throw exception; - } - - @Override - public void error(SAXParseException exception) throws SAXException - { - throw exception; - } - - @Override - public void fatalError(SAXParseException exception) throws SAXException - { - throw exception; - } - - }; - - private static final EntityResolver entityResolver = new EntityResolver() - { - private final Map<String, String> systemIdToUri = new HashMap<>(); - - { - systemIdToUri.put("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", - "xhtml1-transitional.dtd"); - systemIdToUri.put("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", - "xhtml1-strict.dtd"); - - /* - * Cheating: using xhtml dtd-s for html4 files too because the html4 dtd-s are not valid - * xml dtd-s. - */ - systemIdToUri.put("http://www.w3.org/TR/html4/loose.dtd", "xhtml1-transitional.dtd"); - systemIdToUri.put("http://www.w3.org/TR/html4/strict.dtd", "xhtml1-strict.dtd"); - } - - @Override - public InputSource resolveEntity(String publicId, String systemId) throws SAXException, - IOException - { - String uri = systemIdToUri.get(systemId); - if (uri != null) - { - return new InputSource(WellFormedXmlTestCase.class.getResource(uri).toString()); - } - - return null; - } - }; -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.util.markup.xhtml; + +import org.junit.jupiter.api.Test; +import org.xml.sax.*; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * Usable by tests to check that the html markup files are well formed. + * + * @author akiraly + */ +public class WellFormedXmlTestCase +{ + private DocumentBuilderFactory factory; + + /** + * Checks xml well formedness of html markup files under the current working directory. + */ + @Test + public void markupFiles() + { + factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + + File root = new File("").getAbsoluteFile(); + processDirectory(root); + } + + private void processDirectory(File dir) + { + for (File f : dir.listFiles(fileFilter)) + { + if (f.isDirectory()) + { + processDirectory(f); + } + else + { + processFile(f); + } + } + } + + private void processFile(File file) + { + DocumentBuilder builder; + + try + { + builder = factory.newDocumentBuilder(); + } + catch (ParserConfigurationException e) + { + throw new RuntimeException("Configuration exception while parsing xml markup.", e); + } + + builder.setEntityResolver(entityResolver); + builder.setErrorHandler(errorHandler); + + try + { + builder.parse(file); + } + catch (SAXException e) + { + throw new RuntimeException("Parsing xml sax failed, file: " + file, e); + } + catch (IOException e) + { + throw new RuntimeException("Parsing xml io failed, file: " + file, e); + } + } + + private static final FileFilter fileFilter = new FileFilter() + { + @Override + public boolean accept(File pathname) + { + String path = pathname.getAbsolutePath().replace('\\', '/'); + return !path.contains("/src/test/") && !path.contains("/target/") && + !"package.html".equals(pathname.getName()) && + (pathname.isDirectory() || pathname.getName().endsWith(".html")); + } + }; + + private static final ErrorHandler errorHandler = new ErrorHandler() + { + @Override + public void warning(SAXParseException exception) throws SAXException + { + throw exception; + } + + @Override + public void error(SAXParseException exception) throws SAXException + { + throw exception; + } + + @Override + public void fatalError(SAXParseException exception) throws SAXException + { + throw exception; + } + + }; + + private static final EntityResolver entityResolver = new EntityResolver() + { + private final Map<String, String> systemIdToUri = new HashMap<>(); + + { + systemIdToUri.put("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", + "xhtml1-transitional.dtd"); + systemIdToUri.put("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", + "xhtml1-strict.dtd"); + + /* + * Cheating: using xhtml dtd-s for html4 files too because the html4 dtd-s are not valid + * xml dtd-s. + */ + systemIdToUri.put("http://www.w3.org/TR/html4/loose.dtd", "xhtml1-transitional.dtd"); + systemIdToUri.put("http://www.w3.org/TR/html4/strict.dtd", "xhtml1-strict.dtd"); + } + + @Override + public InputSource resolveEntity(String publicId, String systemId) + { + String uri = systemIdToUri.get(systemId); + if (uri != null) + { + return new InputSource(WellFormedXmlTestCase.class.getResource(uri).toString()); + } + + return null; + } + }; +} http://git-wip-us.apache.org/repos/asf/wicket/blob/51725af8/wicket-util/src/test/java/org/apache/wicket/util/collections/IntHashMapTest.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/test/java/org/apache/wicket/util/collections/IntHashMapTest.java b/wicket-util/src/test/java/org/apache/wicket/util/collections/IntHashMapTest.java index f3e9587..295244f 100644 --- a/wicket-util/src/test/java/org/apache/wicket/util/collections/IntHashMapTest.java +++ b/wicket-util/src/test/java/org/apache/wicket/util/collections/IntHashMapTest.java @@ -45,7 +45,8 @@ class IntHashMapTest byte[] serialized = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(serialized); ObjectInputStream ois = new ObjectInputStream(bais); - IntHashMap<String> deserialized = (IntHashMap<String>)ois.readObject(); + + IntHashMap<String> deserialized = (IntHashMap<String>) ois.readObject(); assertNotNull(deserialized); assertEquals("one", deserialized.get(1)); assertEquals("two", deserialized.get(2));