From 7146a0954f1bc162486d66950215a08b795e59b0 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 8 May 2026 07:52:43 +0200 Subject: [PATCH] replace our own Predicate interface with java.util.function --- pom.xml | 4 +-- .../org/xmlunit/assertj/CompareAssert.java | 2 +- .../CompareAssertAreIdenticalTest.java | 2 +- .../org/xmlunit/assertj3/CompareAssert.java | 2 +- .../CompareAssertAreIdenticalTest.java | 2 +- .../java/org/xmlunit/builder/DiffBuilder.java | 2 +- .../builder/DifferenceEngineConfigurer.java | 2 +- .../diff/AbstractDifferenceEngine.java | 9 ++---- .../DefaultConditionalSelectorBuilder.java | 3 +- .../org/xmlunit/diff/DifferenceEngine.java | 2 +- .../org/xmlunit/diff/ElementSelectors.java | 21 +++++-------- .../java/org/xmlunit/diff/NodeFilters.java | 17 +++------- .../org/xmlunit/util/IsNullPredicate.java | 24 -------------- .../src/main/java/org/xmlunit/util/Linqy.java | 1 + .../src/main/java/org/xmlunit/util/Nodes.java | 8 ++--- .../main/java/org/xmlunit/util/Predicate.java | 26 ---------------- .../org/xmlunit/builder/DiffBuilderTest.java | 2 +- .../xmlunit/diff/DOMDifferenceEngineTest.java | 2 +- .../xmlunit/diff/ElementSelectorsTest.java | 10 +++--- .../org/xmlunit/diff/NodeFiltersTest.java | 2 +- .../org/xmlunit/util/IsNullPredicateTest.java | 31 ------------------- .../test/java/org/xmlunit/util/LinqyTest.java | 6 ++-- .../test/java/org/xmlunit/util/NodesTest.java | 1 + .../xmlunit/NewDifferenceEngine.java | 2 +- .../org/xmlunit/matchers/CompareMatcher.java | 2 +- .../xmlunit/matchers/ValidationMatcher.java | 6 ++-- .../xmlunit/matchers/CompareMatcherTest.java | 14 ++++----- 27 files changed, 52 insertions(+), 153 deletions(-) delete mode 100644 xmlunit-core/src/main/java/org/xmlunit/util/IsNullPredicate.java delete mode 100644 xmlunit-core/src/main/java/org/xmlunit/util/Predicate.java delete mode 100644 xmlunit-core/src/test/java/org/xmlunit/util/IsNullPredicateTest.java diff --git a/pom.xml b/pom.xml index 02f16d9d..b62628b2 100644 --- a/pom.xml +++ b/pom.xml @@ -24,8 +24,8 @@ https://www.xmlunit.org/ - 1.7 - 1.7 + 8 + 8 UTF-8 UTF-8 UTF-8 diff --git a/xmlunit-assertj/src/main/java/org/xmlunit/assertj/CompareAssert.java b/xmlunit-assertj/src/main/java/org/xmlunit/assertj/CompareAssert.java index 5d279e80..8d1cb035 100644 --- a/xmlunit-assertj/src/main/java/org/xmlunit/assertj/CompareAssert.java +++ b/xmlunit-assertj/src/main/java/org/xmlunit/assertj/CompareAssert.java @@ -30,9 +30,9 @@ import org.xmlunit.diff.DifferenceEvaluators; import org.xmlunit.diff.ElementSelectors; import org.xmlunit.diff.NodeMatcher; -import org.xmlunit.util.Predicate; import java.util.Map; +import java.util.function.Predicate; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Source; diff --git a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/CompareAssertAreIdenticalTest.java b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/CompareAssertAreIdenticalTest.java index c952b998..989fc097 100644 --- a/xmlunit-assertj/src/test/java/org/xmlunit/assertj/CompareAssertAreIdenticalTest.java +++ b/xmlunit-assertj/src/test/java/org/xmlunit/assertj/CompareAssertAreIdenticalTest.java @@ -28,9 +28,9 @@ import org.xmlunit.diff.DifferenceEvaluator; import org.xmlunit.diff.DifferenceEvaluators; import org.xmlunit.diff.ElementSelectors; -import org.xmlunit.util.Predicate; import java.io.IOException; +import java.util.function.Predicate; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; diff --git a/xmlunit-assertj3/src/main/java/org/xmlunit/assertj3/CompareAssert.java b/xmlunit-assertj3/src/main/java/org/xmlunit/assertj3/CompareAssert.java index b9a2785f..119e70fa 100644 --- a/xmlunit-assertj3/src/main/java/org/xmlunit/assertj3/CompareAssert.java +++ b/xmlunit-assertj3/src/main/java/org/xmlunit/assertj3/CompareAssert.java @@ -30,9 +30,9 @@ import org.xmlunit.diff.DifferenceEvaluators; import org.xmlunit.diff.ElementSelectors; import org.xmlunit.diff.NodeMatcher; -import org.xmlunit.util.Predicate; import java.util.Map; +import java.util.function.Predicate; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Source; diff --git a/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/CompareAssertAreIdenticalTest.java b/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/CompareAssertAreIdenticalTest.java index 24cfbeb0..b6ebc9cf 100644 --- a/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/CompareAssertAreIdenticalTest.java +++ b/xmlunit-assertj3/src/test/java/org/xmlunit/assertj3/CompareAssertAreIdenticalTest.java @@ -28,9 +28,9 @@ import org.xmlunit.diff.DifferenceEvaluator; import org.xmlunit.diff.DifferenceEvaluators; import org.xmlunit.diff.ElementSelectors; -import org.xmlunit.util.Predicate; import java.io.IOException; +import java.util.function.Predicate; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; diff --git a/xmlunit-core/src/main/java/org/xmlunit/builder/DiffBuilder.java b/xmlunit-core/src/main/java/org/xmlunit/builder/DiffBuilder.java index 3ac001ec..87c5986e 100644 --- a/xmlunit-core/src/main/java/org/xmlunit/builder/DiffBuilder.java +++ b/xmlunit-core/src/main/java/org/xmlunit/builder/DiffBuilder.java @@ -32,7 +32,6 @@ import org.xmlunit.input.ElementContentWhitespaceStrippedSource; import org.xmlunit.input.WhitespaceNormalizedSource; import org.xmlunit.input.WhitespaceStrippedSource; -import org.xmlunit.util.Predicate; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Source; @@ -43,6 +42,7 @@ import java.util.EnumSet; import java.util.List; import java.util.Map; +import java.util.function.Predicate; /** * DiffBuilder to create a {@link Diff} instance. diff --git a/xmlunit-core/src/main/java/org/xmlunit/builder/DifferenceEngineConfigurer.java b/xmlunit-core/src/main/java/org/xmlunit/builder/DifferenceEngineConfigurer.java index 8540b22e..c80f4833 100644 --- a/xmlunit-core/src/main/java/org/xmlunit/builder/DifferenceEngineConfigurer.java +++ b/xmlunit-core/src/main/java/org/xmlunit/builder/DifferenceEngineConfigurer.java @@ -14,6 +14,7 @@ package org.xmlunit.builder; import java.util.Map; +import java.util.function.Predicate; import org.w3c.dom.Attr; import org.w3c.dom.Node; @@ -26,7 +27,6 @@ import org.xmlunit.diff.DifferenceEvaluator; import org.xmlunit.diff.DifferenceEvaluators; import org.xmlunit.diff.NodeMatcher; -import org.xmlunit.util.Predicate; /** * Subset of the configuration options available for a {@link DifferenceEngine}. diff --git a/xmlunit-core/src/main/java/org/xmlunit/diff/AbstractDifferenceEngine.java b/xmlunit-core/src/main/java/org/xmlunit/diff/AbstractDifferenceEngine.java index 26ab80a7..b242aa28 100644 --- a/xmlunit-core/src/main/java/org/xmlunit/diff/AbstractDifferenceEngine.java +++ b/xmlunit-core/src/main/java/org/xmlunit/diff/AbstractDifferenceEngine.java @@ -15,9 +15,9 @@ import java.util.Collections; import java.util.Map; +import java.util.function.Predicate; import org.w3c.dom.Attr; import org.w3c.dom.Node; -import org.xmlunit.util.Predicate; /** * Useful base-implementation of some parts of the DifferenceEngine @@ -32,12 +32,7 @@ public abstract class AbstractDifferenceEngine implements DifferenceEngine { private DifferenceEvaluator diffEvaluator = DifferenceEvaluators.Default; private ComparisonController comparisonController = ComparisonControllers.Default; private Map prefix2uri = Collections.emptyMap(); - private Predicate attributeFilter = new Predicate() { - @Override - public boolean test(Attr a) { - return true; - } - }; + private Predicate attributeFilter = a -> true; private Predicate nodeFilter = NodeFilters.Default; /** diff --git a/xmlunit-core/src/main/java/org/xmlunit/diff/DefaultConditionalSelectorBuilder.java b/xmlunit-core/src/main/java/org/xmlunit/diff/DefaultConditionalSelectorBuilder.java index 8c937677..010409e6 100644 --- a/xmlunit-core/src/main/java/org/xmlunit/diff/DefaultConditionalSelectorBuilder.java +++ b/xmlunit-core/src/main/java/org/xmlunit/diff/DefaultConditionalSelectorBuilder.java @@ -16,7 +16,7 @@ import java.util.Map; import java.util.LinkedHashMap; import javax.xml.namespace.QName; -import org.xmlunit.util.Predicate; +import java.util.function.Predicate; import org.w3c.dom.Element; class DefaultConditionalSelectorBuilder @@ -94,4 +94,3 @@ public boolean canBeCompared(Element controlElement, } } } - diff --git a/xmlunit-core/src/main/java/org/xmlunit/diff/DifferenceEngine.java b/xmlunit-core/src/main/java/org/xmlunit/diff/DifferenceEngine.java index 5a901296..becff01d 100644 --- a/xmlunit-core/src/main/java/org/xmlunit/diff/DifferenceEngine.java +++ b/xmlunit-core/src/main/java/org/xmlunit/diff/DifferenceEngine.java @@ -14,10 +14,10 @@ package org.xmlunit.diff; import java.util.Map; +import java.util.function.Predicate; import javax.xml.transform.Source; import org.w3c.dom.Attr; import org.w3c.dom.Node; -import org.xmlunit.util.Predicate; /** * XMLUnit's difference engine. diff --git a/xmlunit-core/src/main/java/org/xmlunit/diff/ElementSelectors.java b/xmlunit-core/src/main/java/org/xmlunit/diff/ElementSelectors.java index 7b44f0a8..d83038a1 100644 --- a/xmlunit-core/src/main/java/org/xmlunit/diff/ElementSelectors.java +++ b/xmlunit-core/src/main/java/org/xmlunit/diff/ElementSelectors.java @@ -20,13 +20,13 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.Objects; import java.util.Map; +import java.util.function.Predicate; import javax.xml.namespace.QName; -import org.xmlunit.util.IsNullPredicate; import org.xmlunit.util.Linqy; import org.xmlunit.util.Mapper; import org.xmlunit.util.Nodes; -import org.xmlunit.util.Predicate; import org.xmlunit.xpath.JAXPXPathEngine; import org.xmlunit.xpath.XPathEngine; import org.w3c.dom.Attr; @@ -91,12 +91,7 @@ && bothNullOrEqual(Nodes.getMergedNestedText(controlElement), * #byNameAndAllAttributes(Predicate)} passing in your attribute filter if this causes problems.

*/ public static final ElementSelector byNameAndAllAttributes = - byNameAndAllAttributes(new Predicate() { - @Override - public boolean test(Attr a) { - return true; - } - }); + byNameAndAllAttributes(a -> true); /** * Elements with the same local name (and namespace URI - if any) @@ -161,7 +156,7 @@ public static ElementSelector byNameAndAttributes(String... attribs) { if (attribs == null) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_BE_NULL); } - if (any(Arrays.asList(attribs), new IsNullPredicate())) { + if (any(Arrays.asList(attribs), Objects::isNull)) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_CONTAIN_NULL_VALUES); } QName[] qs = new QName[attribs.length]; @@ -190,7 +185,7 @@ public static ElementSelector byNameAndAttributes(String... attribs) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_BE_NULL); } final Collection qs = Arrays.asList(attribs); - if (any(qs, new IsNullPredicate())) { + if (any(qs, Objects::isNull)) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_CONTAIN_NULL_VALUES); } final HashSet as = new HashSet(qs); @@ -236,7 +231,7 @@ public static ElementSelector byNameAndAttributes(final QName... attribs) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_BE_NULL); } final Collection qs = Arrays.asList(attribs); - if (any(qs, new IsNullPredicate())) { + if (any(qs, Objects::isNull)) { throw new IllegalArgumentException(ATTRIBUTES_MUST_NOT_CONTAIN_NULL_VALUES); } return new ElementSelector() { @@ -306,7 +301,7 @@ public static ElementSelector or(final ElementSelector... selectors) { throw new IllegalArgumentException(SELECTORS_MUST_NOT_BE_NULL); } final Collection s = Arrays.asList(selectors); - if (any(s, new IsNullPredicate())) { + if (any(s, Objects::isNull)) { throw new IllegalArgumentException("selectors must not contain null values"); } return new ElementSelector() { @@ -329,7 +324,7 @@ public static ElementSelector and(final ElementSelector... selectors) { throw new IllegalArgumentException(SELECTORS_MUST_NOT_BE_NULL); } final Collection s = Arrays.asList(selectors); - if (any(s, new IsNullPredicate())) { + if (any(s, Objects::isNull)) { throw new IllegalArgumentException("selectors must not contain null values"); } return new ElementSelector() { diff --git a/xmlunit-core/src/main/java/org/xmlunit/diff/NodeFilters.java b/xmlunit-core/src/main/java/org/xmlunit/diff/NodeFilters.java index 9ad659a0..79b1234b 100644 --- a/xmlunit-core/src/main/java/org/xmlunit/diff/NodeFilters.java +++ b/xmlunit-core/src/main/java/org/xmlunit/diff/NodeFilters.java @@ -14,7 +14,7 @@ package org.xmlunit.diff; import org.w3c.dom.Node; -import org.xmlunit.util.Predicate; +import java.util.function.Predicate; /** * Common NodeFilter implementations. @@ -27,24 +27,15 @@ public final class NodeFilters { *

This is the default used by {@link AbstractDifferenceEngine} * and thus {@link DOMDifferenceEngine}.

*/ - public static final Predicate Default = new Predicate() { - @Override - public boolean test(Node n) { - return n.getNodeType() != Node.DOCUMENT_TYPE_NODE; - } - }; + public static final Predicate Default = + n -> n.getNodeType() != Node.DOCUMENT_TYPE_NODE; /** * Accepts all nodes. * * @since XMLUnit 2.6.0 */ - public static final Predicate AcceptAll = new Predicate() { - @Override - public boolean test(Node n) { - return true; - } - }; + public static final Predicate AcceptAll = n -> true; /** * Accepts nodes that are accepted by all given filters. diff --git a/xmlunit-core/src/main/java/org/xmlunit/util/IsNullPredicate.java b/xmlunit-core/src/main/java/org/xmlunit/util/IsNullPredicate.java deleted file mode 100644 index 33e6ce0b..00000000 --- a/xmlunit-core/src/main/java/org/xmlunit/util/IsNullPredicate.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - This file is licensed 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.xmlunit.util; - -/** - * A function that tests whether an object is null. - */ -public class IsNullPredicate implements Predicate { - @Override - public boolean test(Object toTest) { - return toTest == null; - } -} diff --git a/xmlunit-core/src/main/java/org/xmlunit/util/Linqy.java b/xmlunit-core/src/main/java/org/xmlunit/util/Linqy.java index 7105ebe2..8fee20a9 100644 --- a/xmlunit-core/src/main/java/org/xmlunit/util/Linqy.java +++ b/xmlunit-core/src/main/java/org/xmlunit/util/Linqy.java @@ -18,6 +18,7 @@ import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; +import java.util.function.Predicate; /** * A couple of (functional) sequence processing constructs. diff --git a/xmlunit-core/src/main/java/org/xmlunit/util/Nodes.java b/xmlunit-core/src/main/java/org/xmlunit/util/Nodes.java index 9132c1f2..fe69c0d4 100644 --- a/xmlunit-core/src/main/java/org/xmlunit/util/Nodes.java +++ b/xmlunit-core/src/main/java/org/xmlunit/util/Nodes.java @@ -17,6 +17,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.function.Predicate; import javax.xml.XMLConstants; import javax.xml.namespace.QName; import org.w3c.dom.Attr; @@ -78,12 +79,7 @@ public static String getMergedNestedText(Node n) { * @return attributes */ public static Map getAttributes(Node n) { - return getAttributes(n, new Predicate() { - @Override - public boolean test(Attr a) { - return true; - } - }); + return getAttributes(n, ignored -> true); } /** diff --git a/xmlunit-core/src/main/java/org/xmlunit/util/Predicate.java b/xmlunit-core/src/main/java/org/xmlunit/util/Predicate.java deleted file mode 100644 index c5754b9b..00000000 --- a/xmlunit-core/src/main/java/org/xmlunit/util/Predicate.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - This file is licensed 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.xmlunit.util; - -/** - * A function that tests an object for a property. - */ -public interface Predicate { - /** - * Performs the test. - * @param toTest the object to test - * @return true if the test is successful - */ - boolean test(T toTest); -} diff --git a/xmlunit-core/src/test/java/org/xmlunit/builder/DiffBuilderTest.java b/xmlunit-core/src/test/java/org/xmlunit/builder/DiffBuilderTest.java index 03e4f21c..bbce6a87 100644 --- a/xmlunit-core/src/test/java/org/xmlunit/builder/DiffBuilderTest.java +++ b/xmlunit-core/src/test/java/org/xmlunit/builder/DiffBuilderTest.java @@ -31,7 +31,6 @@ import org.xmlunit.diff.Difference; import org.xmlunit.diff.DifferenceEvaluator; import org.xmlunit.diff.DifferenceEvaluators; -import org.xmlunit.util.Predicate; import org.junit.Assert; import org.junit.Test; @@ -44,6 +43,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.function.Predicate; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; diff --git a/xmlunit-core/src/test/java/org/xmlunit/diff/DOMDifferenceEngineTest.java b/xmlunit-core/src/test/java/org/xmlunit/diff/DOMDifferenceEngineTest.java index fdc16837..ef56ba93 100644 --- a/xmlunit-core/src/test/java/org/xmlunit/diff/DOMDifferenceEngineTest.java +++ b/xmlunit-core/src/test/java/org/xmlunit/diff/DOMDifferenceEngineTest.java @@ -15,6 +15,7 @@ import java.util.Arrays; import java.util.List; +import java.util.function.Predicate; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.dom.DOMSource; import org.xmlunit.NullNode; @@ -23,7 +24,6 @@ import org.xmlunit.builder.Input; import org.xmlunit.util.Convert; import org.xmlunit.util.Linqy; -import org.xmlunit.util.Predicate; import org.junit.Before; import org.junit.Test; import org.w3c.dom.Attr; diff --git a/xmlunit-core/src/test/java/org/xmlunit/diff/ElementSelectorsTest.java b/xmlunit-core/src/test/java/org/xmlunit/diff/ElementSelectorsTest.java index a31b3958..0076dd80 100644 --- a/xmlunit-core/src/test/java/org/xmlunit/diff/ElementSelectorsTest.java +++ b/xmlunit-core/src/test/java/org/xmlunit/diff/ElementSelectorsTest.java @@ -16,6 +16,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.Objects; +import java.util.function.Predicate; import javax.xml.XMLConstants; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; @@ -29,8 +31,6 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; -import org.xmlunit.util.IsNullPredicate; -import org.xmlunit.util.Predicate; import org.xmlunit.xpath.JAXPXPathEngine; import org.xmlunit.xpath.XPathEngine; @@ -545,7 +545,7 @@ public void xorDoesntLikeNullElementSelector2() { @Test(expected = IllegalArgumentException.class) public void conditionalSelectorDoesntLikeNullElementSelector() { - ElementSelectors.conditionalSelector(new IsNullPredicate(), null); + ElementSelectors.conditionalSelector(Objects::isNull, null); } @Test(expected = IllegalArgumentException.class) @@ -584,7 +584,7 @@ public void conditionalSelectorBuilderWontAllowThenWithoutWhen() { public void conditionalSelectorBuilderWontAllowWhensWithoutThens() { ElementSelectors.ConditionalSelectorBuilder b = ElementSelectors.conditionalBuilder(); - b.when(new IsNullPredicate()); + b.when(Objects::isNull); b.build(); } @@ -592,7 +592,7 @@ public void conditionalSelectorBuilderWontAllowWhensWithoutThens() { public void conditionalSelectorBuilderWontAllowMultipleWhensWithoutInterleavingThens() { ElementSelectors.ConditionalSelectorBuilder b = ElementSelectors.conditionalBuilder(); - b.when(new IsNullPredicate()); + b.when(Objects::isNull); b.whenElementIsNamed(new QName("foo")); } diff --git a/xmlunit-core/src/test/java/org/xmlunit/diff/NodeFiltersTest.java b/xmlunit-core/src/test/java/org/xmlunit/diff/NodeFiltersTest.java index e6d2e61b..f438517e 100644 --- a/xmlunit-core/src/test/java/org/xmlunit/diff/NodeFiltersTest.java +++ b/xmlunit-core/src/test/java/org/xmlunit/diff/NodeFiltersTest.java @@ -13,9 +13,9 @@ */ package org.xmlunit.diff; +import java.util.function.Predicate; import org.junit.Test; import org.w3c.dom.Node; -import org.xmlunit.util.Predicate; import static org.junit.Assert.*; diff --git a/xmlunit-core/src/test/java/org/xmlunit/util/IsNullPredicateTest.java b/xmlunit-core/src/test/java/org/xmlunit/util/IsNullPredicateTest.java deleted file mode 100644 index e3e0c3d7..00000000 --- a/xmlunit-core/src/test/java/org/xmlunit/util/IsNullPredicateTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - This file is licensed 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.xmlunit.util; - -import org.junit.Test; -import static org.junit.Assert.assertTrue; - -public class IsNullPredicateTest { - - @Test - public void shouldReturnTrueOnNull() { - assertTrue(new IsNullPredicate().test(null)); - } - - - @Test - public void shouldReturnFalseOnNonNull() { - assertTrue(!new IsNullPredicate().test(new Object())); - } -} diff --git a/xmlunit-core/src/test/java/org/xmlunit/util/LinqyTest.java b/xmlunit-core/src/test/java/org/xmlunit/util/LinqyTest.java index 710807f6..8f773d0c 100644 --- a/xmlunit-core/src/test/java/org/xmlunit/util/LinqyTest.java +++ b/xmlunit-core/src/test/java/org/xmlunit/util/LinqyTest.java @@ -13,11 +13,13 @@ */ package org.xmlunit.util; +import java.util.AbstractCollection; import java.util.ArrayList; import java.util.Arrays; -import java.util.AbstractCollection; import java.util.Iterator; import java.util.NoSuchElementException; +import java.util.Objects; +import java.util.function.Predicate; import org.junit.Assert; import org.junit.Test; @@ -98,7 +100,7 @@ public void cantRemoveFromSingletonIterator() { @Test(expected=NoSuchElementException.class) public void cantReadPastLastFilterElement() { - Iterator i = Linqy.filter(Arrays.asList("foo"), new IsNullPredicate()) + Iterator i = Linqy.filter(Arrays.asList("foo"), Objects::isNull) .iterator(); i.next(); } diff --git a/xmlunit-core/src/test/java/org/xmlunit/util/NodesTest.java b/xmlunit-core/src/test/java/org/xmlunit/util/NodesTest.java index b6a70a41..0009e9df 100644 --- a/xmlunit-core/src/test/java/org/xmlunit/util/NodesTest.java +++ b/xmlunit-core/src/test/java/org/xmlunit/util/NodesTest.java @@ -14,6 +14,7 @@ package org.xmlunit.util; import java.util.Map; +import java.util.function.Predicate; import javax.xml.XMLConstants; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; diff --git a/xmlunit-legacy/src/main/java/org/custommonkey/xmlunit/NewDifferenceEngine.java b/xmlunit-legacy/src/main/java/org/custommonkey/xmlunit/NewDifferenceEngine.java index 9580da78..4aeee28d 100644 --- a/xmlunit-legacy/src/main/java/org/custommonkey/xmlunit/NewDifferenceEngine.java +++ b/xmlunit-legacy/src/main/java/org/custommonkey/xmlunit/NewDifferenceEngine.java @@ -42,6 +42,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.function.Predicate; import javax.xml.transform.Source; import org.xmlunit.builder.Input; @@ -63,7 +64,6 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN import org.xmlunit.input.WhitespaceStrippedSource; import org.xmlunit.util.IterableNodeList; import org.xmlunit.util.Linqy; -import org.xmlunit.util.Predicate; import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier; import org.w3c.dom.CDATASection; diff --git a/xmlunit-matchers/src/main/java/org/xmlunit/matchers/CompareMatcher.java b/xmlunit-matchers/src/main/java/org/xmlunit/matchers/CompareMatcher.java index 14f2e887..8754434e 100644 --- a/xmlunit-matchers/src/main/java/org/xmlunit/matchers/CompareMatcher.java +++ b/xmlunit-matchers/src/main/java/org/xmlunit/matchers/CompareMatcher.java @@ -29,7 +29,6 @@ import org.xmlunit.diff.DifferenceEvaluators; import org.xmlunit.diff.ElementSelector; import org.xmlunit.diff.NodeMatcher; -import org.xmlunit.util.Predicate; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; @@ -38,6 +37,7 @@ import java.lang.reflect.Constructor; import java.util.Map; +import java.util.function.Predicate; import java.util.logging.Logger; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Attr; diff --git a/xmlunit-matchers/src/main/java/org/xmlunit/matchers/ValidationMatcher.java b/xmlunit-matchers/src/main/java/org/xmlunit/matchers/ValidationMatcher.java index 252b21ca..220a63ab 100644 --- a/xmlunit-matchers/src/main/java/org/xmlunit/matchers/ValidationMatcher.java +++ b/xmlunit-matchers/src/main/java/org/xmlunit/matchers/ValidationMatcher.java @@ -18,9 +18,7 @@ import static org.xmlunit.util.Linqy.map; import org.xmlunit.builder.Input; -import org.xmlunit.util.IsNullPredicate; import org.xmlunit.util.Mapper; -import org.xmlunit.util.Predicate; import org.xmlunit.validation.JAXPValidator; import org.xmlunit.validation.Languages; import org.xmlunit.validation.ValidationProblem; @@ -32,6 +30,8 @@ import javax.xml.transform.Source; import javax.xml.validation.Schema; import java.util.Arrays; +import java.util.Objects; +import java.util.function.Predicate; /** * Hamcrest Matcher for XML Validation against W3C XML Schema using @@ -52,7 +52,7 @@ public ValidationMatcher(Object... schemaSource) { throw new IllegalArgumentException("schemaSource must not be null"); } Iterable schemaSourceList = Arrays.asList(schemaSource); - if (any(schemaSourceList, new IsNullPredicate())) { + if (any(schemaSourceList, Objects::isNull)) { throw new IllegalArgumentException("schemaSource must not contain null values"); } this.schemaSource = asList(map(schemaSourceList, diff --git a/xmlunit-matchers/src/test/java/org/xmlunit/matchers/CompareMatcherTest.java b/xmlunit-matchers/src/test/java/org/xmlunit/matchers/CompareMatcherTest.java index 6c74d5b3..a8b6a0db 100644 --- a/xmlunit-matchers/src/test/java/org/xmlunit/matchers/CompareMatcherTest.java +++ b/xmlunit-matchers/src/test/java/org/xmlunit/matchers/CompareMatcherTest.java @@ -36,7 +36,6 @@ import org.xmlunit.diff.DefaultNodeMatcher; import org.xmlunit.diff.DifferenceEvaluator; import org.xmlunit.diff.ElementSelectors; -import org.xmlunit.util.Predicate; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; @@ -65,6 +64,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.util.function.Predicate; public class CompareMatcherTest { @@ -248,7 +248,7 @@ public void testIsSimilarTo_withComparisonListener_shouldCollectChanges() { } catch (AssertionError e) { assertThat(e.getMessage(), containsString("Expected text value 'ABC' but was 'XYZ'")); } - + // validate result assertThat(comparisonListener.differents, is(1)); assertThat(comparisonListener.similars, is(1)); @@ -268,7 +268,7 @@ public void testIsSimilarTo_withDifferenceListener_shouldCollectChanges() { } catch (AssertionError e) { assertThat(e.getMessage(), containsString("Expected text value 'ABC' but was 'XYZ'")); } - + // validate result assertThat(comparisonListener.differents, is(1)); assertThat(comparisonListener.similars, is(1)); @@ -277,7 +277,7 @@ public void testIsSimilarTo_withDifferenceListener_shouldCollectChanges() { @Test public void testCompareMatcherWrapper_shouldWriteFailedTestInput() { - + final String control = ""; final String test = ""; @@ -289,7 +289,7 @@ public void testCompareMatcherWrapper_shouldWriteFailedTestInput() { } catch (AssertionError e) { assertThat(e.getMessage(), containsString("Expected attribute value 'abc' but was 'xyz'")); } - + // validate that the written File contains the right data: assertThat(new File(getTestResultFolder(), fileName), isSimilarTo(test)); } @@ -476,7 +476,7 @@ public void comparisonPerformed(Comparison comparison, ComparisonResult outcome) *

* This example will write the Test-Input into the Files System.
* This could be useful for manual reviews or as template for a control-File. - * + * */ private static class TestCompareMatcherWrapper extends BaseMatcher { private final CompareMatcher compareMatcher; @@ -540,7 +540,7 @@ public void describeTo(Description description) { public void describeMismatch(Object item, Description description) { compareMatcher.describeMismatch(item, description); } - + } private static File getTestResultFolder() {