org.testng.internal.junit.ArrayComparisonFailure Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testng Show documentation
Show all versions of testng Show documentation
A testing framework for the JVM
package org.testng.internal.junit;
import java.util.ArrayList;
import java.util.List;
/** Thrown when two array elements differ */
public class ArrayComparisonFailure extends AssertionError {
private final List fIndices = new ArrayList<>();
private final String fMessage;
private final AssertionError fCause;
/**
* Construct a new ArrayComparisonFailure
with an error text and the array's
* dimension that was not equal
*
* @param cause the exception that caused the array's content to fail the assertion test
* @param index the array position of the objects that are not equal.
*/
public ArrayComparisonFailure(String message, AssertionError cause, int index) {
fMessage = message;
fCause = cause;
addDimension(index);
}
public void addDimension(int index) {
fIndices.add(0, index);
}
@Override
public String getMessage() {
StringBuilder builder = new StringBuilder();
if (fMessage != null) builder.append(fMessage);
builder.append("arrays first differed at element ");
for (int each : fIndices) {
builder.append("[");
builder.append(each);
builder.append("]");
}
builder.append("; ");
builder.append(fCause.getMessage());
return builder.toString();
}
/** {@inheritDoc} */
@Override
public String toString() {
return getMessage();
}
}