1 package org.junit.internal; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import org.junit.Assert; 7 8 12 public class ArrayComparisonFailure extends AssertionError { 13 14 private static final long serialVersionUID= 1L; 15 16 private List <Integer > fIndices= new ArrayList <Integer >(); 17 private final String fMessage; 18 private final AssertionError fCause; 19 20 27 public ArrayComparisonFailure(String message, AssertionError cause, int index) { 28 fMessage= message; 29 fCause= cause; 30 addDimension(index); 31 } 32 33 public void addDimension(int index) { 34 fIndices.add(0, index); 35 } 36 37 @Override 38 public String getMessage() { 39 StringBuilder builder= new StringBuilder (); 40 if (fMessage != null) 41 builder.append(fMessage); 42 builder.append("arrays first differed at element "); 43 for (int each : fIndices) { 44 builder.append("["); 45 builder.append(each); 46 builder.append("]"); 47 } 48 builder.append("; "); 49 builder.append(fCause.getMessage()); 50 return builder.toString(); 51 } 52 53 56 @Override public String toString() { 57 return getMessage(); 58 } 59 } 60 | Popular Tags |