Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
XMLUnit-Java.pdf
Скачиваний:
12
Добавлен:
24.03.2015
Размер:
266.81 Кб
Скачать

XMLUnit Java User’s Guide

16 / 35

Whenever a difference has been detected by the DifferenceEngine the haltComparison method will be called immediately after the DifferenceListener has been informed of the difference. This is true no matter what type of Difference has been found or which value the DifferenceListener has returned.

The only implementations of ComparisonController that ship with XMLUnit are Diff and DetailedDiff, see Section 3.5 for details about them.

A ComparisonController that halted the comparison on any non-recoverable difference could be implemented as:

Example 3.2 A Simple ComparisonController

public class HaltOnNonRecoverable implements ComparisonController {

public boolean haltComparison(Difference afterDifference) {

return !afterDifference.isRecoverable();

}

}

3.3 DifferenceListener

DifferenceListener contains two callback methods that are invoked by the DifferenceEngine when differences are detected:

/**

*Receive notification that 2 nodes are different.

*@param difference a Difference instance as defined in {@link

*DifferenceConstants DifferenceConstants} describing the cause

*of the difference and containing the detail of the nodes that

*differ

*@return int one of the RETURN_... constants describing how this

*difference was interpreted

*/

int differenceFound(Difference difference);

/**

*Receive notification that a comparison between 2 nodes has been skipped

*because the node types are not comparable by the DifferenceEngine

*@param control the control node being compared

*@param test the test node being compared

*@see DifferenceEngine

*/

void skippedComparison(Node control, Node test);

differenceFound is invoked by DifferenceEngine as soon as a difference has been detected. The return value of that method is completely ignored by DifferenceEngine, it becomes important when used together with Diff, though (see Section 3.5). The return value should be one of the four constants defined in the the DifferenceListener interface:

/**

*Standard return value for the <code>differenceFound</code> method.

*Indicates that the <code>Difference</code> is interpreted as defined

*in {@link DifferenceConstants DifferenceConstants}.

*/

int RETURN_ACCEPT_DIFFERENCE; /**

*Override return value for the <code>differenceFound</code> method.

*Indicates that the nodes identified as being different should be

*interpreted as being identical.

*/

int RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; /**

* Override return value for the <code>differenceFound</code> method.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]