001: /*
002: ******************************************************************
003: Copyright (c) 200, Jeff Martin, Tim Bacon
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: * Redistributions of source code must retain the above copyright
011: notice, this list of conditions and the following disclaimer.
012: * Redistributions in binary form must reproduce the above
013: copyright notice, this list of conditions and the following
014: disclaimer in the documentation and/or other materials provided
015: with the distribution.
016: * Neither the name of the xmlunit.sourceforge.net nor the names
017: of its contributors may be used to endorse or promote products
018: derived from this software without specific prior written
019: permission.
020:
021: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
022: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
023: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
024: FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
025: COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
026: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
027: BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
028: LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
029: CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
030: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
031: ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
032: POSSIBILITY OF SUCH DAMAGE.
033:
034: ******************************************************************
035: */
036:
037: package org.custommonkey.xmlunit;
038:
039: import junit.framework.TestCase;
040:
041: import org.w3c.dom.Document;
042: import org.w3c.dom.Node;
043:
044: /**
045: * @author TimBacon
046: */
047: public class test_Difference extends TestCase {
048: private final Difference ORIGINAL = DifferenceConstants.ATTR_NAME_NOT_FOUND;
049:
050: public void testCopyConstructor() {
051: Difference copy = new Difference(ORIGINAL, null, null);
052: assertEquals("id", ORIGINAL.getId(), copy.getId());
053: assertEquals("description", ORIGINAL.getDescription(), copy
054: .getDescription());
055: assertEquals("recoverable", ORIGINAL.isRecoverable(), copy
056: .isRecoverable());
057:
058: assertEquals("precondition", false, ORIGINAL.isRecoverable());
059: copy.setRecoverable(true);
060: assertEquals("recoverable again", !ORIGINAL.isRecoverable(),
061: copy.isRecoverable());
062: }
063:
064: public void testEquals() {
065: assertTrue("not equal to null", !ORIGINAL.equals(null));
066: assertTrue("not equal to other class", !ORIGINAL
067: .equals("aString"));
068: assertEquals("equal to self", ORIGINAL, ORIGINAL);
069:
070: Difference copy = new Difference(ORIGINAL, null, null);
071: assertEquals("equal to copy", ORIGINAL, copy);
072: }
073:
074: public void testToString() throws Exception {
075: String originalAsString = "Difference (#" + ORIGINAL.getId()
076: + ") " + ORIGINAL.getDescription();
077: assertEquals("Original", originalAsString, ORIGINAL.toString());
078:
079: Document document = XMLUnit.newControlParser().newDocument();
080:
081: Node controlNode = document.createComment("control");
082: NodeDetail controlNodeDetail = new NodeDetail(controlNode
083: .getNodeValue(), controlNode, "/testToString/comment()");
084:
085: Node testNode = document.createComment("test");
086: NodeDetail testNodeDetail = new NodeDetail(testNode
087: .getNodeValue(), testNode, "/testToString/comment()");
088:
089: Difference difference = new Difference(
090: DifferenceConstants.COMMENT_VALUE, controlNodeDetail,
091: testNodeDetail);
092: StringBuffer buf = new StringBuffer("Expected ").append(
093: DifferenceConstants.COMMENT_VALUE.getDescription())
094: .append(" 'control' but was 'test' - comparing ");
095: NodeDescriptor.appendNodeDetail(buf, controlNodeDetail);
096: buf.append(" to ");
097: NodeDescriptor.appendNodeDetail(buf, testNodeDetail);
098: assertEquals("detail", buf.toString(), difference.toString());
099: }
100:
101: /**
102: * Constructor for test_Difference.
103: * @param name
104: */
105: public test_Difference(String name) {
106: super(name);
107: }
108:
109: }
|