From: <bo...@us...> - 2007-04-04 12:01:52
|
Revision: 172 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=172&view=rev Author: bodewig Date: 2007-04-04 05:01:51 -0700 (Wed, 04 Apr 2007) Log Message: ----------- Move CountingNodeTester to examples Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/CountingNodeTester.java Added Paths: ----------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CountingNodeTester.java trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_CountingNodeTester.java Removed Paths: ------------- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_CountingNodeTester.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/CountingNodeTester.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/CountingNodeTester.java 2007-04-03 04:44:20 UTC (rev 171) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/CountingNodeTester.java 2007-04-04 12:01:51 UTC (rev 172) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -36,53 +36,19 @@ package org.custommonkey.xmlunit; -import org.w3c.dom.Node; - /** * Counts the number of nodes in a document to allow assertions to be made * using a NodeTest. * <br />Examples and more at <a href="http://xmlunit.sourceforge.net"/>xmlunit.sourceforge.net</a> * @see NodeTest + * @deprecated Use {@link + * org.custommonkey.xmlunit.examples.CountingNodeTester + * CountingNodeTester} instead. */ -public class CountingNodeTester implements NodeTester { - private final int expectedNumNodes; - private int actualNumNodes; +public class CountingNodeTester + extends org.custommonkey.xmlunit.examples.CountingNodeTester { public CountingNodeTester(int expectedNumNodes) { - this.expectedNumNodes = expectedNumNodes; + super(expectedNumNodes); } - - /** - * A single Node is always valid - * @param aNode - * @param forTest - */ - public void testNode(Node aNode, NodeTest forTest) { - actualNumNodes++; - } - - /** - * Called by NodeTest when all nodes have been iterated over: time to see - * if all the nodes that were expected were found. - * Note that this method also invokes {@link #resetCounter resetCounter} - * so that the instance can be reused. - * @exception true if expected num nodes == actual num nodes, - * false otherwise - */ - public void noMoreNodes(NodeTest forTest) throws NodeTestException { - int testedNodes = actualNumNodes; - resetCounter(); - if (testedNodes != expectedNumNodes) { - throw new NodeTestException("Counted " + testedNodes - + " node(s) but expected " + expectedNumNodes); - } - } - - /** - * Reset the counter so that an instance can be reused for another - * <code>NodeTest</code> - */ - public void resetCounter() { - actualNumNodes = 0; - } } \ No newline at end of file Copied: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CountingNodeTester.java (from rev 171, trunk/xmlunit/src/java/org/custommonkey/xmlunit/CountingNodeTester.java) =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CountingNodeTester.java (rev 0) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/CountingNodeTester.java 2007-04-04 12:01:51 UTC (rev 172) @@ -0,0 +1,91 @@ +/* +****************************************************************** +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ + +package org.custommonkey.xmlunit.examples; + +import org.custommonkey.xmlunit.NodeTest; +import org.custommonkey.xmlunit.NodeTestException; +import org.custommonkey.xmlunit.NodeTester; +import org.w3c.dom.Node; + +/** + * Counts the number of nodes in a document to allow assertions to be made + * using a NodeTest. + * <br />Examples and more at <a href="http://xmlunit.sourceforge.net"/>xmlunit.sourceforge.net</a> + * @see NodeTest + */ +public class CountingNodeTester implements NodeTester { + private final int expectedNumNodes; + private int actualNumNodes; + + public CountingNodeTester(int expectedNumNodes) { + this.expectedNumNodes = expectedNumNodes; + } + + /** + * A single Node is always valid + * @param aNode + * @param forTest + */ + public void testNode(Node aNode, NodeTest forTest) { + actualNumNodes++; + } + + /** + * Called by NodeTest when all nodes have been iterated over: time to see + * if all the nodes that were expected were found. + * Note that this method also invokes {@link #resetCounter resetCounter} + * so that the instance can be reused. + * @exception true if expected num nodes == actual num nodes, + * false otherwise + */ + public void noMoreNodes(NodeTest forTest) throws NodeTestException { + int testedNodes = actualNumNodes; + resetCounter(); + if (testedNodes != expectedNumNodes) { + throw new NodeTestException("Counted " + testedNodes + + " node(s) but expected " + expectedNumNodes); + } + } + + /** + * Reset the counter so that an instance can be reused for another + * <code>NodeTest</code> + */ + public void resetCounter() { + actualNumNodes = 0; + } +} \ No newline at end of file Copied: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_CountingNodeTester.java (from rev 171, trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_CountingNodeTester.java) =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_CountingNodeTester.java (rev 0) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/examples/test_CountingNodeTester.java 2007-04-04 12:01:51 UTC (rev 172) @@ -0,0 +1,119 @@ +/* +****************************************************************** +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ + +package org.custommonkey.xmlunit.examples; + +import java.io.StringReader; + +import junit.framework.TestCase; + +import org.custommonkey.xmlunit.NodeTest; +import org.custommonkey.xmlunit.NodeTestException; +import org.w3c.dom.Node; + +/** + * JUnit test for CountingNodeTester + */ +public class test_CountingNodeTester extends TestCase { + private NodeTest test; + private CountingNodeTester tester; + + public void testPositivePath() throws Exception { + test = new NodeTest(new StringReader("<a><b>c</b></a>")); + tester = new CountingNodeTester(2); + test.performTest(tester, Node.ELEMENT_NODE); + + tester = new CountingNodeTester(1); + test.performTest(tester, Node.TEXT_NODE); + + tester = new CountingNodeTester(3); + test.performTest(tester, + new short[] {Node.TEXT_NODE, Node.ELEMENT_NODE}); + + tester = new CountingNodeTester(0); + test.performTest(tester, Node.COMMENT_NODE); + } + + public void testNegativePath() throws Exception { + test = new NodeTest(new StringReader("<a><b>c</b></a>")); + try { + tester = new CountingNodeTester(2); + test.performTest(tester, Node.TEXT_NODE); + fail("Expected NodeTestException"); + } catch (NodeTestException e) { + // failure, as expected + } + + try { + tester = new CountingNodeTester(1); + test.performTest(tester, Node.ELEMENT_NODE); + fail("Expected NodeTestException"); + } catch (NodeTestException e) { + // failure, as expected + } + + try { + tester = new CountingNodeTester(2); + test.performTest(tester, + new short[] {Node.TEXT_NODE, Node.ELEMENT_NODE}); + fail("Expected NodeTestException"); + } catch (NodeTestException e) { + // failure, as expected + } + + try { + tester = new CountingNodeTester(1); + test.performTest(tester, Node.COMMENT_NODE); + fail("Expected NodeTestException"); + } catch (NodeTestException e) { + // failure, as expected + } + + try { + tester = new CountingNodeTester(0); + test.performTest(tester, Node.TEXT_NODE); + fail("Expected NodeTestException"); + } catch (NodeTestException e) { + // failure, as expected + } + } + + public test_CountingNodeTester(String name) { + super(name); + } + +} + Deleted: trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_CountingNodeTester.java =================================================================== --- trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_CountingNodeTester.java 2007-04-03 04:44:20 UTC (rev 171) +++ trunk/xmlunit/tests/java/org/custommonkey/xmlunit/test_CountingNodeTester.java 2007-04-04 12:01:51 UTC (rev 172) @@ -1,117 +0,0 @@ -/* -****************************************************************** -Copyright (c) 200, Jeff Martin, Tim Bacon -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of the xmlunit.sourceforge.net nor the names - of its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -****************************************************************** -*/ - -package org.custommonkey.xmlunit; - -import java.io.StringReader; - -import junit.framework.TestCase; - -import org.w3c.dom.Node; - -/** - * JUnit test for CountingNodeTester - */ -public class test_CountingNodeTester extends TestCase { - private NodeTest test; - private CountingNodeTester tester; - - public void testPositivePath() throws Exception { - test = new NodeTest(new StringReader("<a><b>c</b></a>")); - tester = new CountingNodeTester(2); - test.performTest(tester, Node.ELEMENT_NODE); - - tester = new CountingNodeTester(1); - test.performTest(tester, Node.TEXT_NODE); - - tester = new CountingNodeTester(3); - test.performTest(tester, - new short[] {Node.TEXT_NODE, Node.ELEMENT_NODE}); - - tester = new CountingNodeTester(0); - test.performTest(tester, Node.COMMENT_NODE); - } - - public void testNegativePath() throws Exception { - test = new NodeTest(new StringReader("<a><b>c</b></a>")); - try { - tester = new CountingNodeTester(2); - test.performTest(tester, Node.TEXT_NODE); - fail("Expected NodeTestException"); - } catch (NodeTestException e) { - // failure, as expected - } - - try { - tester = new CountingNodeTester(1); - test.performTest(tester, Node.ELEMENT_NODE); - fail("Expected NodeTestException"); - } catch (NodeTestException e) { - // failure, as expected - } - - try { - tester = new CountingNodeTester(2); - test.performTest(tester, - new short[] {Node.TEXT_NODE, Node.ELEMENT_NODE}); - fail("Expected NodeTestException"); - } catch (NodeTestException e) { - // failure, as expected - } - - try { - tester = new CountingNodeTester(1); - test.performTest(tester, Node.COMMENT_NODE); - fail("Expected NodeTestException"); - } catch (NodeTestException e) { - // failure, as expected - } - - try { - tester = new CountingNodeTester(0); - test.performTest(tester, Node.TEXT_NODE); - fail("Expected NodeTestException"); - } catch (NodeTestException e) { - // failure, as expected - } - } - - public test_CountingNodeTester(String name) { - super(name); - } - -} - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |