Home | History | Annotate | Download | only in internal
      1 package org.junit.internal;
      2 
      3 import org.hamcrest.Description;
      4 import org.hamcrest.Matcher;
      5 import org.hamcrest.SelfDescribing;
      6 import org.hamcrest.StringDescription;
      7 
      8 public class AssumptionViolatedException extends RuntimeException implements SelfDescribing {
      9 	private static final long serialVersionUID= 1L;
     10 
     11 	private final Object fValue;
     12 
     13 	private final Matcher<?> fMatcher;
     14 
     15 	public AssumptionViolatedException(Object value, Matcher<?> matcher) {
     16 		super(value instanceof Throwable ? (Throwable) value : null);
     17 		fValue= value;
     18 		fMatcher= matcher;
     19 	}
     20 
     21 	public AssumptionViolatedException(String assumption) {
     22 		this(assumption, null);
     23 	}
     24 
     25 	@Override
     26 	public String getMessage() {
     27 		return StringDescription.asString(this);
     28 	}
     29 
     30 	public void describeTo(Description description) {
     31 		if (fMatcher != null) {
     32 			description.appendText("got: ");
     33 			description.appendValue(fValue);
     34 			description.appendText(", expected: ");
     35 			description.appendDescriptionOf(fMatcher);
     36 		} else {
     37 			description.appendText("failed assumption: " + fValue);
     38 		}
     39 	}
     40 }